# 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({
"5": {
"class_type": "Wan3ImageToVideoApi",
"inputs": {
"first_frame": [
"6",
0
],
"model": "wan3.0-video",
"model.audio": True,
"model.duration": "5",
"model.prompt": "The midnight-blue rally coupe slides sideways across the old stone viaduct, its rear swinging out as the driver counter-steers hard, then the tyres bite and the car straightens and accelerates out of frame toward the far end of the bridge. A huge curtain of amber dust and shale spray blooms from the rear wheels and drifts over the parapet into the misty canyon. The camera whip-pans to follow the car from a low angle beside the balustrade, then rises in a slow crane move to reveal the river and pine forest far below. Sound of a howling engine, gravel spitting against stone, a turbo whistle and wind in the canyon. No text, no music.",
"model.prompt_extend": True,
"model.ratio": "16:9",
"model.resolution": "720P",
"seed": 1032549103,
"watermark": False
},
"_meta": {
"title": "Wan 3.0 Image to Video"
}
},
"6": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"8": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/Wan3.0",
"format": "auto",
"format.codec": "auto",
"video": [
"5",
0
]
},
"_meta": {
"title": "Save Video"
}
}
})
workflow.set_input("6", "image", client.assets.from_url("https://comfy.org/catalog-media/ff3653bd-3dc9-4f80-bb50-b24550fd260f/24f6f711-487b-452c-8db7-11e7eb04af80"))
# 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("8"):
output.to_file(output.name)