# 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": 192044955347061,
"steps": 20
},
"_meta": {
"title": "KSampler"
}
},
"38": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "flux1-dev.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": "Inside a cavernous orbital research bay, a solitary xenobotanist leans intently over a brushed titanium workstation, manipulating floating holographic gene-sequences with tactile data gloves. The expansive vista stretches across the chamber, anchored by seamless carbon-fiber bulkheads and glowing emerald fiber-optic conduits running along the deck plates. To the left, tall pressurized acrylic cylinders house translucent alien specimens bathed in soft violet nutrient mist; to the right, sprawling curved diagnostic consoles flicker with pale amber readouts and topographical telemetry. Massive reinforced viewports reveal the colossal rings of an amethyst gas giant bathed in harsh white starlight. Immersed in micro-dissection analysis, the researcher studies an iridescent crystalline blossom under a suspended laser-spectrometer, solitary and focused within the cold, pristine geometry of the spacecraft.",
"guidance": 3.5,
"t5xxl": "Inside a cavernous orbital research bay, a solitary xenobotanist leans intently over a brushed titanium workstation, manipulating floating holographic gene-sequences with tactile data gloves. The expansive vista stretches across the chamber, anchored by seamless carbon-fiber bulkheads and glowing emerald fiber-optic conduits running along the deck plates. To the left, tall pressurized acrylic cylinders house translucent alien specimens bathed in soft violet nutrient mist; to the right, sprawling curved diagnostic consoles flicker with pale amber readouts and topographical telemetry. Massive reinforced viewports reveal the colossal rings of an amethyst gas giant bathed in harsh white starlight. Immersed in micro-dissection analysis, the researcher studies an iridescent crystalline blossom under a suspended laser-spectrometer, solitary and focused within the cold, pristine geometry of the spacecraft."
},
"_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)