# 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({
"92": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/MiniMax_H3",
"format": "auto",
"format.codec": "auto",
"video": [
"105:91",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"114": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"115": {
"class_type": "ResolutionSelector",
"inputs": {
"aspect_ratio": "16:9 (Widescreen)",
"megapixels": 0.4,
"multiple": 32
},
"_meta": {
"title": "Resolution Selector"
}
},
"119": {
"class_type": "ImageScaleToTotalPixels",
"inputs": {
"megapixels": 1,
"resolution_steps": 32,
"upscale_method": "nearest-exact"
},
"_meta": {
"title": "Scale Image to Total Pixels"
}
},
"120": {
"class_type": "GetImageSize",
"inputs": {
"image": [
"119",
0
]
},
"_meta": {
"title": "Get Image Size"
}
},
"105:10": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"105:14",
0
],
"vae": [
"105:11",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"105:104": {
"class_type": "MiniMaxH3ImageToVideo",
"inputs": {
"clip": [
"105:13",
0
],
"first_frame": [
"114",
0
],
"height": [
"115",
1
],
"length": [
"105:107",
1
],
"prompt": "Clean premium beverage commercial look: bright white studio, crisp specular highlights, cool condensation, mood refreshing and confident. Timeline: [0s–2s] slow push-in on the chilled can as condensation droplets bead and roll down the label; [2s–4s] a wisp of cold mist drifts past the can; [4s–5s] a light sweep glides across the halftone circle and settles on the \"Soda\" lettering. Audio: a crisp can-opening hiss and fizz, a soft chime on the light sweep. Keep label text unchanged and legible, no added text, no soft dissolves, no subtitle bars.",
"vae": [
"105:11",
0
],
"width": [
"115",
0
]
},
"_meta": {
"title": "MiniMax H3 Image to Video"
}
},
"105:107": {
"class_type": "ComfyMathExpression",
"inputs": {
"expression": "max(5, round(a * 24)) + (5 - (max(5, round(a * 24)) % 17)) % 17",
"values.a": [
"105:111",
0
]
},
"_meta": {
"title": "Math Expression"
}
},
"105:11": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "minimax_h3_video_vae_fp16.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"105:111": {
"class_type": "PrimitiveFloat",
"inputs": {
"value": 5
},
"_meta": {
"title": "Float (duration)"
}
},
"105:13": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "qwen3vl_32b_minimax_h3_nvfp4_awq.safetensors",
"device": "default",
"type": "minimax"
},
"_meta": {
"title": "Load CLIP"
}
},
"105:14": {
"class_type": "SamplerCustomAdvanced",
"inputs": {
"guider": [
"105:16",
0
],
"latent_image": [
"105:104",
1
],
"noise": [
"105:15",
0
],
"sampler": [
"105:17",
0
],
"sigmas": [
"105:9",
0
]
},
"_meta": {
"title": "SamplerCustomAdvanced"
}
},
"105:15": {
"class_type": "RandomNoise",
"inputs": {
"noise_seed": 168866841893410
},
"_meta": {
"title": "RandomNoise"
}
},
"105:16": {
"class_type": "BasicGuider",
"inputs": {
"conditioning": [
"105:104",
0
],
"model": [
"105:6",
0
]
},
"_meta": {
"title": "Basic Guider"
}
},
"105:17": {
"class_type": "KSamplerSelect",
"inputs": {
"sampler_name": "res_multistep"
},
"_meta": {
"title": "KSamplerSelect"
}
},
"105:23": {
"class_type": "VAEDecodeAudio",
"inputs": {
"samples": [
"105:14",
0
],
"vae": [
"105:24",
0
]
},
"_meta": {
"title": "VAE Decode Audio"
}
},
"105:24": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "minimax_h3_audio_vae_fp32.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"105:6": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "minimax_h3_fl2va_pruned_int8_convrot.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"105:9": {
"class_type": "BasicScheduler",
"inputs": {
"denoise": 1,
"model": [
"105:6",
0
],
"scheduler": "simple",
"steps": 20
},
"_meta": {
"title": "BasicScheduler"
}
},
"105:91": {
"class_type": "CreateVideo",
"inputs": {
"audio": [
"105:23",
0
],
"bit_depth": 8,
"codec": "none",
"color_space": "sRGB",
"fps": 24,
"images": [
"105:10",
0
]
},
"_meta": {
"title": "Create Video"
}
}
})
workflow.set_input("114", "image", client.assets.from_url("https://comfy.org/catalog-media/7b9a7f69-e2f4-410d-9288-1f4935965877/6a5ee2d7-967d-4c7c-aac8-5c35fb479b64"))
# 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("92"):
output.to_file(output.name)