# 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({
"3": {
"class_type": "KSampler",
"inputs": {
"cfg": 5,
"denoise": 1,
"latent_image": [
"60",
2
],
"model": [
"48",
0
],
"negative": [
"60",
1
],
"positive": [
"60",
0
],
"sampler_name": "uni_pc",
"scheduler": "simple",
"seed": 436961904444694,
"steps": 20
},
"_meta": {
"title": "KSampler"
}
},
"6": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"38",
0
],
"text": "A hand-painted gouache animation of a woman in a cream linen top and wide trousers dancing barefoot in a warm terracotta studio. She raises both arms high overhead, sweeps them wide, steps to the side and turns, bends one knee into a low dip, rises and spins, then ends with her arms stretched wide. Flat warm colour shapes, soft paper grain and visible brush strokes stay consistent on every frame; the trousers swing with each step and her long shadow slides across the pale painted floor. The camera stays still. Smooth, graceful, flowing motion in warm golden light."
},
"_meta": {
"title": "CLIP Text Encode (Positive Prompt)"
}
},
"7": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"38",
0
],
"text": "色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走"
},
"_meta": {
"title": "CLIP Text Encode (Negative Prompt)"
}
},
"8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"3",
0
],
"vae": [
"39",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"37": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "wan2.2_fun_control_5B_bf16.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"38": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "umt5_xxl_fp8_e4m3fn_scaled.safetensors",
"device": "default",
"type": "wan"
},
"_meta": {
"title": "Load CLIP"
}
},
"39": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "wan2.2_vae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"48": {
"class_type": "ModelSamplingSD3",
"inputs": {
"model": [
"37",
0
],
"shift": 8
},
"_meta": {
"title": "ModelSamplingSD3"
}
},
"57": {
"class_type": "CreateVideo",
"inputs": {
"bit_depth": "auto",
"codec": "none",
"color_space": "sRGB",
"fps": 24,
"images": [
"8",
0
]
},
"_meta": {
"title": "Create Video"
}
},
"58": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/ComfyUI",
"format": "auto",
"format.codec": "auto",
"video": [
"57",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"60": {
"class_type": "Wan22FunControlToVideo",
"inputs": {
"batch_size": 1,
"control_video": [
"67",
0
],
"height": 704,
"length": 121,
"negative": [
"7",
0
],
"positive": [
"6",
0
],
"ref_image": [
"70",
0
],
"vae": [
"39",
0
],
"width": 1280
},
"_meta": {
"title": "Wan22FunControlToVideo"
}
},
"66": {
"class_type": "LoadVideo",
"inputs": {
"file": "UPLOADED_control_video_FILENAME"
},
"_meta": {
"title": "Load Video"
}
},
"67": {
"class_type": "GetVideoComponents",
"inputs": {
"video": [
"66",
0
]
},
"_meta": {
"title": "Get Video Components"
}
},
"70": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_ref_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
}
})
workflow.set_input("66", "file", client.assets.from_url("https://comfy.org/catalog-media/64ab8e37-3a41-4c59-a663-5ec324e7509f/7f0abd10-f8c3-4ab4-9397-fa2a08bfda9c"))
workflow.set_input("70", "image", client.assets.from_url("https://comfy.org/catalog-media/273cab6b-6755-457b-8e1b-cafbf97a242c/bfea8973-a10c-40da-a341-db011d8016b8"))
# 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("58"):
output.to_file(output.name)