# 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/Kandinsky5",
"format": "mp4",
"format.codec": "h264",
"video": [
"69:66",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"11": {
"class_type": "LoadImage",
"inputs": {
"image": "crystal_flower.png"
},
"_meta": {
"title": "Load Image"
}
},
"69:53": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "kandinsky5lite_i2v_5s.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"69:54": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "hunyuan_video_vae_bf16.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"69:55": {
"class_type": "DualCLIPLoader",
"inputs": {
"clip_name1": "qwen_2.5_vl_7b_fp8_scaled.safetensors",
"clip_name2": "clip_l.safetensors",
"device": "default",
"type": "kandinsky5"
},
"_meta": {
"title": "Load CLIP (Dual)"
}
},
"69:56": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"69:55",
0
],
"text": "Cinematic dynamic scene in deep blue dream haze: The camera glides slowly forward, focusing on tightly closed crystal flower buds (starlight-sparkled, translucent) that sway gently with misty currents. As the lens pans right, more closed blooms blur into pulsing bokeh; sequined leaves tremble, scattering glimmers that trail light streaks. The camera then pulls back softly, the blue tone deepening from cyan to indigo, while the buds’ subtle sway syncs with drifting mist—all motion flowing in a quiet, breath-like rhythm, wrapping the scene in immersive, glittering cinematic serenity."
},
"_meta": {
"title": "CLIP Text Encode (Positive Prompt)"
}
},
"69:57": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"69:55",
0
],
"text": ""
},
"_meta": {
"title": "CLIP Text Encode (Negative Prompt)"
}
},
"69:58": {
"class_type": "ImageScale",
"inputs": {
"crop": "center",
"height": [
"69:60",
0
],
"image": [
"11",
0
],
"upscale_method": "lanczos",
"width": [
"69:59",
0
]
},
"_meta": {
"title": "Upscale Image"
}
},
"69:59": {
"class_type": "PrimitiveInt",
"inputs": {
"value": 768
},
"_meta": {
"title": "Width"
}
},
"69:60": {
"class_type": "PrimitiveInt",
"inputs": {
"value": 512
},
"_meta": {
"title": "Height"
}
},
"69:61": {
"class_type": "ModelSamplingSD3",
"inputs": {
"model": [
"69:53",
0
],
"shift": 5
},
"_meta": {
"title": "ModelSamplingSD3"
}
},
"69:62": {
"class_type": "Kandinsky5ImageToVideo",
"inputs": {
"batch_size": 1,
"height": [
"69:60",
0
],
"length": 121,
"negative": [
"69:57",
0
],
"positive": [
"69:56",
0
],
"start_image": [
"69:58",
0
],
"vae": [
"69:54",
0
],
"width": [
"69:59",
0
]
},
"_meta": {
"title": "Kandinsky5ImageToVideo"
}
},
"69:63": {
"class_type": "KSampler",
"inputs": {
"cfg": 5,
"denoise": 1,
"latent_image": [
"69:62",
2
],
"model": [
"69:61",
0
],
"negative": [
"69:62",
1
],
"positive": [
"69:62",
0
],
"sampler_name": "euler_ancestral",
"scheduler": "beta",
"seed": 611409204875324,
"steps": 50
},
"_meta": {
"title": "KSampler"
}
},
"69:64": {
"class_type": "ReplaceVideoLatentFrames",
"inputs": {
"destination": [
"69:63",
0
],
"index": 0,
"source": [
"69:62",
3
]
},
"_meta": {
"title": "Replace Video Latent Frames"
}
},
"69:65": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"69:69",
0
],
"vae": [
"69:54",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"69:66": {
"class_type": "CreateVideo",
"inputs": {
"bit_depth": "auto",
"codec": "none",
"color_space": "sRGB",
"fps": 24,
"images": [
"69:65",
0
]
},
"_meta": {
"title": "Create Video"
}
},
"69:69": {
"class_type": "NormalizeVideoLatentStart",
"inputs": {
"latent": [
"69:64",
0
],
"reference_frame_count": 5,
"start_frame_count": 4
},
"_meta": {
"title": "NormalizeVideoLatentStart"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)