# 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({
"103": {
"class_type": "LoadImage",
"inputs": {
"image": "comfy_cloud_bottle.png"
},
"_meta": {
"title": "Load Image + Draw Square Mask"
}
},
"208": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"224:213",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"224:119": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "qwen_image_edit_2509_fp8_e4m3fn.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"224:131": {
"class_type": "LoraLoaderModelOnly",
"inputs": {
"lora_name": "Qwen-Image-Edit-2509-Lightning-4steps-V1.0-bf16.safetensors",
"model": [
"224:89",
0
],
"strength_model": 1
},
"_meta": {
"title": "Load LoRA"
}
},
"224:211": {
"class_type": "TextEncodeQwenImageEditPlus",
"inputs": {
"clip": [
"224:38",
0
],
"image1": [
"224:221",
1
],
"image2": [
"224:221",
1
],
"prompt": "Image blending, correcting the product's perspective angle and light and shadow to integrate the product into the background",
"vae": [
"224:39",
0
]
},
"_meta": {
"title": "Text Encode Qwen Image Edit Plus"
}
},
"224:212": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"224:222",
0
],
"vae": [
"224:39",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"224:213": {
"class_type": "InpaintStitchImproved",
"inputs": {
"inpainted_image": [
"224:212",
0
],
"stitcher": [
"224:221",
0
]
},
"_meta": {
"title": "✂️ Inpaint Stitch (Improved)"
}
},
"224:215": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"224:212",
0
]
},
"_meta": {
"title": "Preview Image"
}
},
"224:216": {
"class_type": "TextEncodeQwenImageEditPlus",
"inputs": {
"clip": [
"224:38",
0
],
"image1": [
"224:221",
1
],
"image2": [
"224:221",
1
],
"prompt": "",
"vae": [
"224:39",
0
]
},
"_meta": {
"title": "Text Encode Qwen Image Edit Plus"
}
},
"224:217": {
"class_type": "VAEEncode",
"inputs": {
"pixels": [
"224:221",
1
],
"vae": [
"224:39",
0
]
},
"_meta": {
"title": "VAE Encode"
}
},
"224:218": {
"class_type": "ModelSamplingAuraFlow",
"inputs": {
"model": [
"224:131",
0
],
"sampling": "flow",
"shift": 3
},
"_meta": {
"title": "ModelSamplingAuraFlow"
}
},
"224:219": {
"class_type": "CFGNorm",
"inputs": {
"model": [
"224:218",
0
],
"pre_cfg": False,
"strength": 1
},
"_meta": {
"title": "CFGNorm"
}
},
"224:220": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"224:221",
1
]
},
"_meta": {
"title": "Preview 1024x1024 Crop Image"
}
},
"224:221": {
"class_type": "InpaintCropImproved",
"inputs": {
"context_from_mask_extend_factor": 1,
"downscale_algorithm": "bilinear",
"extend_down_factor": 1,
"extend_for_outpainting": False,
"extend_left_factor": 1,
"extend_right_factor": 1,
"extend_up_factor": 1,
"image": [
"103",
0
],
"mask": [
"103",
1
],
"mask_blend_pixels": 16,
"mask_expand_pixels": 0,
"mask_fill_holes": True,
"mask_hipass_filter": 0.1,
"mask_invert": False,
"output_padding": "0",
"output_resize_to_target_size": True,
"output_target_height": 1024,
"output_target_width": 1024,
"preresize": False,
"preresize_max_height": 16384,
"preresize_max_width": 16384,
"preresize_min_height": 1024,
"preresize_min_width": 1024,
"preresize_mode": "ensure minimum resolution",
"upscale_algorithm": "bicubic"
},
"_meta": {
"title": "✂️ Inpaint Crop (Improved)"
}
},
"224:222": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"224:217",
0
],
"model": [
"224:219",
0
],
"negative": [
"224:216",
0
],
"positive": [
"224:211",
0
],
"sampler_name": "euler",
"scheduler": "simple",
"seed": 1032597172973225,
"steps": 4
},
"_meta": {
"title": "KSampler"
}
},
"224:223": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"224:213",
0
]
},
"_meta": {
"title": "Preview Image"
}
},
"224:38": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "qwen_2.5_vl_7b_fp8_scaled.safetensors",
"device": "default",
"type": "qwen_image"
},
"_meta": {
"title": "Load CLIP"
}
},
"224:39": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "qwen_image_vae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"224:89": {
"class_type": "LoraLoaderModelOnly",
"inputs": {
"lora_name": "Qwen-Image-Edit-2509-Fusion.safetensors",
"model": [
"224:119",
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)