# 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({
"1": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "minimax_h3_fl2va_pruned_int8_convrot.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"2": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "p-h3-image_text_encoder_int8_convrot.safetensors",
"device": "default",
"type": "minimax"
},
"_meta": {
"title": "Text encoder"
}
},
"3": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "p-h3-image_vae_int8_convrot.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"4": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "p-h3-image_prompt_upsampler_w4a8.safetensors",
"device": "default",
"type": "minimax"
},
"_meta": {
"title": "Prompt upsampler model"
}
},
"8": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"23",
0
]
},
"_meta": {
"title": "Upsampled prompt"
}
},
"9": {
"class_type": "PH3ImageConditioning",
"inputs": {
"clip": [
"2",
0
],
"height": [
"27",
1
],
"images.image_1": [
"26",
0
],
"prompt": [
"8",
0
],
"vae": [
"3",
0
],
"width": [
"27",
0
]
},
"_meta": {
"title": "p-h3-image Conditioning"
}
},
"10": {
"class_type": "BasicGuider",
"inputs": {
"conditioning": [
"9",
0
],
"model": [
"18",
0
]
},
"_meta": {
"title": "Basic Guider"
}
},
"11": {
"class_type": "KSamplerSelect",
"inputs": {
"sampler_name": "er_sde"
},
"_meta": {
"title": "KSamplerSelect"
}
},
"12": {
"class_type": "RandomNoise",
"inputs": {
"noise_seed": 691899913323484
},
"_meta": {
"title": "RandomNoise"
}
},
"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"
}
},
"14": {
"class_type": "SamplerCustomAdvanced",
"inputs": {
"guider": [
"10",
0
],
"latent_image": [
"9",
1
],
"noise": [
"12",
0
],
"sampler": [
"11",
0
],
"sigmas": [
"13",
0
]
},
"_meta": {
"title": "SamplerCustomAdvanced"
}
},
"15": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"14",
0
],
"vae": [
"3",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"16": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "image_p_h3_image_edit",
"images": [
"15",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"18": {
"class_type": "MiniMaxH3SigmaShift",
"inputs": {
"model": [
"19",
0
],
"shift_audio": 1,
"shift_video": 1
},
"_meta": {
"title": "ModelSamplingMiniMaxH3 (keep at 1.0)"
}
},
"19": {
"class_type": "LoraLoaderModelOnly",
"inputs": {
"lora_name": "p-h3-image_lora_bf16.safetensors",
"model": [
"1",
0
],
"strength_model": 1
},
"_meta": {
"title": "Load LoRA"
}
},
"20": {
"class_type": "ImageCompare",
"inputs": {
"compare_view": {
"__value__": [
"",
""
]
},
"image_a": [
"16",
0
],
"image_b": [
"26",
0
]
},
"_meta": {
"title": "Compare Images"
}
},
"23": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"24",
0
],
"on_true": [
"29",
0
],
"switch": True
},
"_meta": {
"title": "If/Else Switch"
}
},
"24": {
"class_type": "PrimitiveStringMultiline",
"inputs": {
"value": "Change the season to deep winter. Frost creeps across the panes of the glass roof, the warm daylight turns cool, diffuse and blue grey, and a thin dusting of snow settles on the white edges of the wooden architectural model, on the black plinth and across the polished floor. Keep the model with its miniature trees and paths, the timber columns, the curved balconies and the framing exactly as they are, do not move, remove or add anything. Only relight the scene, shift the palette colder and add the frost and snow."
},
"_meta": {
"title": "Text (Prompt)"
}
},
"26": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"27": {
"class_type": "GetImageSize",
"inputs": {
"image": [
"26",
0
]
},
"_meta": {
"title": "Get Image Size"
}
},
"29": {
"class_type": "TextGenerateV2",
"inputs": {
"clip": [
"4",
0
],
"images.image1": [
"26",
0
],
"max_length": 1536,
"mtp": "auto",
"prompt": [
"24",
0
],
"sampling_mode": "off",
"thinking": True,
"use_default_template": True
},
"_meta": {
"title": "Generate Text"
}
}
})
workflow.set_input("26", "image", client.assets.from_url("https://comfy.org/catalog-media/77bddb83-01a0-4d3f-8826-d3b2a6b109c0/43ced963-cf1b-422d-b588-cb0260713182"))
# 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)