# 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": 1024,
"width": 1024
},
"_meta": {
"title": "EmptySD3LatentImage"
}
},
"57:27": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"57:30",
0
],
"text": "Photorealistic close-up portrait of a weathered stunt\ncoordinator in his sixties, deep wrinkles around tired\neyes, gray stubble, faded leather jacket, harsh practical\nkey light from camera right casting deep shadows on the\nleft side of his face, smoke from a nearby fire pit\ndrifting through frame, golden hour rim light catching\nthe edge of his hair, shallow depth of field, 50mm at\nf/1.8, dust particles in the light beams, high detail\nskin texture."
},
"_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": 470072989198643,
"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)