# 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": "Flux2_dev",
"images": [
"98:8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"98:10": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "flux2-vae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"98:100": {
"class_type": "PrimitiveInt",
"inputs": {
"value": 20
},
"_meta": {
"title": "Steps"
}
},
"98:101": {
"class_type": "LoraLoaderModelOnly",
"inputs": {
"lora_name": "Flux_2-Turbo-LoRA_comfyui.safetensors",
"model": [
"98:12",
0
],
"strength_model": 1
},
"_meta": {
"title": "Load LoRA"
}
},
"98:102": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"98:12",
0
],
"on_true": [
"98:101",
0
],
"switch": [
"98:104",
0
]
},
"_meta": {
"title": "Switch(model)"
}
},
"98:103": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"98:100",
0
],
"on_true": [
"98:99",
0
],
"switch": [
"98:104",
0
]
},
"_meta": {
"title": "Switch(steps)"
}
},
"98:104": {
"class_type": "PrimitiveBoolean",
"inputs": {
"value": False
},
"_meta": {
"title": "Enable Turbo LoRA"
}
},
"98:12": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "flux2_dev_fp8mixed.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"98:13": {
"class_type": "SamplerCustomAdvanced",
"inputs": {
"guider": [
"98:22",
0
],
"latent_image": [
"98:47",
0
],
"noise": [
"98:25",
0
],
"sampler": [
"98:16",
0
],
"sigmas": [
"98:48",
0
]
},
"_meta": {
"title": "SamplerCustomAdvanced"
}
},
"98:16": {
"class_type": "KSamplerSelect",
"inputs": {
"sampler_name": "euler"
},
"_meta": {
"title": "KSamplerSelect"
}
},
"98:22": {
"class_type": "BasicGuider",
"inputs": {
"conditioning": [
"98:26",
0
],
"model": [
"98:102",
0
]
},
"_meta": {
"title": "Basic Guider"
}
},
"98:25": {
"class_type": "RandomNoise",
"inputs": {
"noise_seed": 0
},
"_meta": {
"title": "RandomNoise"
}
},
"98:26": {
"class_type": "FluxGuidance",
"inputs": {
"conditioning": [
"98:6",
0
],
"guidance": 4
},
"_meta": {
"title": "FluxGuidance"
}
},
"98:38": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "mistral_3_small_flux2_bf16.safetensors",
"device": "default",
"type": "flux2"
},
"_meta": {
"title": "Load CLIP"
}
},
"98:47": {
"class_type": "EmptyFlux2LatentImage",
"inputs": {
"batch_size": 1,
"height": 768,
"width": 1344
},
"_meta": {
"title": "Empty Flux 2 Latent"
}
},
"98:48": {
"class_type": "Flux2Scheduler",
"inputs": {
"height": 768,
"steps": [
"98:103",
0
],
"width": 1344
},
"_meta": {
"title": "Flux2Scheduler"
}
},
"98:6": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"98:38",
0
],
"text": "A 1970s cinematic fashion editorial captured from a dramatic low-angle distant perspective with a vintage 28mm lens. A solitary model stands amid the sprawling expanse of a windswept black sand beach in Iceland, flanked by colossal basalt sea stacks emerging from crashing ocean foam. Thick maritime fog drifts across the expansive coastal vista under a cool, diffused silver-gray morning sky. The model wears an avant-garde tailored chrome-metallic trench coat with sharp exaggerated lapels, paired with a sweeping charcoal wool skirt, a midnight-blue ribbed turtleneck, and mirror-finish patent leather boots. The atmospheric sea spray catches soft, moody ambient light, balancing muted monolithic rock tones with reflective metallic sheen and subtle film grain."
},
"_meta": {
"title": "CLIP Text Encode (Positive Prompt)"
}
},
"98:8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"98:13",
0
],
"vae": [
"98:10",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"98:99": {
"class_type": "PrimitiveInt",
"inputs": {
"value": 8
},
"_meta": {
"title": "Steps"
}
}
})
# 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)