# 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({
"8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"31",
0
],
"vae": [
"39",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"9": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"27": {
"class_type": "EmptySD3LatentImage",
"inputs": {
"batch_size": 1,
"height": 768,
"width": 1344
},
"_meta": {
"title": "EmptySD3LatentImage"
}
},
"31": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"27",
0
],
"model": [
"38",
0
],
"negative": [
"42",
0
],
"positive": [
"41",
0
],
"sampler_name": "euler",
"scheduler": "simple",
"seed": 167447334682596,
"steps": 4
},
"_meta": {
"title": "KSampler"
}
},
"38": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "flux1-schnell.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"39": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "ae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"40": {
"class_type": "DualCLIPLoader",
"inputs": {
"clip_name1": "clip_l.safetensors",
"clip_name2": "t5xxl_fp16.safetensors",
"device": "default",
"type": "flux"
},
"_meta": {
"title": "Load CLIP (Dual)"
}
},
"41": {
"class_type": "CLIPTextEncodeFlux",
"inputs": {
"clip": [
"40",
0
],
"clip_l": "A whimsical miniature fantasy settlement carved into jagged, frost-dusted slate crags, drifting through a freezing midnight blizzard. Intricately sculpted blown-glass dome cottages and verdigris copper pavilions perch along terraced cliff edges, interconnected by frosted filigree brass walkways. Amber candlebeams softly radiate from tiny leaded-glass windows, illuminating swirling snowflakes and icicles clinging to cedar eaves. On a suspended crystal bridge, a tiny elderly East Asian alchemist with a slender, stooped build and long braided silver hair tends an ornate brass brazier, warmly wrapped in a padded indigo-dyed silk haori, thick woolen leggings, and fur-lined leather boots. The floating landscape stretches across distant drifting ice-sheathed boulders, captured with crisp tilt-shift diorama focus, tactile velvet-soft snow textures, and deep sapphire atmospheric mist.",
"guidance": 3.5,
"t5xxl": "A whimsical miniature fantasy settlement carved into jagged, frost-dusted slate crags, drifting through a freezing midnight blizzard. Intricately sculpted blown-glass dome cottages and verdigris copper pavilions perch along terraced cliff edges, interconnected by frosted filigree brass walkways. Amber candlebeams softly radiate from tiny leaded-glass windows, illuminating swirling snowflakes and icicles clinging to cedar eaves. On a suspended crystal bridge, a tiny elderly East Asian alchemist with a slender, stooped build and long braided silver hair tends an ornate brass brazier, warmly wrapped in a padded indigo-dyed silk haori, thick woolen leggings, and fur-lined leather boots. The floating landscape stretches across distant drifting ice-sheathed boulders, captured with crisp tilt-shift diorama focus, tactile velvet-soft snow textures, and deep sapphire atmospheric mist."
},
"_meta": {
"title": "CLIPTextEncodeFlux"
}
},
"42": {
"class_type": "ConditioningZeroOut",
"inputs": {
"conditioning": [
"41",
0
]
},
"_meta": {
"title": "Conditioning Zero Out"
}
}
})
# 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)