# 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": {
"codec": "auto",
"filename_prefix": "video/MiniMax_H3",
"format": "auto",
"format.codec": "auto",
"video": [
"105:91",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"136": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"141": {
"class_type": "GetImageSize",
"inputs": {
"image": [
"142",
0
]
},
"_meta": {
"title": "Get Image Size"
}
},
"142": {
"class_type": "ImageScaleToTotalPixels",
"inputs": {
"image": [
"136",
0
],
"megapixels": 0.4,
"resolution_steps": 32,
"upscale_method": "nearest-exact"
},
"_meta": {
"title": "Scale Image to Total Pixels"
}
},
"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": [
"136",
0
],
"height": [
"141",
1
],
"length": [
"105:107",
1
],
"prompt": "For the target video, at 0.00 seconds into the target video, <Picture 1> is fully referenced as the first frame. Single continuous first-person shot as the rider pedals along the coastal road at an easy pace. The camera moves steadily forward with a gentle sway from each pedal stroke, and the handlebars tilt slightly as the road curves left along the seawall. Waves roll in and break against the boulders on the right, throwing bright spray into the low morning sun. Loose strands of dark hair flick across the top corner of the frame in the breeze. Hydrangeas, wooden houses and pines slide past on the left, and the small mint van drifts by in its driveway. Sound: tyres rolling on damp asphalt, the soft tick of the freewheel, surf, distant gulls and one cheerful ring of the brass bell.",
"vae": [
"105:11",
0
],
"width": [
"141",
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:127": {
"class_type": "BlockSparseAttention",
"inputs": {
"dense_blocks": "",
"end_percent": 1,
"extra_tokens": 256,
"min_tokens": 12288,
"model": [
"105:128",
0
],
"selection": "vsa",
"selection.keep_percent": 10,
"sink_conditioning": "exact_kv_and_rows",
"start_percent": 0.2,
"verbose": False
},
"_meta": {
"title": "Model Sparse Attention"
}
},
"105:128": {
"class_type": "ModelAttentionBackend",
"inputs": {
"attention": "comfy kitchen attention",
"model": [
"105:143",
0
]
},
"_meta": {
"title": "Model Attention Backend"
}
},
"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:143": {
"class_type": "MiniMaxH3SigmaShift",
"inputs": {
"model": [
"105:6",
0
],
"shift_audio": 3,
"shift_video": 10
},
"_meta": {
"title": "ModelSamplingMiniMaxH3"
}
},
"105:15": {
"class_type": "RandomNoise",
"inputs": {
"noise_seed": 793369680225544
},
"_meta": {
"title": "RandomNoise"
}
},
"105:16": {
"class_type": "BasicGuider",
"inputs": {
"conditioning": [
"105:104",
0
],
"model": [
"105:127",
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": "fastvideo_fasth3_8step_v2_pruned_int8_convrot.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"105:9": {
"class_type": "BasicScheduler",
"inputs": {
"denoise": 1,
"model": [
"105:127",
0
],
"scheduler": "simple",
"steps": 8
},
"_meta": {
"title": "BasicScheduler"
}
},
"105:91": {
"class_type": "CreateVideo",
"inputs": {
"audio": [
"105:23",
0
],
"bit_depth": "auto",
"codec": "none",
"color_space": "sRGB",
"fps": 24,
"images": [
"105:10",
0
]
},
"_meta": {
"title": "Create Video"
}
}
})
workflow.set_input("136", "image", client.assets.from_url("https://comfy.org/catalog-media/bd97166a-0007-4b86-b965-6012011b21d5/23da989b-8dde-43f2-850d-b2d0c83ced74"))
# 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)