# 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({
"9": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "image_minimax_h3_image_character_swap",
"images": [
"42",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"29": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "minimax_h3_image_pruned_int8_convrot.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"30": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "qwen3vl_32b_minimax_h3_int8_convrot.safetensors",
"device": "default",
"type": "minimax"
},
"_meta": {
"title": "Load CLIP"
}
},
"31": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "minimax_h3_image_vae_fp16.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"33": {
"class_type": "ConditioningZeroOut",
"inputs": {
"conditioning": [
"65",
0
]
},
"_meta": {
"title": "Conditioning Zero Out"
}
},
"38": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"65",
1
],
"model": [
"63",
0
],
"negative": [
"33",
0
],
"positive": [
"65",
0
],
"sampler_name": "euler",
"scheduler": "simple",
"seed": 142232601287349,
"steps": 6
},
"_meta": {
"title": "KSampler"
}
},
"42": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"38",
0
],
"vae": [
"31",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"43": {
"class_type": "PrimitiveStringMultiline",
"inputs": {
"value": "Swap the human in <Picture 1> with human <Picture 2>, also update the human in the mirror"
},
"_meta": {
"title": "Text (user_prompt)"
}
},
"45": {
"class_type": "LoadImage",
"inputs": {
"image": "h3_char_swap_source.png"
},
"_meta": {
"title": "Load Image (Source Image)"
}
},
"48": {
"class_type": "ResizeImageMaskNode",
"inputs": {
"input": [
"56",
0
],
"resize_type": "scale to multiple",
"resize_type.multiple": 32,
"scale_method": "area"
},
"_meta": {
"title": "Resize Image/Mask"
}
},
"50": {
"class_type": "GetImageSize",
"inputs": {
"image": [
"48",
0
]
},
"_meta": {
"title": "Get Image Size"
}
},
"56": {
"class_type": "ResizeImageMaskNode",
"inputs": {
"input": [
"45",
0
],
"resize_type": "scale total pixels",
"resize_type.megapixels": 1,
"scale_method": "area"
},
"_meta": {
"title": "Resize Image/Mask"
}
},
"62": {
"class_type": "ImageCompare",
"inputs": {
"compare_view": None,
"image_a": [
"48",
0
],
"image_b": [
"9",
0
]
},
"_meta": {
"title": "Compare Images"
}
},
"63": {
"class_type": "LoadLoraModel",
"inputs": {
"loras.0.enabled": True,
"loras.0.lora_name": "h3_image_character_swap_v1.safetensors",
"loras.0.strength": 1,
"model": [
"29",
0
]
},
"_meta": {
"title": "Load LoRA (Model)"
}
},
"64": {
"class_type": "LoadImage",
"inputs": {
"image": "h3_char_swap_reference.png"
},
"_meta": {
"title": "Load Image (Reference Character)"
}
},
"65": {
"class_type": "MiniMaxH3ImageConditioning",
"inputs": {
"clip": [
"30",
0
],
"height": [
"50",
1
],
"images.image_0": [
"48",
0
],
"images.image_1": [
"64",
0
],
"prompt": [
"43",
0
],
"vae": [
"31",
0
],
"width": [
"50",
0
]
},
"_meta": {
"title": "MiniMax H3 Image Conditioning"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)