# 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": "z-image",
"images": [
"76:65",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"76:62": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "qwen_3_4b.safetensors",
"device": "default",
"type": "lumina2"
},
"_meta": {
"title": "Load CLIP"
}
},
"76:63": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "ae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"76:65": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"76:69",
0
],
"vae": [
"76:63",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"76:66": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "z_image_bf16.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"76:67": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"76:62",
0
],
"text": "A dramatic 1980s avant-garde fashion editorial portrait captures a young adult with an arresting, graphic presence, featuring an ultra-sharp bleached geometric buzzcut, stark black angular eye paint, and an exaggerated, structured metallic-gold lamé power suit with sculpted pagoda shoulders. The figure stands off-center across an endless expanse of cracked obsidian salt flats that stretch toward the distant, haze-shrouded horizon line. Towering, razor-sharp crystalline spires rise from the dark mineral crust under a bruised violet twilight sky. Low-angle, harsh golden spotlighting cuts violently through rising sulfur steam, carving deep chiaroscuro shadows across the gleaming landscape and casting long, razor-thin silhouettes across the vast, uninterrupted ground. The atmosphere is tense, theatrical, and darkly sublime."
},
"_meta": {
"title": "CLIP Text Encode (Positive Prompt)"
}
},
"76:68": {
"class_type": "EmptySD3LatentImage",
"inputs": {
"batch_size": 1,
"height": 768,
"width": 1344
},
"_meta": {
"title": "EmptySD3LatentImage"
}
},
"76:69": {
"class_type": "KSampler",
"inputs": {
"cfg": 4,
"denoise": 1,
"latent_image": [
"76:68",
0
],
"model": [
"76:70",
0
],
"negative": [
"76:71",
0
],
"positive": [
"76:67",
0
],
"sampler_name": "res_multistep",
"scheduler": "simple",
"seed": 770044821593082,
"steps": 25
},
"_meta": {
"title": "KSampler"
}
},
"76:70": {
"class_type": "ModelSamplingAuraFlow",
"inputs": {
"model": [
"76:66",
0
],
"sampling": "flow",
"shift": 3
},
"_meta": {
"title": "ModelSamplingAuraFlow"
}
},
"76:71": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"76:62",
0
],
"text": ""
},
"_meta": {
"title": "CLIP Text Encode (Negative Prompt)"
}
}
})
# 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("9"):
output.to_file(output.name)