# 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({
"14": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/kling_o3_flf2v",
"format": "auto",
"format.codec": "auto",
"video": [
"32",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"17": {
"class_type": "LoadImage",
"inputs": {
"image": "ivory_rider_right_front_view.png"
},
"_meta": {
"title": "First Frame"
}
},
"32": {
"class_type": "KlingOmniProFirstLastFrameNode",
"inputs": {
"duration": 5,
"end_frame": [
"34",
0
],
"first_frame": [
"17",
0
],
"generate_audio": False,
"model_name": "kling-v3-omni",
"prompt": "A graceful pale-haired girl in an ivory lace outfit and orange-tinted sunglasses rides a majestic white horse. The scene transitions from a calm, intimate close-up (first frame) to a dynamic, sweeping gallop across a sun-drenched desert (end frame). The horse’s mane flows with motion, and the desert landscape shifts from a soft, ethereal close-up to a vast, open expanse. The transition is smooth, maintaining the character’s and horse’s consistent appearance and style, with cinematic lighting and a dreamlike, otherworldly atmosphere.\n",
"resolution": "1080p",
"seed": 0,
"storyboards": "disabled"
},
"_meta": {
"title": "Kling 3.0 Omni First-Last-Frame to Video"
}
},
"34": {
"class_type": "LoadImage",
"inputs": {
"image": "ivory_rider.png"
},
"_meta": {
"title": "End Frame"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)