# 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": 3.5,
"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": 1124798614324697,
"steps": 45
},
"_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 richly detailed storybook painted illustration of a young medieval scholar in a thick, fur-lined emerald cloak, sitting on a weathered stone bench within an ancient cloister garden. Deep winter twilight blankets the expansive courtyard, where gentle flurries of soft snow drift past frosted gothic stone arches, sprawling across to a frozen decorative fountain. A warm tin lantern rests between the scholar and a massive, gentle forest stag with frost-dusted antlers, who peacefully nibbles roasted oats from the scholar's outstretched mitten. Warm golden lantern light spills across the fresh powdered snow, contrasting with the cold indigo shadows of dusk. Delicate gouache brushwork and visible canvas texture capture the quiet companionship, with frozen pines stretching into the quiet twilight distance."
},
"_meta": {
"title": "CLIP Text Encode (Positive Prompt)"
}
},
"76:66": {
"class_type": "ModelSamplingAuraFlow",
"inputs": {
"model": [
"76:73",
0
],
"sampling": "flow",
"shift": 7
},
"_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": "illustration-1.0-qwen-image.safetensors",
"model": [
"76:37",
0
],
"strength_model": 1
},
"_meta": {
"title": "Load LoRA"
}
},
"76:8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"76:3",
0
],
"vae": [
"76: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("60"):
output.to_file(output.name)