# 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({
"8": {
"class_type": "VHS_LoadVideo",
"inputs": {
"custom_height": 0,
"custom_width": 0,
"force_rate": 0,
"format": "AnimateDiff",
"frame_load_cap": 0,
"select_every_nth": 1,
"skip_first_frames": 0,
"video": "UPLOADED_video_FILENAME"
},
"_meta": {
"title": "Reference Video"
}
},
"13": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/ComfyUI",
"format": "auto",
"format.codec": "auto",
"video": [
"17:16",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"18": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Reference Image"
}
},
"17:14": {
"class_type": "VHS_VideoCombine",
"inputs": {
"audio": [
"8",
2
],
"filename_prefix": "AnimateDiff",
"format": "image/gif",
"frame_rate": [
"17:9",
0
],
"images": [
"17:6",
0
],
"loop_count": 0,
"pingpong": False,
"save_output": False
},
"_meta": {
"title": "Video Combine 🎥🅥🅗🅢"
}
},
"17:15": {
"class_type": "GetVideoComponents",
"inputs": {
"video": [
"17:3",
0
]
},
"_meta": {
"title": "Get Video Components"
}
},
"17:16": {
"class_type": "CreateVideo",
"inputs": {
"audio": [
"8",
2
],
"bit_depth": 8,
"codec": "none",
"color_space": "sRGB",
"fps": [
"17:15",
2
],
"images": [
"17:15",
0
]
},
"_meta": {
"title": "Create Video"
}
},
"17:3": {
"class_type": "ByteDance2ReferenceNode",
"inputs": {
"model": "Seedance 2.0",
"model.auto_downscale": True,
"model.auto_upscale": False,
"model.duration": 5,
"model.generate_audio": True,
"model.prompt": "dance",
"model.ratio": "adaptive",
"model.reference_images.image_1": [
"18",
0
],
"model.reference_videos.video_1": [
"17:7",
0
],
"model.resolution": "720p",
"seed": 601585036,
"watermark": False
},
"_meta": {
"title": "ByteDance Seedance 2.5 Reference to Video (Legacy)"
}
},
"17:6": {
"class_type": "DepthAnythingV2Preprocessor",
"inputs": {
"ckpt_name": "depth_anything_v2_vitl.pth",
"image": [
"8",
0
],
"resolution": 512
},
"_meta": {
"title": "Depth Anything V2 - Relative"
}
},
"17:7": {
"class_type": "CreateVideo",
"inputs": {
"audio": [
"8",
2
],
"bit_depth": 8,
"codec": "none",
"color_space": "sRGB",
"fps": [
"17:9",
0
],
"images": [
"17:6",
0
]
},
"_meta": {
"title": "Create Video"
}
},
"17:9": {
"class_type": "VHS_VideoInfo",
"inputs": {
"video_info": [
"8",
3
]
},
"_meta": {
"title": "Video Info 🎥🅥🅗🅢"
}
}
})
# Replace each example.com URL with a public URL of your file.
workflow.set_input("18", "image", client.assets.from_url("https://example.com/replace-with-a-url/image"))
workflow.set_input("8", "video", client.assets.from_url("https://example.com/replace-with-a-url/video"))
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)