# 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-turbo",
"images": [
"57:8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"57:11": {
"class_type": "ModelSamplingAuraFlow",
"inputs": {
"model": [
"57:28",
0
],
"sampling": "flow",
"shift": 3
},
"_meta": {
"title": "ModelSamplingAuraFlow"
}
},
"57:13": {
"class_type": "EmptySD3LatentImage",
"inputs": {
"batch_size": 1,
"height": 720,
"width": 1280
},
"_meta": {
"title": "EmptySD3LatentImage"
}
},
"57:27": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"57:30",
0
],
"text": "A wide-shot, eye-level photograph captures a lone Apollo astronaut standing beside a Lunar Roving Vehicle on the desolate moonscape. The astronaut’s white pressure suit, thick with wrinkled fabric folds, ribbed joints, and mechanical anodized connectors, glimmers under harsh, unfiltered sunlight. Subtle smudges of dark lunar dust cling to the knees and cuffs of the multi-layered garment. A gold-tinted reflective visor obscures their face, mirroring the stark, curved horizon and the bright specular highlight of the blazing sun, while a bulky white Portable Life Support System backpack, fitted with delicate telemetry sensors, is mounted to their rear. \n\nParked beside them, the metallic silver rover features distinctive red-orange fenders over wire-mesh wheels, which leave clear, geometric chevron tread patterns pressed deeply into the powdery, fine gray dust. An umbrella-shaped high-gain mesh antenna protrudes upward, surrounded by various clamped equipment bundles, scientific payload containers, and gold-foil-wrapped experiments strapped with utilitarian nylon ties. \n\nThe immediate ground is an intricately disturbed expanse of charcoal and light-gray regolith, heavily tracked with overlapping tread marks, boot prints showing ribbed sole patterns, and scattered with sharp, fragmented basalt rocks and mini-impact craters. In the far background, massive, softly rounded lunar mountains rise solemnly against an absolute, vacuum-black, starless sky. \n\nThe scene is side-lit from the low left, casting stark, ink-black, razor-sharp shadows across the undulating, cratered terrain that dramatically emphasize the intense contrast. The entire frame is marked by evenly spaced, small black Reseau crosshairs, a technical artifact of the historic medium-format Hasselblad 70mm camera. The palette is dominated by stark monochromatic grays, powdery whites, and obsidian shadows, punctuated solely by the mirrored gold visor, the vehicle's rust-colored accents, and delicate yellow thermal tape, all rendered with sharp, hyper-focused clarity and an infinite depth of field."
},
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"57:28": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "z_image_turbo_bf16.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"57:29": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "ae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"57:3": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"57:13",
0
],
"model": [
"57:11",
0
],
"negative": [
"57:33",
0
],
"positive": [
"57:27",
0
],
"sampler_name": "res_multistep",
"scheduler": "simple",
"seed": 0,
"steps": 8
},
"_meta": {
"title": "KSampler"
}
},
"57:30": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "qwen_3_4b.safetensors",
"device": "default",
"type": "lumina2"
},
"_meta": {
"title": "Load CLIP"
}
},
"57:33": {
"class_type": "ConditioningZeroOut",
"inputs": {
"conditioning": [
"57:27",
0
]
},
"_meta": {
"title": "Conditioning Zero Out"
}
},
"57:8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"57:3",
0
],
"vae": [
"57: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("9"):
output.to_file(output.name)