# 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({
"13": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "Wan2_1-I2V-14B-480p_fp8_e4m3fn_scaled_KJ.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"14": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"16",
0
],
"text": "The camera zooms in. Two characters are talking."
},
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"16": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "umt5_xxl_fp8_e4m3fn_scaled.safetensors",
"device": "default",
"type": "wan"
},
"_meta": {
"title": "Load CLIP"
}
},
"17": {
"class_type": "ConditioningZeroOut",
"inputs": {
"conditioning": [
"14",
0
]
},
"_meta": {
"title": "Conditioning Zero Out"
}
},
"24": {
"class_type": "LoadAudio",
"inputs": {
"audio": "audio_speaker1_woman.mp3"
},
"_meta": {
"title": "Load Audio"
}
},
"25": {
"class_type": "AudioEncoderEncode",
"inputs": {
"audio": [
"24",
0
],
"audio_encoder": [
"26",
0
]
},
"_meta": {
"title": "AudioEncoderEncode"
}
},
"26": {
"class_type": "AudioEncoderLoader",
"inputs": {
"audio_encoder_name": "wav2vec2-chinese-base_fp16.safetensors"
},
"_meta": {
"title": "Load Audio Encoder"
}
},
"29": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "Wan2_1_VAE_bf16.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"32": {
"class_type": "LoadImage",
"inputs": {
"image": "two_character_talking.png"
},
"_meta": {
"title": "Load Image"
}
},
"33": {
"class_type": "LoraLoaderModelOnly",
"inputs": {
"lora_name": "lightx2v_I2V_14B_480p_cfg_step_distill_rank64_bf16.safetensors",
"model": [
"13",
0
],
"strength_model": 1
},
"_meta": {
"title": "Load LoRA"
}
},
"90": {
"class_type": "LoadAudio",
"inputs": {
"audio": "audio_speaker2_man.mp3"
},
"_meta": {
"title": "Load Audio"
}
},
"93": {
"class_type": "AudioEncoderEncode",
"inputs": {
"audio": [
"90",
0
],
"audio_encoder": [
"26",
0
]
},
"_meta": {
"title": "AudioEncoderEncode"
}
},
"112": {
"class_type": "ModelPatchLoader",
"inputs": {
"name": "wan2.1_infiniteTalk_multi_fp16.safetensors"
},
"_meta": {
"title": "Load Model Patch"
}
},
"113": {
"class_type": "AudioConcat",
"inputs": {
"audio1": [
"24",
0
],
"audio2": [
"90",
0
],
"direction": "after"
},
"_meta": {
"title": "Concatenate Audio"
}
},
"119": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"145:120",
0
],
"vae": [
"29",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"124": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"146:171",
0
],
"vae": [
"29",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"126": {
"class_type": "ImageFromBatch",
"inputs": {
"batch_index": [
"130",
4
],
"image": [
"124",
0
],
"length": 4096
},
"_meta": {
"title": "Get Image from Batch"
}
},
"127": {
"class_type": "ImageBatch",
"inputs": {
"image1": [
"119",
0
],
"image2": [
"126",
0
]
},
"_meta": {
"title": "Batch Images (DEPRECATED)"
}
},
"129": {
"class_type": "WanInfiniteTalkToVideo",
"inputs": {
"audio_encoder_output_1": [
"25",
0
],
"audio_scale": 1,
"height": [
"150",
0
],
"length": 81,
"mode": "two_speakers",
"mode.audio_encoder_output_2": [
"93",
0
],
"mode.mask_1": [
"32",
1
],
"mode.mask_2": [
"137",
1
],
"model": [
"33",
0
],
"model_patch": [
"112",
0
],
"motion_frame_count": 9,
"negative": [
"17",
0
],
"positive": [
"14",
0
],
"start_image": [
"32",
0
],
"vae": [
"29",
0
],
"width": [
"149",
0
]
},
"_meta": {
"title": "WanInfiniteTalkToVideo"
}
},
"130": {
"class_type": "WanInfiniteTalkToVideo",
"inputs": {
"audio_encoder_output_1": [
"25",
0
],
"audio_scale": 1,
"height": [
"150",
0
],
"length": 81,
"mode": "two_speakers",
"mode.audio_encoder_output_2": [
"93",
0
],
"mode.mask_1": [
"32",
1
],
"mode.mask_2": [
"137",
1
],
"model": [
"33",
0
],
"model_patch": [
"112",
0
],
"motion_frame_count": 9,
"negative": [
"17",
0
],
"positive": [
"14",
0
],
"previous_frames": [
"119",
0
],
"start_image": [
"32",
0
],
"vae": [
"29",
0
],
"width": [
"149",
0
]
},
"_meta": {
"title": "WanInfiniteTalkToVideo"
}
},
"137": {
"class_type": "LoadImage",
"inputs": {
"image": "two_character_talking.png"
},
"_meta": {
"title": "Load Image"
}
},
"138": {
"class_type": "CreateVideo",
"inputs": {
"audio": [
"113",
0
],
"bit_depth": "auto",
"codec": "none",
"color_space": "sRGB",
"fps": 25,
"images": [
"119",
0
]
},
"_meta": {
"title": "Create Video"
}
},
"140": {
"class_type": "CreateVideo",
"inputs": {
"audio": [
"113",
0
],
"bit_depth": "auto",
"codec": "none",
"color_space": "sRGB",
"fps": 25,
"images": [
"127",
0
]
},
"_meta": {
"title": "Create Video"
}
},
"141": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/ComfyUI",
"format": "auto",
"format.codec": "auto",
"video": [
"140",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"149": {
"class_type": "PrimitiveInt",
"inputs": {
"value": 832
},
"_meta": {
"title": "Width"
}
},
"150": {
"class_type": "PrimitiveInt",
"inputs": {
"value": 480
},
"_meta": {
"title": "Height"
}
},
"162": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/ComfyUI",
"format": "auto",
"format.codec": "auto",
"video": [
"138",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"145:106": {
"class_type": "RandomNoise",
"inputs": {
"noise_seed": 264423375967408
},
"_meta": {
"title": "RandomNoise"
}
},
"145:107": {
"class_type": "CFGGuider",
"inputs": {
"cfg": 1,
"model": [
"129",
0
],
"negative": [
"129",
2
],
"positive": [
"129",
1
]
},
"_meta": {
"title": "CFG Guider"
}
},
"145:108": {
"class_type": "KSamplerSelect",
"inputs": {
"sampler_name": "euler"
},
"_meta": {
"title": "KSamplerSelect"
}
},
"145:120": {
"class_type": "SamplerCustomAdvanced",
"inputs": {
"guider": [
"145:107",
0
],
"latent_image": [
"129",
3
],
"noise": [
"145:106",
0
],
"sampler": [
"145:108",
0
],
"sigmas": [
"145:19",
0
]
},
"_meta": {
"title": "SamplerCustomAdvanced"
}
},
"145:19": {
"class_type": "BasicScheduler",
"inputs": {
"denoise": 1,
"model": [
"129",
0
],
"scheduler": "normal",
"steps": 4
},
"_meta": {
"title": "BasicScheduler"
}
},
"146:167": {
"class_type": "KSamplerSelect",
"inputs": {
"sampler_name": "euler"
},
"_meta": {
"title": "KSamplerSelect"
}
},
"146:168": {
"class_type": "CFGGuider",
"inputs": {
"cfg": 1,
"model": [
"130",
0
],
"negative": [
"130",
2
],
"positive": [
"130",
1
]
},
"_meta": {
"title": "CFG Guider"
}
},
"146:169": {
"class_type": "BasicScheduler",
"inputs": {
"denoise": 1,
"model": [
"130",
0
],
"scheduler": "normal",
"steps": 4
},
"_meta": {
"title": "BasicScheduler"
}
},
"146:170": {
"class_type": "RandomNoise",
"inputs": {
"noise_seed": 967091162875519
},
"_meta": {
"title": "RandomNoise"
}
},
"146:171": {
"class_type": "SamplerCustomAdvanced",
"inputs": {
"guider": [
"146:168",
0
],
"latent_image": [
"130",
3
],
"noise": [
"146:170",
0
],
"sampler": [
"146:167",
0
],
"sigmas": [
"146:169",
0
]
},
"_meta": {
"title": "SamplerCustomAdvanced"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)