# 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({
"60": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "z-image-turbo",
"images": [
"83:8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"83:13": {
"class_type": "EmptySD3LatentImage",
"inputs": {
"batch_size": 1,
"height": 768,
"width": 1344
},
"_meta": {
"title": "EmptySD3LatentImage"
}
},
"83:27": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"83:30",
0
],
"text": "A surreal graphic poster set against a rain-drenched futuristic metropolis alleyway, where reflective puddles mirror flashing holographic billboards. In the center, a solitary bioluminescent lotus radiates an intense emerald and violet glow, its dew-covered petals pulsing with liquid light. Standing to the side, a slender young South Asian cybernetic courier with shaved temples and an iridescent teal topknot gazes at the blossom, wearing a soaked translucent vinyl trench coat over utilitarian dark mesh. Cascading rainwater and misty atmospheric vapor drift across the sprawling panoramic vista, blurring towering neon-lit architecture in the distance. Above the blooming aquatic flora, bold distressed typographic lettering reads \"AETHERIS\" in clean geometric stenciling. The visual combines wet urban grain, high-contrast shadows, and cinematic teal and magenta grading across the expansive composition."
},
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"83:28": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "z_image_turbo_bf16.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"83:29": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "ae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"83:3": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"83:13",
0
],
"model": [
"83:28",
0
],
"negative": [
"83:33",
0
],
"positive": [
"83:27",
0
],
"sampler_name": "res_multistep",
"scheduler": "simple",
"seed": 528562900154240,
"steps": 4
},
"_meta": {
"title": "KSampler"
}
},
"83:30": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "qwen_3_4b.safetensors",
"device": "default",
"type": "lumina2"
},
"_meta": {
"title": "Load CLIP"
}
},
"83:33": {
"class_type": "ConditioningZeroOut",
"inputs": {
"conditioning": [
"83:27",
0
]
},
"_meta": {
"title": "Conditioning Zero Out"
}
},
"83:8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"83:3",
0
],
"vae": [
"83:29",
0
]
},
"_meta": {
"title": "VAE Decode"
}
}
})
# 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("60"):
output.to_file(output.name)