# 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({
"7": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "sdxl_simple",
"images": [
"14",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"10": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"15",
1
],
"text": "a giant classical marble statue standing alone in a pure white empty void, soft diffused lighting, subtle shadows, surreal, minimalist, fine art photography, quiet atmosphere, sense of scale"
},
"_meta": {
"title": "Positive Prompt"
}
},
"11": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"15",
1
],
"text": "color, colored, lowres, blurry, out of focus, deformed, bad anatomy, extra limbs, mutated, watermark, text, logo, signature\n"
},
"_meta": {
"title": "Negative Prompt"
}
},
"12": {
"class_type": "KSampler",
"inputs": {
"cfg": 7,
"denoise": 1,
"latent_image": [
"13",
0
],
"model": [
"15",
0
],
"negative": [
"11",
0
],
"positive": [
"10",
0
],
"sampler_name": "dpmpp_2m",
"scheduler": "karras",
"seed": 812045847300606,
"steps": 25
},
"_meta": {
"title": "KSampler"
}
},
"13": {
"class_type": "EmptyLatentImage",
"inputs": {
"batch_size": 1,
"height": 1024,
"width": 1024
},
"_meta": {
"title": "Empty Latent"
}
},
"14": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"12",
0
],
"vae": [
"15",
2
]
},
"_meta": {
"title": "VAE Decode"
}
},
"15": {
"class_type": "CheckpointLoaderSimple",
"inputs": {
"ckpt_name": "sd_xl_base_1.0.safetensors"
},
"_meta": {
"title": "Load Checkpoint"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)