# 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({
"90": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "umt5_xxl_fp8_e4m3fn_scaled.safetensors",
"device": "default",
"type": "wan"
},
"_meta": {
"title": "Load CLIP"
}
},
"91": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"90",
0
],
"text": "色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走"
},
"_meta": {
"title": "CLIP Text Encode (Negative Prompt)"
}
},
"92": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "wan_2.1_vae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"93": {
"class_type": "ModelSamplingSD3",
"inputs": {
"model": [
"101",
0
],
"shift": 8.000000000000002
},
"_meta": {
"title": "ModelSamplingSD3"
}
},
"94": {
"class_type": "ModelSamplingSD3",
"inputs": {
"model": [
"102",
0
],
"shift": 8.000000000000002
},
"_meta": {
"title": "ModelSamplingSD3"
}
},
"95": {
"class_type": "KSamplerAdvanced",
"inputs": {
"add_noise": "disable",
"cfg": 3.5,
"end_at_step": 10000,
"latent_image": [
"96",
0
],
"model": [
"94",
0
],
"negative": [
"160",
1
],
"noise_seed": 0,
"positive": [
"160",
0
],
"return_with_leftover_noise": "disable",
"sampler_name": "euler",
"scheduler": "simple",
"start_at_step": 10,
"steps": 20
},
"_meta": {
"title": "KSampler (Advanced)"
}
},
"96": {
"class_type": "KSamplerAdvanced",
"inputs": {
"add_noise": "enable",
"cfg": 3.5,
"end_at_step": 10,
"latent_image": [
"160",
2
],
"model": [
"93",
0
],
"negative": [
"160",
1
],
"noise_seed": 909895218860439,
"positive": [
"160",
0
],
"return_with_leftover_noise": "enable",
"sampler_name": "euler",
"scheduler": "simple",
"start_at_step": 0,
"steps": 20
},
"_meta": {
"title": "KSampler (Advanced)"
}
},
"97": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"95",
0
],
"vae": [
"92",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"98": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/wan2.2_fun_control",
"format": "auto",
"format.codec": "auto",
"video": [
"100",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"99": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"90",
0
],
"text": "A hand-painted gouache animation of a barefoot dancer in charcoal trousers performing alone in a foggy concrete pavilion at dawn. He lands from a leap, spins twice with his arms sweeping wide, sinks into a deep lunge, then rises and reaches one arm high as he turns slowly. Flat shapes of slate blue and warm ochre, visible brush texture and clean dark outlines stay consistent from frame to frame, with the wet floor reflecting his movements as soft painted streaks. Mist drifts gently behind him and the warm sidelight glows along his shoulders and arms. Smooth, fluid motion with graceful timing, a still camera, the painterly style holding steady through the whole clip."
},
"_meta": {
"title": "CLIP Text Encode (Positive Prompt)"
}
},
"100": {
"class_type": "CreateVideo",
"inputs": {
"bit_depth": "auto",
"codec": "none",
"color_space": "sRGB",
"fps": 16,
"images": [
"97",
0
]
},
"_meta": {
"title": "Create Video"
}
},
"101": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "wan2.2_fun_control_high_noise_14B_fp8_scaled.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"102": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "wan2.2_fun_control_low_noise_14B_fp8_scaled.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"145": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_ref_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"156": {
"class_type": "GetVideoComponents",
"inputs": {
"video": [
"158",
0
]
},
"_meta": {
"title": "Get Video Components"
}
},
"158": {
"class_type": "LoadVideo",
"inputs": {
"file": "UPLOADED_control_video_FILENAME"
},
"_meta": {
"title": "Load Video"
}
},
"160": {
"class_type": "Wan22FunControlToVideo",
"inputs": {
"batch_size": 1,
"control_video": [
"156",
0
],
"height": 480,
"length": 81,
"negative": [
"91",
0
],
"positive": [
"99",
0
],
"ref_image": [
"145",
0
],
"vae": [
"92",
0
],
"width": 832
},
"_meta": {
"title": "Wan22FunControlToVideo"
}
}
})
workflow.set_input("158", "file", client.assets.from_url("https://comfy.org/catalog-media/be072ef6-2fba-46d0-afaf-18e4eb90eaac/10c09749-d392-463f-bdf5-ad3142fd4288"))
workflow.set_input("145", "image", client.assets.from_url("https://comfy.org/catalog-media/9feb727b-9428-42c6-9746-765cae39e72a/5d6f2da7-5be9-4c1f-86a9-c885113f93fd"))
# 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("98"):
output.to_file(output.name)