# 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": "SaveVideo",
"inputs": {
"codec": "auto",
"filename_prefix": "video/flux3_max_i2v",
"format": "auto",
"format.codec": "auto",
"video": [
"16",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"16": {
"class_type": "Flux3MaxImageToVideoNode",
"inputs": {
"aspect_ratio": "auto",
"duration": "5",
"generate_audio": True,
"keyframes.image_0": [
"17",
0
],
"placement": "spread across the clip",
"prompt": "Three-shot sequence, hard cuts, cold blue dusk with amber accents, anamorphic.\nSHOT ONE: wide static shot from the ice, the figure standing small beside the parked sedan, the pyramid-shaped hull filling the sky above the mountains, snow drifting across the frame.\nHARD CUT.\nSHOT TWO: close on a cluster of thrusters under the hull, bell nozzles rimed with frost, heat burning the frost off into vapour, a ring of amber light kindling deep inside the bells, one nozzle flexing slightly on its gimbal.\nHARD CUT.\nSHOT THREE: the thrusters fire and it rises straight up, ice blasting outward in a ring across the lake, the hull climbing past the top of frame, the camera tilting up to follow it into the dusk sky, the figure left small on the bare ice, the sedan's taillight still orange.\nAudio: a deep organ drone, a rising thruster whine, then a pressure roar dropping into silence. 5 seconds.",
"reasoning_level": "high",
"resolution": "720p",
"seed": 827835527
},
"_meta": {
"title": "FLUX 3 Max Image to Video"
}
},
"17": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
}
})
workflow.set_input("17", "image", client.assets.from_url("https://comfy.org/catalog-media/948c1f9c-f1d9-4c18-9452-c6e94d17a5fa/ecaebaee-fca9-4a00-90e7-e59f7c72c73f"))
# 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("5"):
output.to_file(output.name)