# 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": [
"347",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"347": {
"class_type": "ByteDance2ReferenceNode",
"inputs": {
"model": "Seedance 2.0",
"model.auto_downscale": True,
"model.auto_upscale": False,
"model.duration": 15,
"model.generate_audio": True,
"model.prompt": "Use @ Reference Image 1 (the handmade puppet surveyor with tricorn hat, plum frock coat and white whiskers) as the only character, keeping every sculpted detail consistent. Set the action on the miniature coastal headland from @ Reference Image 2, in front of the stilted shack. He carries the brass lantern from @ Reference Image 3 and the rolled chart from @ Reference Image 4 as handmade props.\nStop-motion short film, shot on twos with gentle jitter, felt and clay textures, tilt-shift macro lens, warm lantern glow against a dusky violet sky.\n[0:00–0:05] Wide shot: he totters along the clay shore toward the shack, lantern swinging.\n[0:05–0:10] Medium shot: he kneels, unrolls the chart on a rock and squints at it as cotton-wool fog drifts in.\n[0:10–0:15] Close-up: he lifts the lantern, the shack window lights up in answer, and he gives a delighted little hop.",
"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": "720p",
"seed": 778658766,
"watermark": False
},
"_meta": {
"title": "ByteDance Seedance 2.5 Reference to Video (Legacy)"
}
},
"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"
}
}
})
workflow.set_input("356", "image", client.assets.from_url("https://comfy.org/catalog-media/da0500b0-df78-4cf8-830b-f4fa8ea0ac34/1e45b29f-8ce5-4208-b4f7-a87c9f866ab3"))
workflow.set_input("352", "image", client.assets.from_url("https://comfy.org/catalog-media/ad84b1f6-47d6-4614-a657-834a0add3e47/7d1970d6-8491-4b05-94e6-3b0e8fd7e272"))
workflow.set_input("353", "image", client.assets.from_url("https://comfy.org/catalog-media/d685644e-3247-4f56-acda-fa6a0eb87140/1f16320b-02cf-49ec-999e-82ad80d3e070"))
workflow.set_input("354", "image", client.assets.from_url("https://comfy.org/catalog-media/9910af9e-9ba7-401e-98fe-c347724b2448/f5b84c60-40a2-4f8d-a7e7-375873360e80"))
# 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)