# 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({
"7": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/ByteDance-Seedance",
"format": "auto",
"format.codec": "auto",
"video": [
"13",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"12": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"13": {
"class_type": "ByteDanceImageToVideoNode",
"inputs": {
"aspect_ratio": "16:9",
"camera_fixed": False,
"duration": 5,
"generate_audio": False,
"image": [
"12",
0
],
"model": "seedance-1-0-pro-250528",
"prompt": "The armoured winged guardian beats its ragged black wings hard against the storm and hauls the drowning mariner up out of the whirlpool, their gauntleted hands locked together, sea water streaming off the mariner's soaked wool and rope. Waves surge and break around them, spray whipping sideways in the gale, and violet lightning forks behind the basalt sea stacks. The camera starts low just above the churning swells and tilts up while pushing in, following the guardian as it rises with the mariner dangling below, golden light breaking through the clouds on the horizon. Painterly oil texture stays consistent, with heavy, dramatic motion of water, feathers and cloth.",
"resolution": "720p",
"seed": 0,
"watermark": False
},
"_meta": {
"title": "ByteDance Image to Video"
}
}
})
workflow.set_input("12", "image", client.assets.from_url("https://comfy.org/catalog-media/7bb61a2b-e89a-4a40-a11c-78f444ca589d/b8e8793a-292a-4fae-a25b-59032f601e41"))
# 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("7"):
output.to_file(output.name)