# 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": 8,
"denoise": 1,
"latent_image": [
"5",
0
],
"model": [
"4",
0
],
"negative": [
"7",
0
],
"positive": [
"6",
0
],
"sampler_name": "euler",
"scheduler": "normal",
"seed": 685468484323813,
"steps": 20
},
"_meta": {
"title": "KSampler"
}
},
"4": {
"class_type": "CheckpointLoaderSimple",
"inputs": {
"ckpt_name": "v1-5-pruned-emaonly-fp16.safetensors"
},
"_meta": {
"title": "Load Checkpoint"
}
},
"5": {
"class_type": "EmptyLatentImage",
"inputs": {
"batch_size": 1,
"height": 512,
"width": 912
},
"_meta": {
"title": "Empty Latent Image"
}
},
"6": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"4",
1
],
"text": "An expressive oil impasto landscape painting viewed from a high bird's-eye angle with a distant wide-angle perspective. Down below, an elderly East Asian woman with a sturdy build and grey hair in a topknot walks along a winding wet slate footpath. She wears a faded indigo cotton coat, coarse hemp trousers, and woven straw sandals, gripping a gnarled wooden staff as a tiny distant figure. The winding path curves through rolling moors of dark peat soil, damp charcoal boulders, and wild purple heather. In the background, jagged sea cliffs drop toward misty fjords under a brooding overcast dawn sky. The cold morning light casts faint silver reflections onto the damp cobblestones, dominated by cool steel-blue, slate-grey, sage-green, and pale lavender tones applied with heavy, tactile palette knife strokes."
},
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"7": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"4",
1
],
"text": "text, watermark"
},
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"3",
0
],
"vae": [
"4",
2
]
},
"_meta": {
"title": "VAE Decode"
}
},
"9": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "SD1.5",
"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("9"):
output.to_file(output.name)