# 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({
"1": {
"class_type": "FL_PromptSelectorBasic",
"inputs": {
"index": [
"37",
0
],
"prompts": "Low-angle macro photograph of a single unfurling fern frond centered on wet black slate at stormy dusk, captured with a 90mm lens, beaded with rain droplets, cool indigo shadows and faint stormy rim light.\nLow-angle macro photograph of a single ruptured milkweed seed pod centered on wet black slate at stormy dusk, captured with a 90mm lens, beaded with rain droplets, cool indigo shadows and faint stormy rim light.\nLow-angle macro photograph of a single sprouted tulip bulb centered on wet black slate at stormy dusk, captured with a 90mm lens, beaded with rain droplets, cool indigo shadows and faint stormy rim light.\nLow-angle macro photograph of a single weathered pine cone centered on wet black slate at stormy dusk, captured with a 90mm lens, beaded with rain droplets, cool indigo shadows and faint stormy rim light."
},
"_meta": {
"title": "FL Prompt Selector Basic"
}
},
"36": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"47:42",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"37": {
"class_type": "PrimitiveInt",
"inputs": {
"value": 1
},
"_meta": {
"title": "Int"
}
},
"47:34": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"47:45",
0
],
"model": [
"47:46",
0
],
"negative": [
"47:41",
0
],
"positive": [
"47:44",
0
],
"sampler_name": "res_multistep",
"scheduler": "simple",
"seed": 577429684457215,
"steps": 4
},
"_meta": {
"title": "KSampler"
}
},
"47:39": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "qwen_3_4b.safetensors",
"device": "default",
"type": "lumina2"
},
"_meta": {
"title": "Load CLIP"
}
},
"47:40": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "ae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"47:41": {
"class_type": "ConditioningZeroOut",
"inputs": {
"conditioning": [
"47:44",
0
]
},
"_meta": {
"title": "Conditioning Zero Out"
}
},
"47:42": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"47:34",
0
],
"vae": [
"47:40",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"47:43": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "z_image_turbo_bf16.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"47:44": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"47:39",
0
],
"text": [
"1",
0
]
},
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"47:45": {
"class_type": "EmptySD3LatentImage",
"inputs": {
"batch_size": 1,
"height": 768,
"width": 1344
},
"_meta": {
"title": "EmptySD3LatentImage"
}
},
"47:46": {
"class_type": "ModelSamplingAuraFlow",
"inputs": {
"model": [
"47:43",
0
],
"sampling": "flow",
"shift": 3
},
"_meta": {
"title": "ModelSamplingAuraFlow"
}
}
})
# 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("36"):
output.to_file(output.name)