# 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({
"34": {
"class_type": "ByteDanceFirstLastFrameNode",
"inputs": {
"aspect_ratio": "1:1",
"camera_fixed": False,
"duration": 10,
"first_frame": [
"35",
0
],
"generate_audio": False,
"last_frame": [
"36",
0
],
"model": "seedance-1-0-pro-250528",
"prompt": "A wizard in a red robe, seen from behind holding two flames in his raised hands, turns around as the camera circles to a side profile, revealing he is an old man with a grey beard. As he turns, he brings his hands together, merging the two flames into one large ball of fire.",
"resolution": "1080p",
"seed": 1076553912,
"watermark": False
},
"_meta": {
"title": "ByteDance First-Last-Frame to Video"
}
},
"35": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"36": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_2_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"37": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/ByteDance-FLF2V",
"format": "auto",
"format.codec": "auto",
"video": [
"34",
0
]
},
"_meta": {
"title": "Save Video"
}
}
})
# Replace each example.com URL with a public URL of your file.
workflow.set_input("35", "image", client.assets.from_url("https://example.com/replace-with-a-url/image"))
workflow.set_input("36", "image", client.assets.from_url("https://example.com/replace-with-a-url/image_2"))
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)