# 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_i2v",
"format": "auto",
"format.codec": "auto",
"video": [
"39",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"39": {
"class_type": "Vidu2ImageToVideoNode",
"inputs": {
"duration": 5,
"image": [
"40",
0
],
"model": "viduq2-pro-fast",
"movement_amplitude": "auto",
"prompt": "The bear takes a slow, appreciative sip from the steaming mug. Thick, realistic steam rises from the cup and curls around its nose. The bear closes its eyes in contentment, and its fuzzy ears twitch slightly. The texture of the knitted sweater is highly detailed as it moves with the bear's breathing.",
"resolution": "720p",
"seed": 562117235
},
"_meta": {
"title": "Vidu2 Image-to-Video Generation"
}
},
"40": {
"class_type": "LoadImage",
"inputs": {
"image": "cozy_bear.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)