# 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": "ComfyUI",
"images": [
"433:8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"78": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"435": {
"class_type": "PrimitiveStringMultiline",
"inputs": {
"value": "Bring this street corner to life at blue hour without changing the architecture. Switch on warm tungsten light behind about half of the windows on every floor, unevenly, as if people are home. On the ground floor, add a small café: a dark green canvas awning over the two arched windows nearest the corner, three round marble bistro tables with wicker chairs on the pavement, and a soft glow spilling out from inside. Add two wrought-iron street lamps at the corner and light them. Make the puddle reflect all of these new lights accurately, with gentle ripples. Keep the facade, the stonework, the cobblestones, the sky and the camera angle exactly as they are. No people, no signs, no text."
},
"_meta": {
"title": "Prompt"
}
},
"433:110": {
"class_type": "TextEncodeQwenImageEditPlus",
"inputs": {
"clip": [
"433:38",
0
],
"image1": [
"433:117",
0
],
"prompt": "",
"vae": [
"433:39",
0
]
},
"_meta": {
"title": "Text Encode Qwen Image Edit Plus"
}
},
"433:111": {
"class_type": "TextEncodeQwenImageEditPlus",
"inputs": {
"clip": [
"433:38",
0
],
"image1": [
"433:117",
0
],
"prompt": [
"435",
0
],
"vae": [
"433:39",
0
]
},
"_meta": {
"title": "Text Encode Qwen Image Edit Plus"
}
},
"433:117": {
"class_type": "FluxKontextImageScale",
"inputs": {
"image": [
"78",
0
]
},
"_meta": {
"title": "FluxKontextImageScale"
}
},
"433:3": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"433:88",
0
],
"model": [
"433:75",
0
],
"negative": [
"433:110",
0
],
"positive": [
"433:111",
0
],
"sampler_name": "euler",
"scheduler": "simple",
"seed": 0,
"steps": 4
},
"_meta": {
"title": "KSampler"
}
},
"433:37": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "qwen_image_edit_2509_fp8_e4m3fn.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"433:38": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "qwen_2.5_vl_7b_fp8_scaled.safetensors",
"device": "default",
"type": "qwen_image"
},
"_meta": {
"title": "Load CLIP"
}
},
"433:39": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "qwen_image_vae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"433:66": {
"class_type": "ModelSamplingAuraFlow",
"inputs": {
"model": [
"433:89",
0
],
"sampling": "flow",
"shift": 3
},
"_meta": {
"title": "ModelSamplingAuraFlow"
}
},
"433:75": {
"class_type": "CFGNorm",
"inputs": {
"model": [
"433:66",
0
],
"pre_cfg": False,
"strength": 1
},
"_meta": {
"title": "CFGNorm"
}
},
"433:8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"433:3",
0
],
"vae": [
"433:39",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"433:88": {
"class_type": "VAEEncode",
"inputs": {
"pixels": [
"433:117",
0
],
"vae": [
"433:39",
0
]
},
"_meta": {
"title": "VAE Encode"
}
},
"433:89": {
"class_type": "LoraLoaderModelOnly",
"inputs": {
"lora_name": "Qwen-Image-Edit-2509-Lightning-4steps-V1.0-bf16.safetensors",
"model": [
"433:37",
0
],
"strength_model": 1
},
"_meta": {
"title": "Load LoRA"
}
}
})
workflow.set_input("78", "image", client.assets.from_url("https://comfy.org/catalog-media/0f1f46e0-d02b-456b-ae66-06bf63073046/817953d3-5ba6-45ae-9d14-3ba026231125"))
# 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)