# Python 3.10+: pip install comfy-sdk==0.4.0
import os
from comfy_sdk import Comfy
api_key = os.environ.get("COMFY_API_KEY", "").strip()
if not api_key: raise RuntimeError("Set COMFY_API_KEY")
os.environ.setdefault("COMFY_BASE_URL", "https://cloud.comfy.org")
client = Comfy(api_key=api_key)
workflow = client.workflows.from_json({
"1": {
"class_type": "ByteDance2FirstLastFrameNode",
"inputs": {
"first_frame": [
"3",
0
],
"first_frame_asset_id": "",
"last_frame": [
"4",
0
],
"last_frame_asset_id": "",
"model": "Seedance 2.0",
"model.duration": 4,
"model.generate_audio": False,
"model.prompt": "extreme shot shifts as two character run and jump and make action poses, anime style, squash and stretch animation, calarts style, cartoon network style",
"model.ratio": "16:9",
"model.resolution": "1080p",
"seed": 223429887,
"watermark": False
},
"_meta": {
"title": "ByteDance Seedance 2.5 First-Last-Frame to Video"
}
},
"2": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/Seedance2.0_flf2v",
"format": "auto",
"format.codec": "auto",
"video": [
"1",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"3": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"4": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_2_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"5": {
"class_type": "ByteDance2FirstLastFrameNode",
"inputs": {
"first_frame": [
"4",
0
],
"first_frame_asset_id": "",
"last_frame": [
"7",
0
],
"last_frame_asset_id": "",
"model": "Seedance 2.0",
"model.duration": 4,
"model.generate_audio": False,
"model.prompt": "extreme shot shifts as two character run and jump and make action poses, anime style, squash and stretch animation, calarts style, cartoon network style",
"model.ratio": "16:9",
"model.resolution": "1080p",
"seed": 1662723398,
"watermark": False
},
"_meta": {
"title": "ByteDance Seedance 2.5 First-Last-Frame to Video"
}
},
"6": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/Seedance2.0_flf2v",
"format": "auto",
"format.codec": "auto",
"video": [
"5",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"7": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_3_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"8": {
"class_type": "ByteDance2FirstLastFrameNode",
"inputs": {
"first_frame": [
"7",
0
],
"first_frame_asset_id": "",
"last_frame": [
"10",
0
],
"last_frame_asset_id": "",
"model": "Seedance 2.0",
"model.duration": 4,
"model.generate_audio": False,
"model.prompt": "extreme shot shifts as two character run and jump and make action poses, anime style, squash and stretch animation, calarts style, cartoon network style",
"model.ratio": "16:9",
"model.resolution": "1080p",
"seed": 1366057492,
"watermark": False
},
"_meta": {
"title": "ByteDance Seedance 2.5 First-Last-Frame to Video"
}
},
"9": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/Seedance2.0_flf2v",
"format": "auto",
"format.codec": "auto",
"video": [
"8",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"10": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_4_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"11": {
"class_type": "ByteDance2FirstLastFrameNode",
"inputs": {
"first_frame": [
"10",
0
],
"first_frame_asset_id": "",
"last_frame": [
"15",
0
],
"last_frame_asset_id": "",
"model": "Seedance 2.0",
"model.duration": 4,
"model.generate_audio": False,
"model.prompt": "extreme shot shifts as two character run and jump and make action poses, anime style, squash and stretch animation, calarts style, cartoon network style",
"model.ratio": "16:9",
"model.resolution": "1080p",
"seed": 651642512,
"watermark": False
},
"_meta": {
"title": "ByteDance Seedance 2.5 First-Last-Frame to Video"
}
},
"12": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/Seedance2.0_flf2v",
"format": "auto",
"format.codec": "auto",
"video": [
"11",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"13": {
"class_type": "ByteDance2FirstLastFrameNode",
"inputs": {
"first_frame": [
"15",
0
],
"first_frame_asset_id": "",
"last_frame": [
"16",
0
],
"last_frame_asset_id": "",
"model": "Seedance 2.0",
"model.duration": 4,
"model.generate_audio": False,
"model.prompt": "extreme shot shifts as two character run and jump and make action poses, anime style, squash and stretch animation, calarts style, cartoon network style",
"model.ratio": "16:9",
"model.resolution": "1080p",
"seed": 167021654,
"watermark": False
},
"_meta": {
"title": "ByteDance Seedance 2.5 First-Last-Frame to Video"
}
},
"14": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/Seedance2.0_flf2v",
"format": "auto",
"format.codec": "auto",
"video": [
"13",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"15": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_5_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"16": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_6_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"17": {
"class_type": "ImageBatch",
"inputs": {
"image1": [
"27",
0
],
"image2": [
"26",
0
]
},
"_meta": {
"title": "Batch Images (DEPRECATED)"
}
},
"18": {
"class_type": "ImageBatch",
"inputs": {
"image1": [
"17",
0
],
"image2": [
"25",
0
]
},
"_meta": {
"title": "Batch Images (DEPRECATED)"
}
},
"19": {
"class_type": "ImageBatch",
"inputs": {
"image1": [
"18",
0
],
"image2": [
"24",
0
]
},
"_meta": {
"title": "Batch Images (DEPRECATED)"
}
},
"20": {
"class_type": "ImageBatch",
"inputs": {
"image1": [
"19",
0
],
"image2": [
"23",
0
]
},
"_meta": {
"title": "Batch Images (DEPRECATED)"
}
},
"21": {
"class_type": "CreateVideo",
"inputs": {
"bit_depth": "auto",
"codec": "none",
"color_space": "sRGB",
"fps": 24,
"images": [
"20",
0
]
},
"_meta": {
"title": "Create Video"
}
},
"22": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/ComfyUI",
"format": "auto",
"format.codec": "auto",
"video": [
"21",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"23": {
"class_type": "GetVideoComponents",
"inputs": {
"video": [
"13",
0
]
},
"_meta": {
"title": "Get Video Components"
}
},
"24": {
"class_type": "GetVideoComponents",
"inputs": {
"video": [
"11",
0
]
},
"_meta": {
"title": "Get Video Components"
}
},
"25": {
"class_type": "GetVideoComponents",
"inputs": {
"video": [
"8",
0
]
},
"_meta": {
"title": "Get Video Components"
}
},
"26": {
"class_type": "GetVideoComponents",
"inputs": {
"video": [
"5",
0
]
},
"_meta": {
"title": "Get Video Components"
}
},
"27": {
"class_type": "GetVideoComponents",
"inputs": {
"video": [
"1",
0
]
},
"_meta": {
"title": "Get Video Components"
}
}
})
# Replace each example.com URL with a public URL of your file.
workflow.set_input("3", "image", client.assets.from_url("https://example.com/replace-with-a-url/image"))
workflow.set_input("4", "image", client.assets.from_url("https://example.com/replace-with-a-url/image_2"))
workflow.set_input("7", "image", client.assets.from_url("https://example.com/replace-with-a-url/image_3"))
workflow.set_input("10", "image", client.assets.from_url("https://example.com/replace-with-a-url/image_4"))
workflow.set_input("15", "image", client.assets.from_url("https://example.com/replace-with-a-url/image_5"))
workflow.set_input("16", "image", client.assets.from_url("https://example.com/replace-with-a-url/image_6"))
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)