# 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({
"3": {
"class_type": "LoadAudio",
"inputs": {
"audio": "audio_ace_step_1_m2m_editing_input_audio.mp3"
},
"_meta": {
"title": "Load Audio"
}
},
"7": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/Wan2.5",
"format": "auto",
"format.codec": "auto",
"video": [
"10",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"10": {
"class_type": "WanImageToVideoApi",
"inputs": {
"duration": 5,
"generate_audio": True,
"image": [
"11",
0
],
"model": "wan2.5-i2v-preview",
"negative_prompt": "",
"prompt": "At golden hour on the mountain pass, the old crawler tractor coughs to life: a puff of dark exhaust bursts from the vertical pipe, the engine shudders and the tracks start to grind forward over the gravel, kicking up amber dust that drifts through the low sunlight. The surveyor turns from the edge of the cliff, shields their eyes against the glare and walks toward the machine. The camera starts wide and low behind a boulder, then cranes up and orbits slowly to the right, revealing the full depth of the red-rock canyon falling away below as long shadows stretch across the ledge. Sound: diesel engine rumble, crunching gravel, desert wind.",
"prompt_extend": True,
"resolution": "720P",
"seed": 265691414,
"shot_type": "single",
"watermark": False
},
"_meta": {
"title": "Wan Image to Video"
}
},
"11": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
}
})
workflow.set_input("11", "image", client.assets.from_url("https://comfy.org/catalog-media/80ff7f17-6305-40c1-abce-bdb84ffeea2b/c180c89f-d666-41b1-a705-ef87fd9e0bf9"))
# 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("7"):
output.to_file(output.name)