# 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({
"14": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"18": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"17:12",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"17:1": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "qwen_2.5_vl_7b_fp8_scaled.safetensors",
"device": "default",
"type": "qwen_image"
},
"_meta": {
"title": "Load CLIP"
}
},
"17:10": {
"class_type": "VAEEncode",
"inputs": {
"pixels": [
"14",
0
],
"vae": [
"17:2",
0
]
},
"_meta": {
"title": "VAE Encode"
}
},
"17:11": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"17:10",
0
],
"model": [
"17:7",
0
],
"negative": [
"17:9",
0
],
"positive": [
"17:8",
0
],
"sampler_name": "euler",
"scheduler": "beta",
"seed": 539595976310948,
"steps": 8
},
"_meta": {
"title": "KSampler"
}
},
"17:12": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"17:11",
0
],
"vae": [
"17:2",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"17:2": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "qwen_image_vae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"17:3": {
"class_type": "LoraLoaderModelOnly",
"inputs": {
"lora_name": "Qwen-Image-Edit-2509-Anything2RealAlpha.safetensors",
"model": [
"17:4",
0
],
"strength_model": 1
},
"_meta": {
"title": "Load LoRA"
}
},
"17:4": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "qwen_image_edit_2509_fp8_e4m3fn.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"17:5": {
"class_type": "LoraLoaderModelOnly",
"inputs": {
"lora_name": "Qwen-Image-Edit-2509-Lightning-8steps-V1.0-bf16.safetensors",
"model": [
"17:3",
0
],
"strength_model": 1
},
"_meta": {
"title": "Load LoRA"
}
},
"17:6": {
"class_type": "ModelSamplingAuraFlow",
"inputs": {
"model": [
"17:5",
0
],
"sampling": "flow",
"shift": 3
},
"_meta": {
"title": "ModelSamplingAuraFlow"
}
},
"17:7": {
"class_type": "CFGNorm",
"inputs": {
"model": [
"17:6",
0
],
"pre_cfg": False,
"strength": 1
},
"_meta": {
"title": "CFGNorm"
}
},
"17:8": {
"class_type": "TextEncodeQwenImageEditPlus",
"inputs": {
"clip": [
"17:1",
0
],
"image1": [
"14",
0
],
"prompt": "Change image 1 to a realistic photograph. Keep the composition, the high camera angle, the poses and every element of the scene: the masked rider in a dusty canvas duster and brass goggles hunched over a leather saddle, the huge horned dinosaur with scarred green and ochre scales sprinting across the pale canyon floor, the plumes of white dust and the tiers of limestone cliffs. Make it look like a real telephoto shot taken at noon: true-to-life skin, leather and scale textures, natural hard sunlight with real shadows, believable dust in the air, photographic depth and detail, no painted outlines or brush texture.",
"vae": [
"17:2",
0
]
},
"_meta": {
"title": "Text Encode Qwen Image Edit Plus"
}
},
"17:9": {
"class_type": "TextEncodeQwenImageEditPlus",
"inputs": {
"clip": [
"17:1",
0
],
"image1": [
"14",
0
],
"prompt": "",
"vae": [
"17:2",
0
]
},
"_meta": {
"title": "Text Encode Qwen Image Edit Plus"
}
}
})
workflow.set_input("14", "image", client.assets.from_url("https://comfy.org/catalog-media/89207d5e-f0a3-4da3-8237-a6156192e21c/6e0ee1e9-043e-49a8-bc86-ef66b328e963"))
# 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("18"):
output.to_file(output.name)