# 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({
"9": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"41:8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"41:27": {
"class_type": "EmptySD3LatentImage",
"inputs": {
"batch_size": 1,
"height": 768,
"width": 1344
},
"_meta": {
"title": "EmptySD3LatentImage"
}
},
"41:31": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"41:27",
0
],
"model": [
"41:38",
0
],
"negative": [
"41:42",
0
],
"positive": [
"41:45",
0
],
"sampler_name": "euler",
"scheduler": "simple",
"seed": 192044955347061,
"steps": 20
},
"_meta": {
"title": "KSampler"
}
},
"41:38": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "flux1-dev.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"41:39": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "ae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"41: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:42": {
"class_type": "ConditioningZeroOut",
"inputs": {
"conditioning": [
"41:45",
0
]
},
"_meta": {
"title": "Conditioning Zero Out"
}
},
"41:45": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"41:40",
0
],
"text": "A full-length editorial studio portrait of a distinguished 45-year-old Japanese man with a lean, athletic build and slicked-back salt-and-pepper hair. Captured from a low angle with a 35mm wide lens, he sits poised on a sleek brushed-aluminum cube positioned toward the far left, allowing expansive empty studio space to spread across the view. He wears an oversized, tailored emerald-green velvet blazer, an open-collared ivory silk shirt, and pleated charcoal trousers. The setting features a seamless, curved terracotta cyclorama with subtle textured gradient washes. Crisp editorial lighting sculpts the sharp angles of his cheekbones and strong jaw, casting long, clean graphic shadows across the polished concrete floor while pinpoint rim lights define his shoulders."
},
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"41:8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"41:31",
0
],
"vae": [
"41:39",
0
]
},
"_meta": {
"title": "VAE Decode"
}
}
})
# 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)