# 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({
"10": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/Kling2.6",
"format": "mp4",
"format.codec": "h264",
"video": [
"12",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"12": {
"class_type": "KlingImageToVideoWithAudio",
"inputs": {
"duration": 5,
"generate_audio": True,
"mode": "pro",
"model_name": "kling-v2-6",
"prompt": "Visual: A dimly lit, opulent private club with dark wooden paneling. An anthropomorphic green iguana stands confidently in the center, wearing gold-rimmed sunglasses and a stylish blue knitted jacket with a white fur collar. It pulls open the jacket to reveal a multi-layered gold chain with a diamond-encrusted \"C\" pendant. To the left, a wooden bar with liquor bottles illuminated by warm wall sconces. Subtle smoke drifts through the air. In the blurred background, faint neon signs glow, including a yellow Budweiser logo, with indistinct figures of patrons in booths. The camera slowly pushes in on the creature's face, then pulls back. Film noir lighting creates dramatic shadows.\n\nDialog: [The Iguana, deep and confident voice] says, \"Every shadow tells a story. And mine's just getting started.\"\n\nAudio: Ambient club sounds: distant conversations, clinking glasses, ice cubes. A smooth hip-hop beat with deep bass plays in the background. The creature's voice has slight echo and reverb. Subtle rustling of scales and gold chain clinking.\n\nOther: Cinematic, cool, mysterious, hip-hop aesthetic with film noir lighting. Slow, deliberate camera movement.",
"start_frame": [
"14",
0
]
},
"_meta": {
"title": "Kling 2.6 Image(First Frame) to Video with Audio"
}
},
"14": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
}
})
# Replace each example.com URL with a public URL of your file.
workflow.set_input("14", "image", client.assets.from_url("https://example.com/replace-with-a-url/image"))
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)