# 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({
"8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"125",
0
],
"vae": [
"10",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"10": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "hunyuanvideo15_vae_fp16.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"11": {
"class_type": "DualCLIPLoader",
"inputs": {
"clip_name1": "qwen_2.5_vl_7b_fp8_scaled.safetensors",
"clip_name2": "byt5_small_glyphxl_fp16.safetensors",
"device": "default",
"type": "hunyuan_video_15"
},
"_meta": {
"title": "Load CLIP (Dual)"
}
},
"12": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "hunyuanvideo1.5_720p_i2v_fp16.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"44": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"11",
0
],
"text": "The bull elk stands on the mossy granite ledge above the fog-filled valley at dusk. It lifts its heavy antlered head, exhales a long plume of breath that curls into the cold air, then turns its neck to look back over its shoulder toward the camera before stepping carefully forward along the rock edge, hooves slipping slightly on the wet stone. Below, thick pewter mist rolls slowly through the dark hemlocks and spills over the ridges like a slow tide. The camera starts close at the elk's shoulder and cranes up and out in one smooth move, rising above the ledge to reveal the full misty valley stretching away, with silver rim light flickering through breaks in the storm clouds. Cinematic wildlife footage, natural motion, steady and unhurried."
},
"_meta": {
"title": "CLIP Text Encode (Positive Prompt)"
}
},
"78": {
"class_type": "HunyuanVideo15ImageToVideo",
"inputs": {
"batch_size": 1,
"clip_vision_output": [
"79",
0
],
"height": 720,
"length": 121,
"negative": [
"93",
0
],
"positive": [
"44",
0
],
"start_image": [
"80",
0
],
"vae": [
"10",
0
],
"width": 1280
},
"_meta": {
"title": "HunyuanVideo15ImageToVideo"
}
},
"79": {
"class_type": "CLIPVisionEncode",
"inputs": {
"clip_vision": [
"81",
0
],
"crop": "center",
"image": [
"80",
0
]
},
"_meta": {
"title": "CLIP Vision Encode"
}
},
"80": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"81": {
"class_type": "CLIPVisionLoader",
"inputs": {
"clip_name": "sigclip_vision_patch14_384.safetensors"
},
"_meta": {
"title": "Load CLIP Vision"
}
},
"93": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"11",
0
],
"text": ""
},
"_meta": {
"title": "CLIP Text Encode (Negative Prompt)"
}
},
"101": {
"class_type": "CreateVideo",
"inputs": {
"bit_depth": "auto",
"codec": "none",
"color_space": "sRGB",
"fps": 24,
"images": [
"8",
0
]
},
"_meta": {
"title": "Create Video"
}
},
"102": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/hunyuan_video_1.5",
"format": "auto",
"format.codec": "h264",
"video": [
"101",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"125": {
"class_type": "SamplerCustomAdvanced",
"inputs": {
"guider": [
"129",
0
],
"latent_image": [
"78",
2
],
"noise": [
"127",
0
],
"sampler": [
"128",
0
],
"sigmas": [
"126",
0
]
},
"_meta": {
"title": "SamplerCustomAdvanced"
}
},
"126": {
"class_type": "BasicScheduler",
"inputs": {
"denoise": 1,
"model": [
"12",
0
],
"scheduler": "simple",
"steps": 20
},
"_meta": {
"title": "BasicScheduler"
}
},
"127": {
"class_type": "RandomNoise",
"inputs": {
"noise_seed": 887963123424675
},
"_meta": {
"title": "RandomNoise"
}
},
"128": {
"class_type": "KSamplerSelect",
"inputs": {
"sampler_name": "euler"
},
"_meta": {
"title": "KSamplerSelect"
}
},
"129": {
"class_type": "CFGGuider",
"inputs": {
"cfg": 6,
"model": [
"130",
0
],
"negative": [
"78",
1
],
"positive": [
"78",
0
]
},
"_meta": {
"title": "CFG Guider"
}
},
"130": {
"class_type": "ModelSamplingSD3",
"inputs": {
"model": [
"12",
0
],
"shift": 7
},
"_meta": {
"title": "ModelSamplingSD3"
}
}
})
workflow.set_input("80", "image", client.assets.from_url("https://comfy.org/catalog-media/d312a006-8814-4525-9416-61b1de7a21ed/bea0b5d9-b558-48de-9899-f526d73b354f"))
# 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("102"):
output.to_file(output.name)