# 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": "LoadImage",
"inputs": {
"image": "UPLOADED_start_frame_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"2": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/ComfyUI",
"format": "auto",
"format.codec": "auto",
"video": [
"3",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"3": {
"class_type": "KlingVideoNode",
"inputs": {
"generate_audio": True,
"model": "kling-v3",
"model.aspect_ratio": "16:9",
"model.resolution": "1080p",
"multi_shot": "2 storyboards",
"multi_shot.storyboard_1_duration": 3,
"multi_shot.storyboard_1_prompt": "At dusk on the clifftop skate bowl, the woman with the bleached buzzcut drops her board onto the coping, stands, and plants her back foot on the tail. The camera starts low beside her sneakers, then tilts up and pushes in as she leans forward and drops into the steep concrete transition, jacket snapping in the sea wind.",
"multi_shot.storyboard_2_duration": 4,
"multi_shot.storyboard_2_prompt": "She carves fast across the bottom of the bowl and rockets up the far wall, popping a high air above the coping against the violet sky and distant lighthouse beams. The camera whip-pans to follow, then orbits around her mid-air in dramatic slow motion before she lands cleanly and rolls away. Sound: roaring wheels, crashing surf, wind.",
"seed": 0,
"start_frame": [
"1",
0
]
},
"_meta": {
"title": "Kling 3.0 Video"
}
}
})
workflow.set_input("1", "image", client.assets.from_url("https://comfy.org/catalog-media/92014376-dde0-4be5-947f-a2b5b1bd0e27/b31988e7-16d7-47fb-af46-a19010e037d1"))
# 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)