# 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"
}
},
"7": {
"class_type": "GeminiVideoOmni",
"inputs": {
"model": "Omni Flash",
"model.prompt": [
"17:16",
0
],
"model.temperature": 1,
"model.top_p": 0.95,
"model.videos.video_1": [
"8",
0
],
"seed": 1653332531
},
"_meta": {
"title": "Google Gemini Omni (Video)"
}
},
"8": {
"class_type": "LoadVideo",
"inputs": {
"file": "c502d3421069862b14ec36f58dacb44b1053fa77fceecd4109c32590bbeefaed.mp4"
},
"_meta": {
"title": "Load Video"
}
},
"17:10": {
"class_type": "CustomCombo",
"inputs": {
"choice": "5s "
},
"_meta": {
"title": "Custom Combo"
}
},
"17:11": {
"class_type": "StringConcatenate",
"inputs": {
"delimiter": "",
"string_a": "Aspect Ratio: ",
"string_b": [
"17:9",
0
]
},
"_meta": {
"title": "Concatenate Text"
}
},
"17:12": {
"class_type": "StringConcatenate",
"inputs": {
"delimiter": "",
"string_a": "Duration: ",
"string_b": [
"17:10",
0
]
},
"_meta": {
"title": "Concatenate Text"
}
},
"17:13": {
"class_type": "StringConcatenate",
"inputs": {
"delimiter": ";",
"string_a": [
"17:11",
0
],
"string_b": [
"17:12",
0
]
},
"_meta": {
"title": "Concatenate Text"
}
},
"17:15": {
"class_type": "PrimitiveStringMultiline",
"inputs": {
"value": "Keep the character and all objects unchanged, change the environment to a white studio, and add pink paint exploding from the drums when he hits them."
},
"_meta": {
"title": "Input Text (User Prompt)"
}
},
"17:16": {
"class_type": "StringConcatenate",
"inputs": {
"delimiter": "",
"string_a": [
"17:15",
0
],
"string_b": [
"17:13",
0
]
},
"_meta": {
"title": "Concatenate Text"
}
},
"17:9": {
"class_type": "CustomCombo",
"inputs": {
"choice": "16:9"
},
"_meta": {
"title": "Custom Combo"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)