# 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({
"4": {
"class_type": "CheckpointLoaderSimple",
"inputs": {
"ckpt_name": "sd_xl_base_1.0.safetensors"
},
"_meta": {
"title": "Load Checkpoint - BASE"
}
},
"5": {
"class_type": "EmptyLatentImage",
"inputs": {
"batch_size": 1,
"height": 768,
"width": 1344
},
"_meta": {
"title": "Empty Latent Image"
}
},
"6": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"4",
1
],
"text": "An atmospheric retro-fantasy illustration captured from an elevated bird's-eye perspective with a panoramic 24mm wide-angle lens. At the center, a colossal floating dodecahedron carved from rough, porous volcanic basalt and veined raw malachite hovers majestically. Intricate fractal cracks glow with deep interior smoldering embers, casting soft rim lighting across its weathered, matte stone facets. Flanking canyon ridges and staggered sandstone buttes stretch endlessly toward distant horizon lines, shrouded in low-lying ochre dust and golden atmospheric haze. Gentle late-afternoon sunbeams rake across the arid valley floor, creating long sweeping umber shadows and warm terracotta highlights. The rich, earthy palette balances burnt sienna, dusty sage green, and muted copper with the fiery molten core of the monolith. Deep cinematic shadows and diffused twilight haze emphasize the vast, quiet expanse around the solitary geometric relic."
},
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"7": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"4",
1
],
"text": "text, watermark"
},
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"10": {
"class_type": "KSamplerAdvanced",
"inputs": {
"add_noise": "enable",
"cfg": 8,
"end_at_step": 20,
"latent_image": [
"5",
0
],
"model": [
"4",
0
],
"negative": [
"7",
0
],
"noise_seed": 6767725640732,
"positive": [
"6",
0
],
"return_with_leftover_noise": "enable",
"sampler_name": "euler",
"scheduler": "normal",
"start_at_step": 0,
"steps": 25
},
"_meta": {
"title": "KSampler (Advanced) - BASE"
}
},
"11": {
"class_type": "KSamplerAdvanced",
"inputs": {
"add_noise": "disable",
"cfg": 8,
"end_at_step": 10000,
"latent_image": [
"10",
0
],
"model": [
"12",
0
],
"negative": [
"16",
0
],
"noise_seed": 0,
"positive": [
"15",
0
],
"return_with_leftover_noise": "disable",
"sampler_name": "euler",
"scheduler": "normal",
"start_at_step": 20,
"steps": 25
},
"_meta": {
"title": "KSampler (Advanced) - REFINER"
}
},
"12": {
"class_type": "CheckpointLoaderSimple",
"inputs": {
"ckpt_name": "sd_xl_refiner_1.0.safetensors"
},
"_meta": {
"title": "Load Checkpoint - REFINER"
}
},
"15": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"12",
1
],
"text": "An atmospheric retro-fantasy illustration captured from an elevated bird's-eye perspective with a panoramic 24mm wide-angle lens. At the center, a colossal floating dodecahedron carved from rough, porous volcanic basalt and veined raw malachite hovers majestically. Intricate fractal cracks glow with deep interior smoldering embers, casting soft rim lighting across its weathered, matte stone facets. Flanking canyon ridges and staggered sandstone buttes stretch endlessly toward distant horizon lines, shrouded in low-lying ochre dust and golden atmospheric haze. Gentle late-afternoon sunbeams rake across the arid valley floor, creating long sweeping umber shadows and warm terracotta highlights. The rich, earthy palette balances burnt sienna, dusty sage green, and muted copper with the fiery molten core of the monolith. Deep cinematic shadows and diffused twilight haze emphasize the vast, quiet expanse around the solitary geometric relic."
},
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"16": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"12",
1
],
"text": "text, watermark"
},
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"17": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"11",
0
],
"vae": [
"12",
2
]
},
"_meta": {
"title": "VAE Decode"
}
},
"19": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"17",
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("19"):
output.to_file(output.name)