# 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({
"2": {
"class_type": "SaveVideo",
"inputs": {
"codec": "auto",
"filename_prefix": "video/ComfyUI",
"format": "auto",
"format.codec": "auto",
"video": [
"7",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"3": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"7",
1
]
},
"_meta": {
"title": "Preview as Text"
}
},
"5": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_1_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"6": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_2_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"7": {
"class_type": "GeminiVideoOmni",
"inputs": {
"model": "Omni Flash",
"model.images.image_1": [
"5",
0
],
"model.images.image_2": [
"6",
0
],
"model.prompt": [
"19:16",
0
],
"model.temperature": 1,
"model.top_p": 0.95,
"seed": 42
},
"_meta": {
"title": "Google Gemini Omni (Video)"
}
},
"19:10": {
"class_type": "CustomCombo",
"inputs": {
"choice": "8s "
},
"_meta": {
"title": "Custom Combo"
}
},
"19:11": {
"class_type": "StringConcatenate",
"inputs": {
"delimiter": "",
"string_a": "Aspect Ratio: ",
"string_b": [
"19:9",
0
]
},
"_meta": {
"title": "Concatenate Text"
}
},
"19:12": {
"class_type": "StringConcatenate",
"inputs": {
"delimiter": "",
"string_a": "Duration: ",
"string_b": [
"19:10",
0
]
},
"_meta": {
"title": "Concatenate Text"
}
},
"19:13": {
"class_type": "StringConcatenate",
"inputs": {
"delimiter": ";",
"string_a": [
"19:11",
0
],
"string_b": [
"19:12",
0
]
},
"_meta": {
"title": "Concatenate Text"
}
},
"19:15": {
"class_type": "PrimitiveStringMultiline",
"inputs": {
"value": "Follow the storyboard in Image 2 exactly, panel by panel from left to right, starring the helmeted character from Image 1 with the same gunmetal helmet, glowing cyan visor and charcoal flight jacket. Begin in a narrow rain-soaked alley at night where the character discovers a small lost robot puppy shivering beside a puddle. The camera pushes in as the character kneels and holds out a glowing battery; the puppy's eyes flicker on and its tail starts to wag. The camera then cranes up and back as the two walk away together under one umbrella, neon reflections rippling across the wet ground. Keep the motion smooth and continuous, with gentle rain, soft electronic beeps from the puppy, distant traffic and a warm synth melody rising at the end."
},
"_meta": {
"title": "Input Text (User Prompt)"
}
},
"19:16": {
"class_type": "StringConcatenate",
"inputs": {
"delimiter": "",
"string_a": [
"19:15",
0
],
"string_b": [
"19:13",
0
]
},
"_meta": {
"title": "Concatenate Text"
}
},
"19:9": {
"class_type": "CustomCombo",
"inputs": {
"choice": "16:9"
},
"_meta": {
"title": "Custom Combo"
}
}
})
workflow.set_input("5", "image", client.assets.from_url("https://comfy.org/catalog-media/70ae609c-1421-4741-b056-d8bd8c2ef9ae/1173036c-9547-4c5b-962a-e064f1121b92"))
workflow.set_input("6", "image", client.assets.from_url("https://comfy.org/catalog-media/d794c6f7-6d3d-4227-8c08-356455db53b1/95fea51a-1dbe-42cc-bb53-d80640733d48"))
# 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("2"):
output.to_file(output.name)