# 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({
"60": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "Qwen-Image",
"images": [
"76:8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"76:3": {
"class_type": "KSampler",
"inputs": {
"cfg": [
"76:83",
0
],
"denoise": 1,
"latent_image": [
"76:58",
0
],
"model": [
"76:66",
0
],
"negative": [
"76:7",
0
],
"positive": [
"76:6",
0
],
"sampler_name": "euler",
"scheduler": "simple",
"seed": 50347169638278,
"steps": [
"76:82",
0
]
},
"_meta": {
"title": "KSampler"
}
},
"76:37": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "qwen_image_fp8_e4m3fn.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"76:38": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "qwen_2.5_vl_7b_fp8_scaled.safetensors",
"device": "default",
"type": "qwen_image"
},
"_meta": {
"title": "Load CLIP"
}
},
"76:39": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "qwen_image_vae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"76:58": {
"class_type": "EmptySD3LatentImage",
"inputs": {
"batch_size": 1,
"height": 928,
"width": 1664
},
"_meta": {
"title": "EmptySD3LatentImage"
}
},
"76:6": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"76:38",
0
],
"text": "A bold graphic poster set in a sun-scorched desert during a tempestuous golden dawn, filled with billowing dust storm squalls and radiant amber backlighting. Dominating the center, the monumental headline \"SOLAR\" is rendered in massive, heavy-slab brutalist 3D typography sculpted from sunbaked terracotta and edge-worn oxidized copper, catching low-raking sunrise glare and casting elongated deep-umber shadows across rippling sand. Suspended below toward the right, the tagline \"awakening across the dunes\" appears in an understated, minimalist geometric sans-serif forged from matte brushed brass. Swirling crimson sand particles and intense atmospheric heat shimmer drift through the golden air, creating dramatic atmospheric depth against distant silhouetted mesa ridges."
},
"_meta": {
"title": "CLIP Text Encode (Positive Prompt)"
}
},
"76:66": {
"class_type": "ModelSamplingAuraFlow",
"inputs": {
"model": [
"76:78",
0
],
"sampling": "flow",
"shift": 3.1000000000000005
},
"_meta": {
"title": "ModelSamplingAuraFlow"
}
},
"76:7": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"76:38",
0
],
"text": ""
},
"_meta": {
"title": "CLIP Text Encode (Negative Prompt)"
}
},
"76:73": {
"class_type": "LoraLoaderModelOnly",
"inputs": {
"lora_name": "Qwen-Image-Lightning-8steps-V1.0.safetensors",
"model": [
"76:37",
0
],
"strength_model": 1
},
"_meta": {
"title": "Load LoRA"
}
},
"76:78": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"76:37",
0
],
"on_true": [
"76:73",
0
],
"switch": [
"76:86",
0
]
},
"_meta": {
"title": "Switch (Model)"
}
},
"76:79": {
"class_type": "PrimitiveInt",
"inputs": {
"value": 8
},
"_meta": {
"title": "Steps"
}
},
"76:8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"76:3",
0
],
"vae": [
"76:39",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"76:81": {
"class_type": "PrimitiveFloat",
"inputs": {
"value": 1
},
"_meta": {
"title": "CFG"
}
},
"76:82": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"76:84",
0
],
"on_true": [
"76:79",
0
],
"switch": [
"76:86",
0
]
},
"_meta": {
"title": "Switch (Steps)"
}
},
"76:83": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"76:85",
0
],
"on_true": [
"76:81",
0
],
"switch": [
"76:86",
0
]
},
"_meta": {
"title": "Switch (CFG)"
}
},
"76:84": {
"class_type": "PrimitiveInt",
"inputs": {
"value": 20
},
"_meta": {
"title": "Steps"
}
},
"76:85": {
"class_type": "PrimitiveFloat",
"inputs": {
"value": 4
},
"_meta": {
"title": "CFG"
}
},
"76:86": {
"class_type": "PrimitiveBoolean",
"inputs": {
"value": False
},
"_meta": {
"title": "Enable Lightning LoRA"
}
}
})
# 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("60"):
output.to_file(output.name)