# 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/kling-omni-t2v",
"format": "auto",
"format.codec": "auto",
"video": [
"2",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"2": {
"class_type": "KlingOmniProImageToVideoNode",
"inputs": {
"aspect_ratio": "16:9",
"duration": 3,
"generate_audio": False,
"model_name": "kling-video-o1",
"prompt": "An indoor scene at night where the quokka in a white bathrobe sits by a window, looking out at the stars. The camera slowly zooms in on its contemplative face, then pulls back to reveal the knitted sheep character approaching with a warm drink. The sheep's light blue sweater glows softly in the warm room light. Candles flicker on a nearby table, casting dancing shadows. The atmosphere is cozy, peaceful, and filled with quiet companionship.",
"reference_images": [
"4",
0
],
"resolution": "1080p",
"seed": 0
},
"_meta": {
"title": "Kling 3.0 Omni Image to Video"
}
},
"3": {
"class_type": "LoadImage",
"inputs": {
"image": "sheep_knit.jpg"
},
"_meta": {
"title": "Load Image"
}
},
"4": {
"class_type": "BatchImagesNode",
"inputs": {
"images.image0": [
"3",
0
],
"images.image1": [
"5",
0
],
"images.image2": [
"6",
0
]
},
"_meta": {
"title": "Batch Images"
}
},
"5": {
"class_type": "LoadImage",
"inputs": {
"image": "quokka_bath.jpg"
},
"_meta": {
"title": "Load Image"
}
},
"6": {
"class_type": "LoadImage",
"inputs": {
"image": "quokka_relax.jpg"
},
"_meta": {
"title": "Load Image"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)