# 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": 7,
"model.generate_audio": True,
"model.prompt": "One continuous drone shot. The camera starts high and far above the cracked salt flat, with the lone traveler and the old bicycle a tiny dot in the middle of the empty ground. It glides forward and descends in a long, smooth arc, sweeping low over the crust as the dust storm rolls in across the horizon. As it closes in, the camera curves around to the traveler's side and settles at chest height beside him, ending on a close view of his face in profile as he stares at the approaching wall of amber dust. The light warms from hard afternoon glare to deep gold. Wind gusts lift grit off the ground and tug at his shirt. Sound: rising wind, sand hissing across the flat, a low rumble from the storm.",
"model.ratio": "16:9",
"model.resolution": "720p",
"seed": 498214648,
"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_first_frame_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"4": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_last_frame_FILENAME"
},
"_meta": {
"title": "Load Image"
}
}
})
workflow.set_input("3", "image", client.assets.from_url("https://comfy.org/catalog-media/0972938f-9806-45dd-b8be-6002821800e2/ad8ed3f8-65c5-458e-b705-e476e8eefc87"))
workflow.set_input("4", "image", client.assets.from_url("https://comfy.org/catalog-media/a64e7b2b-38f8-4578-aaea-a8a7b08e40ba/f481909c-d09c-4aa8-8da9-bb5d203f8f25"))
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)
for output in job.get_outputs("2"):
output.to_file(output.name)