# 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({
"3": {
"class_type": "KSampler",
"inputs": {
"cfg": 4.01,
"denoise": 1,
"latent_image": [
"53",
0
],
"model": [
"4",
0
],
"negative": [
"40",
0
],
"positive": [
"16",
0
],
"sampler_name": "euler",
"scheduler": "sgm_uniform",
"seed": 585483408983215,
"steps": 20
},
"_meta": {
"title": "KSampler"
}
},
"4": {
"class_type": "CheckpointLoaderSimple",
"inputs": {
"ckpt_name": "sd3.5_large_fp8_scaled.safetensors"
},
"_meta": {
"title": "Load Checkpoint"
}
},
"8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"3",
0
],
"vae": [
"4",
2
]
},
"_meta": {
"title": "VAE Decode"
}
},
"9": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"16": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"4",
1
],
"text": "A richly detailed painted illustration of an ancient, hulking reptilian drake-folk shaman standing full-length amid a vast expanse of scorched volcanic badlands and smoking fissures. The venerable saurian has thick, weathered emerald-and-bronze scales, deep-set cataract-filmed golden eyes, and long, braided silver-white spines cascading down its hunched shoulders. Clad in archaic Bronze Age ceremonial regalia of hammered verdigris copper plates, coarse crimson weaves, and polished bone talismans, it leans upon a massive gnarled staff topped with a smoldering amber brazier. Wisps of ember-sparked gold smoke drift across the sprawling landscape, illuminating cracked obsidian earth and distant jagged crags under a low-hanging twilight sky. Warm ochre, fiery rust, and deep jade tones harmonize across the atmospheric expanse."
},
"_meta": {
"title": "Positive Prompt"
}
},
"40": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"4",
1
],
"text": ""
},
"_meta": {
"title": "Negative Prompt"
}
},
"53": {
"class_type": "EmptySD3LatentImage",
"inputs": {
"batch_size": 1,
"height": 768,
"width": 1344
},
"_meta": {
"title": "EmptySD3LatentImage"
}
}
})
# 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("9"):
output.to_file(output.name)