# 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": "SaveVideo",
"inputs": {
"filename_prefix": "video/ComfyUI",
"format": "auto",
"format.codec": "auto",
"video": [
"3",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"2": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"3": {
"class_type": "MinimaxImageToVideoNode",
"inputs": {
"image": [
"2",
0
],
"model": "I2V-01-Director",
"prompt_text": "[Push in, Tracking shot] The elderly nomad strides steadily toward the camera across the frozen plateau, her indigo greatcoat and ragged silk hems whipping hard in the gale, long silver hair streaming sideways across her face. With each step, powdered frost bursts up around her fur-trimmed boots and swirls away in glittering spirals. Behind her the colossal moon-white disk pulses faintly with cold light while violet-black blizzard veils sweep across the sky from right to left. The two white owls bank overhead, wings beating slowly, then glide out of frame. She lifts her outstretched hand against the wind, narrows her eyes and keeps walking, her shadow stretching long across the ice. Painterly impasto texture shimmers as the snow streaks past the lens.",
"seed": 593766105563760
},
"_meta": {
"title": "MiniMax Image to Video"
}
}
})
workflow.set_input("2", "image", client.assets.from_url("https://comfy.org/catalog-media/2d8b4c2b-da8b-45de-9e89-d4c6055e72a4/e779c69f-24af-4ab3-88a2-a11a38c4fd44"))
# 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("1"):
output.to_file(output.name)