# 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({
"91": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "wan_2.1_vae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"92": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "wan2.2_fun_camera_high_noise_14B_fp8_scaled.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"95": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "wan2.2_fun_camera_low_noise_14B_fp8_scaled.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"96": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "umt5_xxl_fp8_e4m3fn_scaled.safetensors",
"device": "default",
"type": "wan"
},
"_meta": {
"title": "Load CLIP"
}
},
"97": {
"class_type": "LoadImage",
"inputs": {
"image": "video_wan2_2_14B_fun_camera_start_image.jpg"
},
"_meta": {
"title": "Load Image"
}
},
"98": {
"class_type": "WanCameraImageToVideo",
"inputs": {
"batch_size": 1,
"camera_conditions": [
"108",
0
],
"height": [
"108",
2
],
"length": [
"108",
3
],
"negative": [
"99",
0
],
"positive": [
"107",
0
],
"start_image": [
"97",
0
],
"vae": [
"91",
0
],
"width": [
"108",
1
]
},
"_meta": {
"title": "WanCameraImageToVideo"
}
},
"99": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"96",
0
],
"text": "色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走"
},
"_meta": {
"title": "CLIP Text Encode (Negative Prompt)"
}
},
"100": {
"class_type": "ModelSamplingSD3",
"inputs": {
"model": [
"92",
0
],
"shift": 8.000000000000002
},
"_meta": {
"title": "ModelSamplingSD3"
}
},
"101": {
"class_type": "ModelSamplingSD3",
"inputs": {
"model": [
"95",
0
],
"shift": 8
},
"_meta": {
"title": "ModelSamplingSD3"
}
},
"102": {
"class_type": "KSamplerAdvanced",
"inputs": {
"add_noise": "enable",
"cfg": 3.5,
"end_at_step": 10,
"latent_image": [
"98",
2
],
"model": [
"100",
0
],
"negative": [
"98",
1
],
"noise_seed": 12802742726693,
"positive": [
"98",
0
],
"return_with_leftover_noise": "enable",
"sampler_name": "euler",
"scheduler": "simple",
"start_at_step": 0,
"steps": 20
},
"_meta": {
"title": "KSampler (Advanced)"
}
},
"103": {
"class_type": "KSamplerAdvanced",
"inputs": {
"add_noise": "disable",
"cfg": 3.5,
"end_at_step": 10000,
"latent_image": [
"102",
0
],
"model": [
"101",
0
],
"negative": [
"98",
1
],
"noise_seed": 0,
"positive": [
"98",
0
],
"return_with_leftover_noise": "disable",
"sampler_name": "euler",
"scheduler": "simple",
"start_at_step": 10,
"steps": 20
},
"_meta": {
"title": "KSampler (Advanced)"
}
},
"104": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"103",
0
],
"vae": [
"91",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"105": {
"class_type": "CreateVideo",
"inputs": {
"bit_depth": "auto",
"codec": "none",
"color_space": "sRGB",
"fps": 16,
"images": [
"104",
0
]
},
"_meta": {
"title": "Create Video"
}
},
"106": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/wan2.2_fun_camrea",
"format": "auto",
"format.codec": "auto",
"video": [
"105",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"107": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"96",
0
],
"text": "Two rovers race past, leaving clear tracks. Base tower antenna flashes rapidly, modules flicker with light. Ship speeds toward giant planet, engine lights brilliant.\n"
},
"_meta": {
"title": "CLIP Text Encode (Positive Prompt)"
}
},
"108": {
"class_type": "WanCameraEmbedding",
"inputs": {
"camera_pose": "Static",
"cx": 0.5,
"cy": 0.5,
"fx": 0.5,
"fy": 0.5,
"height": 720,
"length": 81,
"speed": 1,
"width": 720
},
"_meta": {
"title": "WanCameraEmbedding"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)