# 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({
"37": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/vidu_q2_r2v",
"format": "auto",
"format.codec": "auto",
"video": [
"41",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"40": {
"class_type": "LoadImage",
"inputs": {
"image": "api_vidu_q2_r2v_red_haired_girl.jpg"
},
"_meta": {
"title": "Load Image"
}
},
"41": {
"class_type": "Vidu2ReferenceVideoNode",
"inputs": {
"aspect_ratio": "16:9",
"audio": True,
"duration": 5,
"model": "viduq2",
"movement_amplitude": "auto",
"prompt": "@a(red-haired woman in elegant attire) sits on a fallen log in the muted green forest, her hands clasped gently. @b(aged robot with weathered white-grey body) stands before her, its arms still extended in an open gesture. The woman looks up at the robot's glowing orange eyes, a gentle smile forming. The robot speaks in a whisper-soft, almost human-like voice with minimal mechanical resonance—quiet and intimate, as if sharing a secret. The woman responds in a soft, contemplative tone. Camera circles around them in a slow arc, revealing the depth of the forest behind. Natural forest ambience at low volume: soft wind through leaves, occasional bird songs. The robot's internal mechanisms are nearly silent, only a faint, rhythmic hum.",
"resolution": "720p",
"seed": 1752617780,
"subjects.subject1": [
"40",
0
],
"subjects.subject2": [
"42",
0
]
},
"_meta": {
"title": "Vidu2 Reference-to-Video Generation"
}
},
"42": {
"class_type": "LoadImage",
"inputs": {
"image": "vintage_robot.jpg"
},
"_meta": {
"title": "Load Image"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)