# 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({
"71": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "umt5_xxl_fp8_e4m3fn_scaled.safetensors",
"device": "default",
"type": "wan"
},
"_meta": {
"title": "Load CLIP"
}
},
"72": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"71",
0
],
"text": "色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走,裸露,NSFW"
},
"_meta": {
"title": "CLIP Text Encode (Negative Prompt)"
}
},
"73": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "wan_2.1_vae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"74": {
"class_type": "EmptyHunyuanLatentVideo",
"inputs": {
"batch_size": 1,
"height": 720,
"length": 81,
"width": 1280
},
"_meta": {
"title": "Empty Hunyuan Video 1.0 Latent"
}
},
"75": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "wan2.2_t2v_high_noise_14B_fp8_scaled.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"76": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "wan2.2_t2v_low_noise_14B_fp8_scaled.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"78": {
"class_type": "KSamplerAdvanced",
"inputs": {
"add_noise": "disable",
"cfg": 1,
"end_at_step": 4,
"latent_image": [
"81",
0
],
"model": [
"86",
0
],
"negative": [
"72",
0
],
"noise_seed": 0,
"positive": [
"89",
0
],
"return_with_leftover_noise": "disable",
"sampler_name": "euler",
"scheduler": "simple",
"start_at_step": 2,
"steps": 4
},
"_meta": {
"title": "KSampler (Advanced)"
}
},
"80": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/ComfyUI",
"format": "auto",
"format.codec": "auto",
"video": [
"88",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"81": {
"class_type": "KSamplerAdvanced",
"inputs": {
"add_noise": "enable",
"cfg": 1,
"end_at_step": 2,
"latent_image": [
"74",
0
],
"model": [
"82",
0
],
"negative": [
"72",
0
],
"noise_seed": 392459563371087,
"positive": [
"89",
0
],
"return_with_leftover_noise": "enable",
"sampler_name": "euler",
"scheduler": "simple",
"start_at_step": 0,
"steps": 4
},
"_meta": {
"title": "KSampler (Advanced)"
}
},
"82": {
"class_type": "ModelSamplingSD3",
"inputs": {
"model": [
"83",
0
],
"shift": 5.000000000000001
},
"_meta": {
"title": "ModelSamplingSD3"
}
},
"83": {
"class_type": "LoraLoaderModelOnly",
"inputs": {
"lora_name": "wan2.2_t2v_lightx2v_4steps_lora_v1.1_high_noise.safetensors",
"model": [
"75",
0
],
"strength_model": 1.0000000000000002
},
"_meta": {
"title": "Load LoRA"
}
},
"85": {
"class_type": "LoraLoaderModelOnly",
"inputs": {
"lora_name": "wan2.2_t2v_lightx2v_4steps_lora_v1.1_low_noise.safetensors",
"model": [
"76",
0
],
"strength_model": 1.0000000000000002
},
"_meta": {
"title": "Load LoRA"
}
},
"86": {
"class_type": "ModelSamplingSD3",
"inputs": {
"model": [
"85",
0
],
"shift": 5.000000000000001
},
"_meta": {
"title": "ModelSamplingSD3"
}
},
"87": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"78",
0
],
"vae": [
"73",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"88": {
"class_type": "CreateVideo",
"inputs": {
"bit_depth": "auto",
"codec": "none",
"color_space": "sRGB",
"fps": 16,
"images": [
"87",
0
]
},
"_meta": {
"title": "Create Video"
}
},
"89": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"71",
0
],
"text": "A low tracking shot skims just above the churning ocean, slowly pushing in toward the action over five seconds. Across the vast, stormy expanse beneath an overcast sky, two massive black-and-white orcas surge dynamically through the dark blue-gray water. In the center, the dominant orca breaches powerfully, its sleek body and tall dorsal fin arcing skyward before crashing downward, displacing a heavy explosion of white spray. Beside it, the secondary orca smoothly breaks the surface, rolling through the frothy crests as fine ocean mist drifts through the cool air. The rolling swell heaves continuously, sending turbulent ripples outward as both apex predators dive back beneath the foaming waves."
},
"_meta": {
"title": "CLIP Text Encode (Positive Prompt)"
}
}
})
# 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("80"):
output.to_file(output.name)