# 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({
"11": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"12": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"10:8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"14": {
"class_type": "StringConcatenate",
"inputs": {
"delimiter": "",
"string_a": "重新照明,",
"string_b": [
"15",
0
]
},
"_meta": {
"title": "LoRA trigger word"
}
},
"15": {
"class_type": "PrimitiveStringMultiline",
"inputs": {
"value": "relight the image as a calm winter evening after sunset: the windows now show a deep blue dusk outside, and the room is lit from inside by warm low lamps placed beside the sofa and on the console table, with a soft amber glow pooling on the linen cushions, the travertine table and the oak floor. Keep warm candle-like highlights on the terracotta and ceramic pieces, gentle warm falloff across the plaster walls, cool blue light spilling faintly through the window panes, and long soft shadows stretching away from each lamp. Keep every object, material and the room layout exactly the same; only the lighting, colour temperature and shadows change, giving a cosy, intimate, lived-in mood."
},
"_meta": {
"title": "Prompt"
}
},
"10:110": {
"class_type": "TextEncodeQwenImageEditPlus",
"inputs": {
"clip": [
"10:38",
0
],
"image1": [
"10:117",
0
],
"prompt": "",
"vae": [
"10:39",
0
]
},
"_meta": {
"title": "Text Encode Qwen Image Edit Plus"
}
},
"10:111": {
"class_type": "TextEncodeQwenImageEditPlus",
"inputs": {
"clip": [
"10:38",
0
],
"image1": [
"10:117",
0
],
"prompt": [
"14",
0
],
"vae": [
"10:39",
0
]
},
"_meta": {
"title": "Text Encode Qwen Image Edit Plus"
}
},
"10:117": {
"class_type": "FluxKontextImageScale",
"inputs": {
"image": [
"11",
0
]
},
"_meta": {
"title": "FluxKontextImageScale"
}
},
"10:118": {
"class_type": "LoraLoaderModelOnly",
"inputs": {
"lora_name": "Qwen-Image-Edit-2509-Relight.safetensors",
"model": [
"10:89",
0
],
"strength_model": 1
},
"_meta": {
"title": "Load LoRA"
}
},
"10:3": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"10:88",
0
],
"model": [
"10:75",
0
],
"negative": [
"10:110",
0
],
"positive": [
"10:111",
0
],
"sampler_name": "euler",
"scheduler": "simple",
"seed": 1118877715456453,
"steps": 4
},
"_meta": {
"title": "KSampler"
}
},
"10:37": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "qwen_image_edit_2509_fp8_e4m3fn.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"10:38": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "qwen_2.5_vl_7b_fp8_scaled.safetensors",
"device": "default",
"type": "qwen_image"
},
"_meta": {
"title": "Load CLIP"
}
},
"10:39": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "qwen_image_vae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"10:66": {
"class_type": "ModelSamplingAuraFlow",
"inputs": {
"model": [
"10:118",
0
],
"sampling": "flow",
"shift": 3
},
"_meta": {
"title": "ModelSamplingAuraFlow"
}
},
"10:75": {
"class_type": "CFGNorm",
"inputs": {
"model": [
"10:66",
0
],
"pre_cfg": False,
"strength": 1
},
"_meta": {
"title": "CFGNorm"
}
},
"10:8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"10:3",
0
],
"vae": [
"10:39",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"10:88": {
"class_type": "VAEEncode",
"inputs": {
"pixels": [
"10:117",
0
],
"vae": [
"10:39",
0
]
},
"_meta": {
"title": "VAE Encode"
}
},
"10:89": {
"class_type": "LoraLoaderModelOnly",
"inputs": {
"lora_name": "Qwen-Image-Edit-2509-Lightning-4steps-V1.0-bf16.safetensors",
"model": [
"10:37",
0
],
"strength_model": 1
},
"_meta": {
"title": "Load LoRA"
}
}
})
workflow.set_input("11", "image", client.assets.from_url("https://comfy.org/catalog-media/00a9f99c-a979-4359-b38e-fd61637c1023/42048864-3190-4865-8b71-19f186e98089"))
# 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("12"):
output.to_file(output.name)