# 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({
"5": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI-light_migration",
"images": [
"1:8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"6": {
"class_type": "LoadImage",
"inputs": {
"image": "woman_with_sunbeam.jpg"
},
"_meta": {
"title": "Load Lighting Image"
}
},
"7": {
"class_type": "LoadImage",
"inputs": {
"image": "women_with_blue_orb.jpg"
},
"_meta": {
"title": "Load Subject Image"
}
},
"1:101": {
"class_type": "LoraLoaderModelOnly",
"inputs": {
"lora_name": "Qwen-Image-Edit-2509-Light-Migration.safetensors",
"model": [
"1:89",
0
],
"strength_model": 1
},
"_meta": {
"title": "Load LoRA"
}
},
"1:102": {
"class_type": "TextEncodeQwenImageEditPlus",
"inputs": {
"clip": [
"1:38",
0
],
"image1": [
"1:104",
0
],
"image2": [
"1:105",
0
],
"prompt": "参考色调,移除图1原有的光照并参考图2的光照和色调对图1重新照明, maintain canny edge of interior glass orb.",
"vae": [
"1:39",
0
]
},
"_meta": {
"title": "Text Encode Qwen Image Edit Plus"
}
},
"1:103": {
"class_type": "TextEncodeQwenImageEditPlus",
"inputs": {
"clip": [
"1:38",
0
],
"image1": [
"1:104",
0
],
"image2": [
"1:105",
0
],
"prompt": "",
"vae": [
"1:39",
0
]
},
"_meta": {
"title": "Text Encode Qwen Image Edit Plus"
}
},
"1:104": {
"class_type": "ImageScaleToTotalPixels",
"inputs": {
"image": [
"7",
0
],
"megapixels": 1,
"resolution_steps": 1,
"upscale_method": "lanczos"
},
"_meta": {
"title": "Scale Image to Total Pixels"
}
},
"1:105": {
"class_type": "ImageScaleToTotalPixels",
"inputs": {
"image": [
"6",
0
],
"megapixels": 1,
"resolution_steps": 1,
"upscale_method": "nearest-exact"
},
"_meta": {
"title": "Scale Image to Total Pixels"
}
},
"1:108": {
"class_type": "RepeatLatentBatch",
"inputs": {
"amount": 1,
"samples": [
"1:88",
0
]
},
"_meta": {
"title": "Repeat Latent Batch"
}
},
"1:3": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"1:108",
0
],
"model": [
"1:75",
0
],
"negative": [
"1:103",
0
],
"positive": [
"1:102",
0
],
"sampler_name": "euler",
"scheduler": "simple",
"seed": 1047952688565236,
"steps": 8
},
"_meta": {
"title": "KSampler"
}
},
"1:37": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "qwen_image_edit_2509_fp8_e4m3fn.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"1:38": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "qwen_2.5_vl_7b_fp8_scaled.safetensors",
"device": "default",
"type": "qwen_image"
},
"_meta": {
"title": "Load CLIP"
}
},
"1:39": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "qwen_image_vae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"1:66": {
"class_type": "ModelSamplingAuraFlow",
"inputs": {
"model": [
"1:101",
0
],
"sampling": "flow",
"shift": 3
},
"_meta": {
"title": "ModelSamplingAuraFlow"
}
},
"1:75": {
"class_type": "CFGNorm",
"inputs": {
"model": [
"1:66",
0
],
"pre_cfg": False,
"strength": 1
},
"_meta": {
"title": "CFGNorm"
}
},
"1:8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"1:3",
0
],
"vae": [
"1:39",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"1:88": {
"class_type": "VAEEncode",
"inputs": {
"pixels": [
"1:104",
0
],
"vae": [
"1:39",
0
]
},
"_meta": {
"title": "VAE Encode"
}
},
"1:89": {
"class_type": "LoraLoaderModelOnly",
"inputs": {
"lora_name": "Qwen-Image-Edit-2509-Lightning-8steps-V1.0-bf16.safetensors",
"model": [
"1:37",
0
],
"strength_model": 1
},
"_meta": {
"title": "Load LoRA"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)