# 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({
"72": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "umt5_xxl_fp8_e4m3fn_scaled.safetensors",
"device": "default",
"type": "wan"
},
"_meta": {
"title": "Load CLIP"
}
},
"73": {
"class_type": "ModelSamplingSD3",
"inputs": {
"model": [
"76",
0
],
"shift": 8.000000000000002
},
"_meta": {
"title": "ModelSamplingSD3"
}
},
"74": {
"class_type": "ModelSamplingSD3",
"inputs": {
"model": [
"77",
0
],
"shift": 8
},
"_meta": {
"title": "ModelSamplingSD3"
}
},
"76": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "wan2.2_i2v_high_noise_14B_fp8_scaled.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"77": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "wan2.2_i2v_low_noise_14B_fp8_scaled.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"78": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"72",
0
],
"text": "色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走"
},
"_meta": {
"title": "CLIP Text Encode (Negative Prompt)"
}
},
"79": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "wan_2.1_vae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"80": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_start_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"81": {
"class_type": "WanFirstLastFrameToVideo",
"inputs": {
"batch_size": 1,
"end_image": [
"89",
0
],
"height": 480,
"length": 81,
"negative": [
"78",
0
],
"positive": [
"90",
0
],
"start_image": [
"80",
0
],
"vae": [
"79",
0
],
"width": 832
},
"_meta": {
"title": "WanFirstLastFrameToVideo"
}
},
"83": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/ComfyUI",
"format": "auto",
"format.codec": "auto",
"video": [
"86",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"84": {
"class_type": "KSamplerAdvanced",
"inputs": {
"add_noise": "enable",
"cfg": 4,
"end_at_step": 10,
"latent_image": [
"81",
2
],
"model": [
"73",
0
],
"negative": [
"81",
1
],
"noise_seed": 984937593540091,
"positive": [
"81",
0
],
"return_with_leftover_noise": "enable",
"sampler_name": "euler",
"scheduler": "simple",
"start_at_step": 0,
"steps": 20
},
"_meta": {
"title": "KSampler (Advanced)"
}
},
"85": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"87",
0
],
"vae": [
"79",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"86": {
"class_type": "CreateVideo",
"inputs": {
"bit_depth": "auto",
"codec": "none",
"color_space": "sRGB",
"fps": 16,
"images": [
"85",
0
]
},
"_meta": {
"title": "Create Video"
}
},
"87": {
"class_type": "KSamplerAdvanced",
"inputs": {
"add_noise": "disable",
"cfg": 4,
"end_at_step": 10000,
"latent_image": [
"84",
0
],
"model": [
"74",
0
],
"negative": [
"81",
1
],
"noise_seed": 0,
"positive": [
"81",
0
],
"return_with_leftover_noise": "disable",
"sampler_name": "euler",
"scheduler": "simple",
"start_at_step": 10,
"steps": 20
},
"_meta": {
"title": "KSampler (Advanced)"
}
},
"89": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_end_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"90": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"72",
0
],
"text": "The tiny russet creature sleeps curled on the stone surface, then its ears twitch and its eyes snap open. It uncurls, rises onto its legs and begins to grow, swelling to twice its size as its fur bristles outward and blazes into vivid orange and crimson. The small sprout on its head unfurls and bursts into a large red bloom. It arches its back, lashes its long plumed tail and opens its mouth in a fierce roar. The camera holds steady with a slow, gentle push-in, warm lantern light and a painterly oil texture throughout, smooth and natural motion from start to finish."
},
"_meta": {
"title": "CLIP Text Encode (Positive Prompt)"
}
}
})
workflow.set_input("89", "image", client.assets.from_url("https://comfy.org/catalog-media/a9e0e41c-4d4f-40d0-8fce-740c2b9851a9/bcf8c2bb-c35c-40e0-b1a9-a7e5ebf4e8de"))
workflow.set_input("80", "image", client.assets.from_url("https://comfy.org/catalog-media/96b61f43-24b7-4846-9798-dd02af67c3ab/b1afbe7b-48c3-4c9d-9739-bc71fd21a295"))
# 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("83"):
output.to_file(output.name)