# 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({
"21": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/ComfyUI",
"format": "auto",
"format.codec": "auto",
"video": [
"41",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"28": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"30": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_2_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"41": {
"class_type": "ViduReferenceVideoNode",
"inputs": {
"aspect_ratio": "16:9",
"duration": 5,
"images": [
"44",
0
],
"model": "viduq1",
"movement_amplitude": "auto",
"prompt": "In a strange alien desert scene, a futuristic girl with long white hair, wearing tattered yet fashion - forward alien - style clothing, looks up. A giant alien beast with curved tusks and a rugged, armored body is walking toward her. As the camera pulls back, a sci - fi base with towering structures and flying vehicles shuttling about stands behind the beast. An epic and mysterious atmosphere is created, featuring highly detailed textures and cinematic lighting.",
"resolution": "1080p",
"seed": 1486794447
},
"_meta": {
"title": "Vidu Reference To Video Generation"
}
},
"42": {
"class_type": "ImageBatch",
"inputs": {
"image1": [
"28",
0
],
"image2": [
"30",
0
]
},
"_meta": {
"title": "Batch Images (DEPRECATED)"
}
},
"44": {
"class_type": "ImageBatch",
"inputs": {
"image1": [
"42",
0
],
"image2": [
"45",
0
]
},
"_meta": {
"title": "Batch Images (DEPRECATED)"
}
},
"45": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_3_FILENAME"
},
"_meta": {
"title": "Load Image"
}
}
})
# Replace each example.com URL with a public URL of your file.
workflow.set_input("28", "image", client.assets.from_url("https://example.com/replace-with-a-url/image"))
workflow.set_input("30", "image", client.assets.from_url("https://example.com/replace-with-a-url/image_2"))
workflow.set_input("45", "image", client.assets.from_url("https://example.com/replace-with-a-url/image_3"))
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)