# 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({
"665": {
"class_type": "GetVideoComponents",
"inputs": {
"video": [
"727",
0
]
},
"_meta": {
"title": "Get Video Components"
}
},
"666": {
"class_type": "CreateVideo",
"inputs": {
"audio": [
"665",
1
],
"bit_depth": "auto",
"codec": "none",
"color_space": "sRGB",
"fps": [
"665",
2
],
"images": [
"632:698",
0
]
},
"_meta": {
"title": "Create Video"
}
},
"667": {
"class_type": "SaveVideo",
"inputs": {
"codec": "h264",
"filename_prefix": "video/ComfyUI",
"format": "mp4",
"format.codec": "h264",
"video": [
"666",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"668": {
"class_type": "ImageFromBatch",
"inputs": {
"batch_index": 0,
"image": [
"665",
0
],
"length": 48
},
"_meta": {
"title": "Get Image from Batch"
}
},
"676": {
"class_type": "ImageStitch",
"inputs": {
"direction": "right",
"image1": [
"668",
0
],
"image2": [
"632:698",
0
],
"match_image_size": False,
"spacing_color": "white",
"spacing_width": 0
},
"_meta": {
"title": "Stitch Images"
}
},
"677": {
"class_type": "CreateVideo",
"inputs": {
"audio": [
"665",
1
],
"bit_depth": "auto",
"codec": "none",
"color_space": "sRGB",
"fps": [
"665",
2
],
"images": [
"676",
0
]
},
"_meta": {
"title": "Create Video"
}
},
"678": {
"class_type": "SaveVideo",
"inputs": {
"codec": "auto",
"filename_prefix": "video/ComfyUI",
"format": "auto",
"format.codec": "auto",
"video": [
"677",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"719": {
"class_type": "ResolutionSelector",
"inputs": {
"aspect_ratio": "16:9 (Widescreen)",
"megapixels": 2.1,
"multiple": 8
},
"_meta": {
"title": "Resolution Selector"
}
},
"727": {
"class_type": "LoadVideo",
"inputs": {
"file": "UPLOADED_video_FILENAME"
},
"_meta": {
"title": "Load Video"
}
},
"632:695": {
"class_type": "WanVideoEmptyEmbeds",
"inputs": {
"height": [
"632:697",
1
],
"num_frames": [
"632:697",
2
],
"width": [
"632:697",
0
]
},
"_meta": {
"title": "Image Embeds"
}
},
"632:696": {
"class_type": "WanVideoSampler",
"inputs": {
"add_noise_to_samples": True,
"batched_cfg": False,
"cfg": 1.0000000000000002,
"denoise_strength": 0.25,
"end_step": -1,
"force_offload": False,
"image_embeds": [
"632:695",
0
],
"model": [
"632:702",
0
],
"riflex_freq_index": 0,
"rope_function": "comfy",
"samples": [
"632:699",
0
],
"scheduler": "euler",
"seed": 622986558479570,
"shift": 5,
"start_step": 0,
"steps": 4,
"text_embeds": [
"632:704",
0
]
},
"_meta": {
"title": "WanVideo Sampler"
}
},
"632:697": {
"class_type": "GetImageSize",
"inputs": {
"image": [
"632:706",
0
]
},
"_meta": {
"title": "Get Image Size"
}
},
"632:698": {
"class_type": "WanVideoDecode",
"inputs": {
"enable_vae_tiling": True,
"normalization": "default",
"samples": [
"632:696",
1
],
"tile_stride_x": 256,
"tile_stride_y": 256,
"tile_x": 512,
"tile_y": 512,
"vae": [
"632:701",
0
]
},
"_meta": {
"title": "WanVideo Decode"
}
},
"632:699": {
"class_type": "WanVideoEncode",
"inputs": {
"enable_vae_tiling": True,
"image": [
"632:706",
0
],
"latent_strength": 1,
"noise_aug_strength": 0.001,
"tile_stride_x": 256,
"tile_stride_y": 256,
"tile_x": 512,
"tile_y": 512,
"vae": [
"632:701",
0
]
},
"_meta": {
"title": "WanVideo Encode"
}
},
"632:700": {
"class_type": "WanVideoTorchCompileSettings",
"inputs": {
"allow_unmerged_lora_compile": False,
"backend": "inductor",
"compile_transformer_blocks_only": True,
"dynamic": False,
"dynamo_cache_size_limit": 64,
"dynamo_recompile_limit": 128,
"force_parameter_static_shapes": False,
"fullgraph": False,
"mode": "default"
},
"_meta": {
"title": "Torch CompSettings"
}
},
"632:701": {
"class_type": "WanVideoVAELoader",
"inputs": {
"model_name": "wan_2.1_vae.safetensors",
"precision": "bf16",
"use_cpu_cache": False,
"verbose": False
},
"_meta": {
"title": "WanVideo VAE Loader"
}
},
"632:702": {
"class_type": "WanVideoSetLoRAs",
"inputs": {
"lora": [
"632:705",
0
],
"model": [
"632:703",
0
]
},
"_meta": {
"title": "WanVideo Set LoRAs"
}
},
"632:703": {
"class_type": "WanVideoModelLoader",
"inputs": {
"attention_mode": "sdpa",
"base_precision": "fp16_fast",
"compile_args": [
"632:700",
0
],
"load_device": "offload_device",
"model": "Wan2_2-T2V-A14B-LOW_fp8_e4m3fn_scaled_KJ.safetensors",
"quantization": "fp8_e4m3fn_scaled",
"rms_norm_function": "default"
},
"_meta": {
"title": "WanVideo Model Loader"
}
},
"632:704": {
"class_type": "WanVideoTextEncodeCached",
"inputs": {
"device": "gpu",
"model_name": "umt5_xxl_fp16.safetensors",
"negative_prompt": "",
"positive_prompt": "high resolution, sharp, detailed",
"precision": "bf16",
"quantization": "disabled",
"use_disk_cache": True
},
"_meta": {
"title": "WanVideo TextEncode Cached"
}
},
"632:705": {
"class_type": "WanVideoLoraSelect",
"inputs": {
"lora": "lightx2v_14B_T2V_cfg_step_distill_lora_adaptive_rank_quantile_0.15_bf16.safetensors",
"low_mem_load": False,
"merge_loras": False,
"strength": 0.7
},
"_meta": {
"title": "Lightning Lora"
}
},
"632:706": {
"class_type": "ImageResize+",
"inputs": {
"condition": "always",
"height": [
"632:709",
0
],
"image": [
"668",
0
],
"interpolation": "lanczos",
"method": "fill / crop",
"multiple_of": 64,
"width": [
"632:708",
0
]
},
"_meta": {
"title": "🔧 Image Resize"
}
},
"632:708": {
"class_type": "PrimitiveInt",
"inputs": {
"value": [
"719",
0
]
},
"_meta": {
"title": "Width"
}
},
"632:709": {
"class_type": "PrimitiveInt",
"inputs": {
"value": [
"719",
1
]
},
"_meta": {
"title": "Heigth"
}
}
})
workflow.set_input("727", "file", client.assets.from_url("https://comfy.org/catalog-media/ea1e2595-155d-4854-87b8-e4b3a5d938c1/81866afc-ff24-47ed-9828-0634aa9086f2"))
# 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("667"):
output.to_file(output.name)
for output in job.get_outputs("678"):
output.to_file(output.name)