# 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({
"16": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/Seedance2.5_video_edit",
"format": "auto",
"format.codec": "auto",
"video": [
"39",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"35": {
"class_type": "LoadVideo",
"inputs": {
"file": "UPLOADED_video_FILENAME"
},
"_meta": {
"title": "Load Video"
}
},
"36": {
"class_type": "Video Slice",
"inputs": {
"duration": 5,
"start_time": 0,
"strict_duration": False,
"video": [
"35",
0
]
},
"_meta": {
"title": "Trim Video"
}
},
"39": {
"class_type": "ByteDance2ReferenceNodeV2",
"inputs": {
"model": "Seedance 2.5",
"model.auto_downscale": True,
"model.auto_upscale": False,
"model.duration": 5,
"model.generate_audio": True,
"model.output_format": "mp4",
"model.prompt": [
"workshop-prompt",
0
],
"model.ratio": "16:9",
"model.reference_videos.video_1": [
"36",
0
],
"model.resolution": "720p",
"model.task_type": "edit",
"seed": 0,
"watermark": False
},
"_meta": {
"title": "ByteDance Seedance 2.5 Reference to Video"
}
},
"workshop-prompt": {
"class_type": "StringConcatenate",
"inputs": {
"delimiter": " ",
"string_a": "Replace the background with a sunlit city park, leafy trees, and a soft blue sky. Preserve the subject, its clothing, movement, camera framing, and timing. Change only the background and match its lighting to the subject.",
"string_b": "Use this as the new background of the video. Keep the subject, its clothing, pose, movement, camera framing and timing exactly as in the source video. Change only the background, and match the new background's lighting to the subject."
},
"_meta": {
"title": "Workshop prompt + fixed instructions"
}
}
})
workflow.set_input("35", "file", client.assets.from_url("https://cdn.jsdelivr.net/gh/Comfy-Org/workflow_templates@90c71fb78b3726392d010ff62a8e79e92d7296ad/input/kitten_cop.mp4"))
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)
for output in job.get_outputs("16"):
output.to_file(output.name)