# 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_PromptMulti",
"inputs": {
"name_prefix": "prompt_",
"negative_text": "",
"positive_text": "An ultra-wide tracking shot captures a weathered elderly Bedouin man in a billowing saffron tunic urging his galloping racing camel beside a swift Arabian stallion. Sunset bathes the sweeping red dunes in amber light, kicking up vibrant golden dust clouds beneath them.\nA grainy analog film photograph captures a defiant woman in tattered wool standing beside a roaring timber bonfire atop a snow-dusted medieval cliffside. Distant misty peaks stretch across the cold twilight background, illuminated by flickering embers and deep chiaroscuro shadows.\nA wide-angle, directly overhead flat-lay view of an opulent ancient Roman banquet table. Low wooden couches surround a feast of roasted figs, silver chalices, and peacock feathers across emerald mosaic tiling, bathed in cool moonlight and pale turquoise ambient glow."
},
"_meta": {
"title": "FL Prompt Multi"
}
},
"36": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "z_image_turbo",
"images": [
"47:41",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"47:38": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "qwen_3_4b.safetensors",
"device": "default",
"type": "lumina2"
},
"_meta": {
"title": "Load CLIP"
}
},
"47:39": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "ae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"47:40": {
"class_type": "ConditioningZeroOut",
"inputs": {
"conditioning": [
"47:43",
0
]
},
"_meta": {
"title": "Conditioning Zero Out"
}
},
"47:41": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"47:45",
0
],
"vae": [
"47:39",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"47:42": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "z_image_turbo_bf16.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"47:43": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"47:38",
0
],
"text": [
"1",
0
]
},
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"47:44": {
"class_type": "EmptySD3LatentImage",
"inputs": {
"batch_size": 1,
"height": 768,
"width": 1344
},
"_meta": {
"title": "EmptySD3LatentImage"
}
},
"47:45": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"47:44",
0
],
"model": [
"47:42",
0
],
"negative": [
"47:40",
0
],
"positive": [
"47:43",
0
],
"sampler_name": "res_multistep",
"scheduler": "simple",
"seed": 102335344008304,
"steps": 4
},
"_meta": {
"title": "KSampler"
}
}
})
# 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)