# 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": [
"5",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"3": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"5",
1
]
},
"_meta": {
"title": "Preview as Text"
}
},
"5": {
"class_type": "GeminiVideoOmni",
"inputs": {
"model": "Omni Flash",
"model.prompt": [
"21:16",
0
],
"model.temperature": 1,
"model.top_p": 0.95,
"seed": 42
},
"_meta": {
"title": "Google Gemini Omni (Video)"
}
},
"21:10": {
"class_type": "CustomCombo",
"inputs": {
"choice": "3s "
},
"_meta": {
"title": "Custom Combo"
}
},
"21:11": {
"class_type": "StringConcatenate",
"inputs": {
"delimiter": "",
"string_a": "Aspect Ratio: ",
"string_b": [
"21:9",
0
]
},
"_meta": {
"title": "Concatenate Text"
}
},
"21:12": {
"class_type": "StringConcatenate",
"inputs": {
"delimiter": "",
"string_a": "Duration: ",
"string_b": [
"21:10",
0
]
},
"_meta": {
"title": "Concatenate Text"
}
},
"21:13": {
"class_type": "StringConcatenate",
"inputs": {
"delimiter": ";",
"string_a": [
"21:11",
0
],
"string_b": [
"21:12",
0
]
},
"_meta": {
"title": "Concatenate Text"
}
},
"21:15": {
"class_type": "PrimitiveStringMultiline",
"inputs": {
"value": "Wes Anderson style, perfectly symmetrical wide shot of a pastel-pink hotel lobby, two bellhops in matching mustard uniforms stand frozen at attention either side of a brass elevator, the elevator doors slide open in unison, a tiny dog wearing a bow tie trots out toward camera, slow dolly-in, flat lighting, ornate wallpaper"
},
"_meta": {
"title": "Input Text (User Prompt)"
}
},
"21:16": {
"class_type": "StringConcatenate",
"inputs": {
"delimiter": "",
"string_a": [
"21:15",
0
],
"string_b": [
"21:13",
0
]
},
"_meta": {
"title": "Concatenate Text"
}
},
"21:9": {
"class_type": "CustomCombo",
"inputs": {
"choice": "9:16"
},
"_meta": {
"title": "Custom Combo"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)