# 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": "A monolithic modular spacecraft glides horizontally in low orbit, stretching across the vast, sweeping curve of an ochre-hued cratered planet. The vessel features stark white habitat pods and intricate mechanical lattices, intersected by a prominent, segmented centrifuge ring encircling its spine. Thin metallic spokes cast sharp, geometric shadows over ribbed orange propellant tanks that define the ship’s elongated midsection. Hard, directional sunlight strikes from the upper left, carving brilliant highlights and ink-black shadows across the industrial structure. Below, the sprawling planetary horizon reveals rugged impact basins, dusty canyons, and a crisp terminator line transitioning into the void of space. A delicate blue-grey atmospheric haze hugs the planet's distant edge, emphasizing the colossal scale and silence of orbital transit."
},
"_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": 721897303308196,
"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": "A monolithic modular spacecraft glides horizontally in low orbit, stretching across the vast, sweeping curve of an ochre-hued cratered planet. The vessel features stark white habitat pods and intricate mechanical lattices, intersected by a prominent, segmented centrifuge ring encircling its spine. Thin metallic spokes cast sharp, geometric shadows over ribbed orange propellant tanks that define the ship’s elongated midsection. Hard, directional sunlight strikes from the upper left, carving brilliant highlights and ink-black shadows across the industrial structure. Below, the sprawling planetary horizon reveals rugged impact basins, dusty canyons, and a crisp terminator line transitioning into the void of space. A delicate blue-grey atmospheric haze hugs the planet's distant edge, emphasizing the colossal scale and silence of orbital transit."
},
"_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)