# 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({
"16": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/Seedance2.5_flf2v",
"format": "auto",
"format.codec": "auto",
"video": [
"38",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"38": {
"class_type": "ByteDance2FirstLastFrameNode",
"inputs": {
"first_frame": [
"41",
0
],
"first_frame_asset_id": "",
"last_frame": [
"40",
0
],
"last_frame_asset_id": "",
"model": "Seedance 2.5",
"model.duration": 5,
"model.generate_audio": True,
"model.output_format": "mp4",
"model.prompt": "The input images are the first and last frames: @image1 is the wide pool view before the activity starts, @image2 is the final top-down view. Smooth cinematic transition, 5 seconds. [0-1.5s] Starting from the first frame, the camera pushes in from the wide view toward the quiet pool, people standing around the edges, activity not yet started. [1.5-3.5s] Swimmers begin jumping into the pool one after another, splashes erupting, the crowd getting excited and lively, many people in swimsuits leaping in from all sides. [3.5-5s] The camera rises to a top-down view as everyone plays in the water, the pool packed and splashing, landing exactly on the last frame image. No black frames, no jump cuts.\n",
"model.resolution": "720p",
"seed": 0,
"watermark": False
},
"_meta": {
"title": "ByteDance Seedance 2.5 First-Last-Frame to Video"
}
},
"40": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"41": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_2_FILENAME"
},
"_meta": {
"title": "Load Image"
}
}
})
# Replace each example.com URL with a public URL of your file.
workflow.set_input("40", "image", client.assets.from_url("https://example.com/replace-with-a-url/image"))
workflow.set_input("41", "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)