# 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({
"1": {
"class_type": "ViduExtendVideoNode",
"inputs": {
"end_frame": [
"5",
0
],
"model": "viduq2-pro",
"model.duration": 4,
"model.resolution": "720p",
"prompt": "",
"seed": 978453909,
"video": [
"2",
0
]
},
"_meta": {
"title": "Vidu Video Extension"
}
},
"2": {
"class_type": "LoadVideo",
"inputs": {
"file": "lawyer.mp4"
},
"_meta": {
"title": "Load Video"
}
},
"3": {
"class_type": "GetVideoComponents",
"inputs": {
"video": [
"2",
0
]
},
"_meta": {
"title": "Get Video Components"
}
},
"4": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/vidu_video_extended",
"format": "auto",
"format.codec": "auto",
"video": [
"1",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"5": {
"class_type": "ImageFromBatch",
"inputs": {
"batch_index": [
"10",
2
],
"image": [
"3",
0
],
"length": 1
},
"_meta": {
"title": "Get Image from Batch"
}
},
"10": {
"class_type": "GetImageSize",
"inputs": {
"image": [
"3",
0
]
},
"_meta": {
"title": "Get Image Size"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)