# 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": [
"115:8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"78": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"115:110": {
"class_type": "TextEncodeQwenImageEditPlus",
"inputs": {
"clip": [
"115:38",
0
],
"image1": [
"115:93",
0
],
"prompt": "",
"vae": [
"115:39",
0
]
},
"_meta": {
"title": "Text Encode Qwen Image Edit Plus"
}
},
"115:111": {
"class_type": "TextEncodeQwenImageEditPlus",
"inputs": {
"clip": [
"115:38",
0
],
"image1": [
"115:93",
0
],
"prompt": "Turn this rainy afternoon into a clear winter night. Outside the tall windows, the rain becomes falling snow over a dark blue sky, with snow resting on the branches of the trees beyond the glass. Inside, switch on warm light: a low glow from a floor lamp beside the daybed and soft candlelight on the concrete coffee table next to the steaming mug, so the room turns amber and cosy against the cold blue outside. Keep the man, his pose, clothes and expression exactly as they are, and keep the daybed, the rust wool throw, the terracotta lounge chair, the potted ficus and the large textured painting in the same places. Add gentle reflections of the lamps in the window glass. Photographic, natural, no text.",
"vae": [
"115:39",
0
]
},
"_meta": {
"title": "Text Encode Qwen Image Edit Plus"
}
},
"115:112": {
"class_type": "EmptySD3LatentImage",
"inputs": {
"batch_size": 1,
"height": 1440,
"width": 2560
},
"_meta": {
"title": "EmptySD3LatentImage"
}
},
"115:116": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"115:8",
0
]
},
"_meta": {
"title": "Preview Image"
}
},
"115:3": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"115:88",
0
],
"model": [
"115:75",
0
],
"negative": [
"115:110",
0
],
"positive": [
"115:111",
0
],
"sampler_name": "euler",
"scheduler": "simple",
"seed": 1118877715456453,
"steps": 4
},
"_meta": {
"title": "KSampler"
}
},
"115:37": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "qwen_image_edit_2509_fp8_e4m3fn.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"115:38": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "qwen_2.5_vl_7b_fp8_scaled.safetensors",
"device": "default",
"type": "qwen_image"
},
"_meta": {
"title": "Load CLIP"
}
},
"115:39": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "qwen_image_vae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"115:66": {
"class_type": "ModelSamplingAuraFlow",
"inputs": {
"model": [
"115:89",
0
],
"sampling": "flow",
"shift": 3
},
"_meta": {
"title": "ModelSamplingAuraFlow"
}
},
"115:75": {
"class_type": "CFGNorm",
"inputs": {
"model": [
"115:66",
0
],
"pre_cfg": False,
"strength": 1
},
"_meta": {
"title": "CFGNorm"
}
},
"115:8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"115:3",
0
],
"vae": [
"115:39",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"115:88": {
"class_type": "VAEEncode",
"inputs": {
"pixels": [
"115:93",
0
],
"vae": [
"115:39",
0
]
},
"_meta": {
"title": "VAE Encode"
}
},
"115:89": {
"class_type": "LoraLoaderModelOnly",
"inputs": {
"lora_name": "Qwen-Image-Edit-2509-Lightning-4steps-V1.0-bf16.safetensors",
"model": [
"115:37",
0
],
"strength_model": 1
},
"_meta": {
"title": "Load LoRA"
}
},
"115:93": {
"class_type": "ImageScaleToTotalPixels",
"inputs": {
"image": [
"78",
0
],
"megapixels": 1,
"resolution_steps": 1,
"upscale_method": "lanczos"
},
"_meta": {
"title": "Scale Image to Total Pixels"
}
}
})
workflow.set_input("78", "image", client.assets.from_url("https://comfy.org/catalog-media/001c7adc-df38-40ac-9120-951669cc3813/9dd6448a-64d9-434f-a373-d64eb77bd272"))
# 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)