# 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({
"5": {
"class_type": "EmptyLatentImage",
"inputs": {
"batch_size": 1,
"height": 512,
"width": 912
},
"_meta": {
"title": "Empty Latent Image"
}
},
"6": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"20",
1
],
"text": "On a rain-slicked basalt ledge outdoors during stormy dusk, a solitary still-life arrangement glows against the brooding, tempestuous indigo twilight. The single focal point is a squat, unbranded amber glass tincture bottle, drenched in glistening rainwater beads, balanced atop a rough slab of wet driftwood spanning the misty distant background. Beside it, a freshly sliced crimson blood orange rests flat, its radiant ruby pulp glistening with droplets and bleeding vivid juice across the dark volcanic stone. Dramatic, low-angled golden lantern light cuts through the damp fog, producing striking chiaroscuro contrasts, deep velvety shadows, and intense specular gleams along the polished glass shoulder. Rich crimson and electric amber hues starkly pierce the shadowy, charcoal-slate coastal landscape."
},
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"7": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"20",
1
],
"text": "text, watermark"
},
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"13",
0
],
"vae": [
"20",
2
]
},
"_meta": {
"title": "VAE Decode"
}
},
"13": {
"class_type": "SamplerCustom",
"inputs": {
"add_noise": True,
"cfg": 1,
"latent_image": [
"5",
0
],
"model": [
"20",
0
],
"negative": [
"7",
0
],
"noise_seed": 0,
"positive": [
"6",
0
],
"sampler": [
"14",
0
],
"sigmas": [
"22",
0
]
},
"_meta": {
"title": "SamplerCustom"
}
},
"14": {
"class_type": "KSamplerSelect",
"inputs": {
"sampler_name": "euler_ancestral"
},
"_meta": {
"title": "KSamplerSelect"
}
},
"20": {
"class_type": "CheckpointLoaderSimple",
"inputs": {
"ckpt_name": "sd_xl_turbo_1.0_fp16.safetensors"
},
"_meta": {
"title": "Load Checkpoint"
}
},
"22": {
"class_type": "SDTurboScheduler",
"inputs": {
"denoise": 1,
"model": [
"20",
0
],
"steps": 1
},
"_meta": {
"title": "SDTurboScheduler"
}
},
"27": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"8",
0
]
},
"_meta": {
"title": "Save Image"
}
}
})
# 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("27"):
output.to_file(output.name)