# 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": "ByteDance2ReferenceNode",
"inputs": {
"model": "Seedance 2.0",
"model.auto_downscale": False,
"model.auto_upscale": False,
"model.duration": 7,
"model.generate_audio": True,
"model.prompt": [
"119",
0
],
"model.ratio": "adaptive",
"model.reference_videos.video_1": [
"3",
0
],
"model.resolution": "720p",
"seed": 1111111,
"watermark": False
},
"_meta": {
"title": "ByteDance Seedance 2.5 Reference to Video (Legacy)"
}
},
"3": {
"class_type": "LoadVideo",
"inputs": {
"file": "ea6b81bf8e18ceb6ea79e5f08e6ed35271ae6dfb9df1ce88e7a9eda78189445e.mp4"
},
"_meta": {
"title": "Load Video"
}
},
"4": {
"class_type": "GetVideoComponents",
"inputs": {
"video": [
"1",
0
]
},
"_meta": {
"title": "Get Video Components"
}
},
"5": {
"class_type": "GetVideoComponents",
"inputs": {
"video": [
"3",
0
]
},
"_meta": {
"title": "Get Video Components"
}
},
"6": {
"class_type": "BatchImagesNode",
"inputs": {
"images.image0": [
"5",
0
],
"images.image1": [
"114",
0
]
},
"_meta": {
"title": "Batch Images"
}
},
"7": {
"class_type": "CreateVideo",
"inputs": {
"audio": [
"8",
0
],
"bit_depth": "auto",
"codec": "none",
"color_space": "sRGB",
"fps": [
"4",
2
],
"images": [
"6",
0
]
},
"_meta": {
"title": "Create Stitched Video"
}
},
"8": {
"class_type": "AudioConcat",
"inputs": {
"audio1": [
"5",
1
],
"audio2": [
"4",
1
],
"direction": "after"
},
"_meta": {
"title": "Concatenate Audio"
}
},
"9": {
"class_type": "SaveVideo",
"inputs": {
"codec": "auto",
"filename_prefix": "stitched_video",
"format": "auto",
"format.codec": "auto",
"video": [
"7",
0
]
},
"_meta": {
"title": "Save Stitched Video"
}
},
"10": {
"class_type": "SaveVideo",
"inputs": {
"codec": "auto",
"filename_prefix": "extended_video",
"format": "auto",
"format.codec": "auto",
"video": [
"11",
0
]
},
"_meta": {
"title": "Save Extended Video"
}
},
"11": {
"class_type": "CreateVideo",
"inputs": {
"audio": [
"4",
1
],
"bit_depth": "auto",
"codec": "none",
"color_space": "sRGB",
"fps": [
"4",
2
],
"images": [
"4",
0
]
},
"_meta": {
"title": "Create Extended Video"
}
},
"113": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"111:108",
0
]
},
"_meta": {
"title": "Preview Images Difference"
}
},
"114": {
"class_type": "ImageFromBatch+",
"inputs": {
"image": [
"4",
0
],
"length": -1,
"start": 0
},
"_meta": {
"title": "Trim Extended Video"
}
},
"118": {
"class_type": "PrimitiveStringMultiline",
"inputs": {
"value": "Camera pulls back to reveal twin fiery swords crossed at chest height, eyes flaring hotter, cloak settling. Camera locks into a low hero-shot medium, blade flames licking the frame edges."
},
"_meta": {
"title": "Prompt - Video Extension"
}
},
"119": {
"class_type": "StringConcatenate",
"inputs": {
"delimiter": " ",
"string_a": "Extend from the end of @video_1. ",
"string_b": [
"118",
0
]
},
"_meta": {
"title": "Create Prompt"
}
},
"111:106": {
"class_type": "ReverseImageBatch",
"inputs": {
"images": [
"5",
0
]
},
"_meta": {
"title": "Reverse Image Batch"
}
},
"111:107": {
"class_type": "ImageFromBatch",
"inputs": {
"batch_index": 0,
"image": [
"111:106",
0
],
"length": 1
},
"_meta": {
"title": "Get Image from Batch"
}
},
"111:108": {
"class_type": "ImageEnhanceDifference+",
"inputs": {
"exponent": 0.75,
"image1": [
"111:107",
0
],
"image2": [
"111:112",
0
]
},
"_meta": {
"title": "Image Enhance Difference"
}
},
"111:112": {
"class_type": "ImageFromBatch",
"inputs": {
"batch_index": 0,
"image": [
"4",
0
],
"length": 12
},
"_meta": {
"title": "Get Image from Batch"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)