# 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": "SaveImage",
"inputs": {
"filename_prefix": "image_p_h3_t2i",
"images": [
"29:15",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"32": {
"class_type": "ResolutionSelector",
"inputs": {
"aspect_ratio": "16:9 (Widescreen)",
"megapixels": 4,
"multiple": 32
},
"_meta": {
"title": "Resolution Selector"
}
},
"29:1": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "minimax_h3_fl2va_pruned_int8_convrot.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"29:10": {
"class_type": "BasicGuider",
"inputs": {
"conditioning": [
"29:9",
0
],
"model": [
"29:18",
0
]
},
"_meta": {
"title": "Basic Guider"
}
},
"29:11": {
"class_type": "KSamplerSelect",
"inputs": {
"sampler_name": "er_sde"
},
"_meta": {
"title": "KSamplerSelect"
}
},
"29:12": {
"class_type": "RandomNoise",
"inputs": {
"noise_seed": 573653164445910
},
"_meta": {
"title": "RandomNoise"
}
},
"29:13": {
"class_type": "ManualSigmas",
"inputs": {
"sigmas": "1.0, 0.984753, 0.967905, 0.951688, 0.925372, 0.881923, 0.810083, 0.528718, 0.0"
},
"_meta": {
"title": "ManualSigmas"
}
},
"29:14": {
"class_type": "SamplerCustomAdvanced",
"inputs": {
"guider": [
"29:10",
0
],
"latent_image": [
"29:9",
1
],
"noise": [
"29:12",
0
],
"sampler": [
"29:11",
0
],
"sigmas": [
"29:13",
0
]
},
"_meta": {
"title": "SamplerCustomAdvanced"
}
},
"29:15": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"29:14",
0
],
"vae": [
"29:3",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"29:18": {
"class_type": "MiniMaxH3SigmaShift",
"inputs": {
"model": [
"29:19",
0
],
"shift_audio": 1,
"shift_video": 1
},
"_meta": {
"title": "ModelSamplingMiniMaxH3 (keep at 1.0)"
}
},
"29:19": {
"class_type": "LoraLoaderModelOnly",
"inputs": {
"lora_name": "p-h3-image_lora_bf16.safetensors",
"model": [
"29:1",
0
],
"strength_model": 1
},
"_meta": {
"title": "Load LoRA"
}
},
"29:2": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "p-h3-image_text_encoder_int8_convrot.safetensors",
"device": "default",
"type": "minimax"
},
"_meta": {
"title": "Text encoder"
}
},
"29:23": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"29:24",
0
],
"on_true": [
"29:33",
0
],
"switch": True
},
"_meta": {
"title": "If/Else Switch"
}
},
"29:24": {
"class_type": "PrimitiveStringMultiline",
"inputs": {
"value": "A view across a salt flat at first light, where a rusted observatory dome sits half sunk in the crust, its white paint blistered and peeling away in long flakes. Thin standing water mirrors the dome and the pale pink sky, breaking into ripples where a low wind crosses it. Weathered steel stairs climb to a sealed hatch, sand drifted into the treads. In the far distance a line of dead power poles recedes into haze. Soft dawn light rakes in from the left, picking out the texture of the salt crust and the rivets on the dome, with cool blue shadow in the foreground. Medium format camera, deep focus, fine grain, muted natural colour, no text."
},
"_meta": {
"title": "Text (Prompt)"
}
},
"29:3": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "p-h3-image_vae_int8_convrot.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"29:33": {
"class_type": "TextGenerateV2",
"inputs": {
"clip": [
"29:4",
0
],
"max_length": 1536,
"mtp": "auto",
"prompt": [
"29:24",
0
],
"sampling_mode": "off",
"thinking": True,
"use_default_template": True
},
"_meta": {
"title": "Generate Text"
}
},
"29:4": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "p-h3-image_prompt_upsampler_w4a8.safetensors",
"device": "default",
"type": "minimax"
},
"_meta": {
"title": "Prompt upsampler model"
}
},
"29:8": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"29:23",
0
]
},
"_meta": {
"title": "Upsampled prompt"
}
},
"29:9": {
"class_type": "PH3ImageConditioning",
"inputs": {
"clip": [
"29:2",
0
],
"height": [
"32",
1
],
"prompt": [
"29:8",
0
],
"vae": [
"29:3",
0
],
"width": [
"32",
0
]
},
"_meta": {
"title": "p-h3-image Conditioning"
}
}
})
# 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)