# 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": "CLIPLoader",
"inputs": {
"clip_name": "qwen_3_4b.safetensors",
"device": "default",
"type": "lumina2"
},
"_meta": {
"title": "Load CLIP"
}
},
"93": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "ae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"94": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"112",
0
],
"vae": [
"93",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"95": {
"class_type": "ConditioningZeroOut",
"inputs": {
"conditioning": [
"99",
0
]
},
"_meta": {
"title": "Conditioning Zero Out"
}
},
"96": {
"class_type": "DifferentialDiffusion",
"inputs": {
"model": [
"98",
0
],
"strength": 1
},
"_meta": {
"title": "Differential Diffusion"
}
},
"98": {
"class_type": "ModelSamplingAuraFlow",
"inputs": {
"model": [
"109",
0
],
"sampling": "flow",
"shift": 3
},
"_meta": {
"title": "ModelSamplingAuraFlow"
}
},
"99": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"92",
0
],
"text": "sunglasses."
},
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"100": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "Z-Image-Turbo",
"images": [
"94",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"101": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "z_image_turbo_bf16.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"103": {
"class_type": "ModelPatchLoader",
"inputs": {
"name": "Z-Image-Turbo-Fun-Controlnet-Union-2.1.safetensors"
},
"_meta": {
"title": "Load Model Patch"
}
},
"105": {
"class_type": "InpaintModelConditioning",
"inputs": {
"mask": [
"108:184",
0
],
"negative": [
"95",
0
],
"noise_mask": True,
"pixels": [
"108:181",
0
],
"positive": [
"99",
0
],
"vae": [
"93",
0
]
},
"_meta": {
"title": "InpaintModelConditioning"
}
},
"106": {
"class_type": "MaskPreview",
"inputs": {
"mask": [
"108:184",
0
]
},
"_meta": {
"title": "Preview Mask"
}
},
"107": {
"class_type": "LoadImage",
"inputs": {
"image": "gsc_creator_2_2_input.png"
},
"_meta": {
"title": "Load Image"
}
},
"109": {
"class_type": "ZImageFunControlnet",
"inputs": {
"end_percent": 1,
"image": [
"108:181",
0
],
"inpaint_image": [
"108:181",
0
],
"mask": [
"108:184",
0
],
"model": [
"101",
0
],
"model_patch": [
"103",
0
],
"start_percent": 0,
"strength": 1,
"vae": [
"93",
0
]
},
"_meta": {
"title": "Apply Fun ControlNet"
}
},
"112": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"105",
2
],
"model": [
"96",
0
],
"negative": [
"105",
1
],
"positive": [
"105",
0
],
"sampler_name": "res_multistep",
"scheduler": "simple",
"seed": 467616719697168,
"steps": 9
},
"_meta": {
"title": "KSampler"
}
},
"122": {
"class_type": "ImageStitch",
"inputs": {
"direction": "down",
"image1": [
"107",
0
],
"image2": [
"94",
0
],
"match_image_size": True,
"spacing_color": "white",
"spacing_width": 0
},
"_meta": {
"title": "Stitch Images"
}
},
"123": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"122",
0
]
},
"_meta": {
"title": "Preview Image"
}
},
"108:181": {
"class_type": "ImageResize+",
"inputs": {
"condition": "always",
"height": 1024,
"image": [
"107",
0
],
"interpolation": "lanczos",
"method": "keep proportion",
"multiple_of": 0,
"width": 1024
},
"_meta": {
"title": "đ§ Image Resize"
}
},
"108:182": {
"class_type": "ImageResize+",
"inputs": {
"condition": "always",
"height": 1024,
"image": [
"108:183",
0
],
"interpolation": "lanczos",
"method": "keep proportion",
"multiple_of": 0,
"width": 1024
},
"_meta": {
"title": "đ§ Image Resize"
}
},
"108:183": {
"class_type": "MaskToImage",
"inputs": {
"mask": [
"107",
1
]
},
"_meta": {
"title": "Convert Mask to Image"
}
},
"108:184": {
"class_type": "ImageToMask",
"inputs": {
"channel": "red",
"image": [
"108:182",
0
]
},
"_meta": {
"title": "Convert Image to Mask"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)