# 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({
"16": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/CausalForcing_I2V",
"format": "auto",
"format.codec": "auto",
"video": [
"29:17",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"18": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"29:1": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "causal_forcing-framewise.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"29:11": {
"class_type": "RandomNoise",
"inputs": {
"noise_seed": 483145124184881
},
"_meta": {
"title": "Random Noise"
}
},
"29:12": {
"class_type": "SamplerARVideo",
"inputs": {
"num_frame_per_block": 1
},
"_meta": {
"title": "Sampler AR Video"
}
},
"29:13": {
"class_type": "BasicScheduler",
"inputs": {
"denoise": 1,
"model": [
"29:8",
0
],
"scheduler": "simple",
"steps": 4
},
"_meta": {
"title": "Schedule (4 steps)"
}
},
"29:14": {
"class_type": "CFGGuider",
"inputs": {
"cfg": 1,
"model": [
"29:8",
0
],
"negative": [
"29:9",
0
],
"positive": [
"29:4",
0
]
},
"_meta": {
"title": "CFG Guider (cfg=1)"
}
},
"29:15": {
"class_type": "SamplerCustomAdvanced",
"inputs": {
"guider": [
"29:14",
0
],
"latent_image": [
"29:8",
1
],
"noise": [
"29:11",
0
],
"sampler": [
"29:12",
0
],
"sigmas": [
"29:13",
0
]
},
"_meta": {
"title": "SamplerCustomAdvanced"
}
},
"29:17": {
"class_type": "CreateVideo",
"inputs": {
"bit_depth": "auto",
"chroma_subsampling": "auto",
"codec": "none",
"color_space": "sRGB",
"fps": 16,
"images": [
"29:6",
0
]
},
"_meta": {
"title": "Create Video"
}
},
"29:2": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "umt5_xxl_fp8_e4m3fn_scaled.safetensors",
"device": "default",
"type": "wan"
},
"_meta": {
"title": "Load CLIP"
}
},
"29:23": {
"class_type": "ComfyMathExpression",
"inputs": {
"expression": "min(a * 16 + 1, 81)",
"values.a": [
"29:28",
0
]
},
"_meta": {
"title": "Math Expression"
}
},
"29:28": {
"class_type": "PrimitiveFloat",
"inputs": {
"value": 5
},
"_meta": {
"title": "Float (Duration)"
}
},
"29:3": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "wan_2.1_vae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"29:4": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"29:2",
0
],
"text": "A blonde girl rides a white wolf running forward at night, camera locked on them, always centered in the shot."
},
"_meta": {
"title": "CLIP Text Encode (Positive Prompt)"
}
},
"29:6": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"29:15",
0
],
"vae": [
"29:3",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"29:8": {
"class_type": "ARVideoI2V",
"inputs": {
"batch_size": 1,
"height": 480,
"length": [
"29:23",
1
],
"model": [
"29:1",
0
],
"start_image": [
"18",
0
],
"vae": [
"29:3",
0
],
"width": 832
},
"_meta": {
"title": "ARVideoI2V"
}
},
"29:9": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"29:2",
0
],
"text": "色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走,不合理的动作"
},
"_meta": {
"title": "CLIP Text Encode (Negative Prompt)"
}
}
})
workflow.set_input("18", "image", client.assets.from_url("https://comfy.org/catalog-media/d7f238c5-bbf6-42d2-8271-891542ada571/47d81bdd-1fba-48b6-96c7-f52f9342ab28"))
# 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("16"):
output.to_file(output.name)