# 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({
"344": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/Seedance2.0_r2v",
"format": "auto",
"format.codec": "auto",
"video": [
"360",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"352": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_2_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"353": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_3_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"354": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_4_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"356": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_1_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"360": {
"class_type": "ByteDance2ReferenceNode",
"inputs": {
"model": "Seedance 2.0",
"model.auto_downscale": True,
"model.auto_upscale": False,
"model.duration": 7,
"model.generate_audio": True,
"model.prompt": "Fast-paced fashion showcase filmed as a first-person selfie with a wide-angle lens. The woman from the first reference image holds the camera at arm's length on a windswept coastal bluff at dawn, talking to the lens and laughing as sea mist blows past. [0-2s] She wears the light henley top from the third reference with the wide-leg trousers from the fourth, steps back and turns so both are fully visible. [2-4s] Glitch transition: she now wears the slate-blue utility jacket from the second reference over the same henley, tugging the collar and leaning close to the camera. [4-7s] Glitch transition: she twirls in the full look, jacket open, trousers flaring, then waves goodbye. Garments match their references exactly, consistent in every frame. Quick whip-pans, heather and cliffs behind her, wind, waves and an upbeat electronic beat.",
"model.ratio": "16:9",
"model.reference_images.image_1": [
"356",
0
],
"model.reference_images.image_2": [
"352",
0
],
"model.reference_images.image_3": [
"353",
0
],
"model.reference_images.image_4": [
"354",
0
],
"model.resolution": "4k",
"seed": 838593524,
"watermark": False
},
"_meta": {
"title": "ByteDance Seedance 2.5 Reference to Video (Legacy)"
}
}
})
workflow.set_input("356", "image", client.assets.from_url("https://comfy.org/catalog-media/df5a1664-68f6-4c3c-8b34-02895d86db16/54a073ef-1f26-4eec-b764-94bfd82eed0b"))
workflow.set_input("352", "image", client.assets.from_url("https://comfy.org/catalog-media/7d8b9701-bf08-4fb7-a7df-47f64b430460/a25eac7f-d83f-437d-8035-cb999f16c66f"))
workflow.set_input("353", "image", client.assets.from_url("https://comfy.org/catalog-media/8119a491-8843-40ea-8c25-f777b5191fef/0383b1d3-632a-414d-933a-8b67b5f3314e"))
workflow.set_input("354", "image", client.assets.from_url("https://comfy.org/catalog-media/1ab3d685-99d1-4974-8f60-da41339a13fa/21931d99-5c1f-48b2-9b2e-2c8a6a02d53b"))
# 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("344"):
output.to_file(output.name)