# 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({
"11": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/Kandinsky5",
"format": "mp4",
"format.codec": "h264",
"video": [
"12:10",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"12:1": {
"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)"
}
},
"12:10": {
"class_type": "CreateVideo",
"inputs": {
"bit_depth": "auto",
"codec": "none",
"color_space": "sRGB",
"fps": 24,
"images": [
"12:9",
0
]
},
"_meta": {
"title": "Create Video"
}
},
"12:2": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"12:1",
0
],
"text": ""
},
"_meta": {
"title": "CLIP Text Encode (Negative Prompt)"
}
},
"12:3": {
"class_type": "ModelSamplingSD3",
"inputs": {
"model": [
"12:4",
0
],
"shift": 5
},
"_meta": {
"title": "ModelSamplingSD3"
}
},
"12:4": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "kandinsky5lite_t2v_sft_5s.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"12:5": {
"class_type": "Kandinsky5ImageToVideo",
"inputs": {
"batch_size": 1,
"height": 512,
"length": 121,
"negative": [
"12:2",
0
],
"positive": [
"12:7",
0
],
"vae": [
"12:6",
0
],
"width": 768
},
"_meta": {
"title": "Kandinsky5ImageToVideo"
}
},
"12:6": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "hunyuan_video_vae_bf16.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"12:7": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"12:1",
0
],
"text": "Rim light, side light, soft light, medium close-up, dusk, sunset, central composition, warm tones with low saturation, telephoto lens. A woman with fluffy brown curly hair stands elegantly in front of a magnificent stained glass window. She is wearing a flowing white dress, her hair neatly combed back, and her soft facial contours are gently illuminated by the colorful light filtering through the window from outside. The woman is talking to someone off-camera, yet there is a hint of sadness in her eyes, adding a layer of depth to her mysterious temperament. The background is dim, with a strong contrast between light and shadow, further emphasizing the tension of the character's emotions. The stained glass, under the glow of the setting sun, casts colorful light and shadows, enhancing the artistic sense and atmosphere of the overall picture."
},
"_meta": {
"title": "CLIP Text Encode (Positive Prompt)"
}
},
"12:8": {
"class_type": "KSampler",
"inputs": {
"cfg": 5,
"denoise": 1,
"latent_image": [
"12:5",
2
],
"model": [
"12:3",
0
],
"negative": [
"12:5",
1
],
"positive": [
"12:5",
0
],
"sampler_name": "euler_ancestral",
"scheduler": "beta",
"seed": 102704842425568,
"steps": 50
},
"_meta": {
"title": "KSampler"
}
},
"12:9": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"12:8",
0
],
"vae": [
"12:6",
0
]
},
"_meta": {
"title": "VAE Decode"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)