# 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-2512",
"images": [
"238:231",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"238:218": {
"class_type": "PrimitiveFloat",
"inputs": {
"value": 1
},
"_meta": {
"title": "CFG"
}
},
"238:219": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "qwen_2.5_vl_7b_fp8_scaled.safetensors",
"device": "default",
"type": "qwen_image"
},
"_meta": {
"title": "Load CLIP"
}
},
"238:220": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "qwen_image_vae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"238:221": {
"class_type": "LoraLoaderModelOnly",
"inputs": {
"lora_name": "Qwen-Image-2512-Lightning-4steps-V1.0-fp32.safetensors",
"model": [
"238:226",
0
],
"strength_model": 1
},
"_meta": {
"title": "Load LoRA"
}
},
"238:222": {
"class_type": "ModelSamplingAuraFlow",
"inputs": {
"model": [
"238:233",
0
],
"sampling": "flow",
"shift": 3.1000000000000005
},
"_meta": {
"title": "ModelSamplingAuraFlow"
}
},
"238:223": {
"class_type": "PrimitiveFloat",
"inputs": {
"value": 4
},
"_meta": {
"title": "CFG"
}
},
"238:224": {
"class_type": "PrimitiveInt",
"inputs": {
"value": 50
},
"_meta": {
"title": "Steps"
}
},
"238:225": {
"class_type": "PrimitiveInt",
"inputs": {
"value": 4
},
"_meta": {
"title": "Steps"
}
},
"238:226": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "qwen_image_2512_fp8_e4m3fn.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"238:227": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"238:219",
0
],
"text": "A dramatic artistic photograph captures a solitary figure standing at the distant left edge of an expansive, rain-soaked concrete floor. A colossal, upright slit of searing cyan and stark cobalt neon serves as the striking light source, cutting through heavy atmospheric mist and sheet-like downpour. Harsh, razor-sharp edge lighting chisels the subject's profile, glinting vividly off a slick, waterproof vinyl coat and scattering across beaded droplets of water. The ground mirrors the intense electric beam in rippling liquid reflections that streak across the vast, shadow-drenched surface toward the empty darkness on the opposite side. Deep indigo shadows, cold steel-gray tones, and harsh neon cyan dominate the composition, evoking a brooding noir stillness with clinical, hard-edged textures and crystalline rain streaks frozen in midair."
},
"_meta": {
"title": "CLIP Text Encode (Positive Prompt)"
}
},
"238:228": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"238:219",
0
],
"text": "低分辨率,低画质,肢体畸形,手指畸形,画面过饱和,蜡像感,人脸无细节,过度光滑,画面具有AI感。构图混乱。文字模糊,扭曲"
},
"_meta": {
"title": "CLIP Text Encode (Negative Prompt)"
}
},
"238:229": {
"class_type": "PrimitiveBoolean",
"inputs": {
"value": False
},
"_meta": {
"title": "Enable 4 Steps LoRA?"
}
},
"238:230": {
"class_type": "KSampler",
"inputs": {
"cfg": [
"238:243",
0
],
"denoise": 1,
"latent_image": [
"238:232",
0
],
"model": [
"238:222",
0
],
"negative": [
"238:228",
0
],
"positive": [
"238:227",
0
],
"sampler_name": "euler",
"scheduler": "simple",
"seed": 464857551335368,
"steps": [
"238:240",
0
]
},
"_meta": {
"title": "KSampler"
}
},
"238:231": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"238:230",
0
],
"vae": [
"238:220",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"238:232": {
"class_type": "EmptySD3LatentImage",
"inputs": {
"batch_size": 1,
"height": 928,
"width": 1664
},
"_meta": {
"title": "EmptySD3LatentImage"
}
},
"238:233": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"238:226",
0
],
"on_true": [
"238:221",
0
],
"switch": [
"238:229",
0
]
},
"_meta": {
"title": "Switch (model)"
}
},
"238:240": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"238:224",
0
],
"on_true": [
"238:225",
0
],
"switch": [
"238:229",
0
]
},
"_meta": {
"title": "Switch (steps)"
}
},
"238:243": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"238:223",
0
],
"on_true": [
"238:218",
0
],
"switch": [
"238:229",
0
]
},
"_meta": {
"title": "Switch (cfg)"
}
}
})
# 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)