ComfyUI Node

OpenAI GPT Image Edit

OpenAI GPT Image Edit — the mask-capable editor this pack exists to feed

By amortegui84·Created 5 months ago·Updated 3 months ago· 3
OpenAI GPT Image Edit
  • image_1
  • image_2
  • image_3
  • image_4
  • image_5
  • image_6
  • mask_image
  • images
  • info
promptRetouch only the masked region. Preserve the rest of the image.
api_key
api_key_env_varFAL_KEY
openai_api_key
openai_api_key_env_varOPENAI_API_KEY
region_info
size_modepreset
image_sizeauto
aspect_ratio16:9
resolution1K
width1920
height1080
qualityhigh
num_images1
output_formatpng
sync_modefalse

GPT Image is the editor in this pack that actually accepts a mask - which makes it the natural partner for the mask-based local edit path, the one that keeps every pixel outside your region bit-identical. This node is the FAL relay for it: it wraps OpenAI's GPT Image 2 through FAL's relay (openai/gpt-image-2/edit), which matters more than it sounds, because it means you authenticate with a FAL key, not an OpenAI one.

The key story, since it confuses everyone

Despite the input named openai_api_key, this node never calls OpenAI directly. Every request goes to FAL, and FAL authenticates to OpenAI on the backend with its own credentials. Your FAL key is what authenticates the call - wire it into api_key (or FAL_KEY env var) and leave openai_api_key blank. In the current version, blank is fine and the node proceeds using FAL auth alone.

If you ever see RuntimeError: Missing OpenAI API key, the README has the full archaeology: older versions of the pack only checked that the field was non-empty, so people "fixed" it by pasting their FAL key into openai_api_key as well - a workaround that no longer needs to exist. The modern fix is just: update the pack and leave it blank.

The inputs that matter

Required: prompt (default: "Retouch only the masked region. Preserve the rest of the image."), image_1, and the key inputs. Then:

  • mask_image - the mask, uploaded as mask_image_url. It must be the exact same pixel size as image_1. In the pack's flow that's automatic: wire Smart Mask Crop -> cropped_mask_image here, not the original Florence mask.
  • size_mode - preset (with image_size, simplest: auto works like magic for inpainting), aspect_ratio (+ aspect_ratio/resolution), custom (explicit width/height, multiples of 16), or auto_from_region. For a stable automatic flow, connect Smart Mask Crop -> info into region_info and set auto_from_region - GPT then requests the same edit size the stitch expects, so nothing resamples.
  • quality (low/medium/high) and num_images (1–4) - your cost/quality tradeoff.
  • image_2 ... image_6 - optional references sent alongside image_1.

Outputs: images (into Smart Mask Stitch), and info.

Where it sits

Florence-2 or SAM selector -> mask -> Smart Mask Crop
    -> cropped_image      -> image_1
    -> cropped_mask_image -> mask_image
    -> info               -> region_info (size_mode = auto_from_region)
    -> result -> Smart Mask Stitch

Prompt the masked edit conservatively: name only the object, and explicitly preserve everything outside the mask. "Recompose the portrait" belongs in a full-frame pass, not a local masked edit - the editor will happily comply on the crop, and then the stitch pastes an island of chaos back.

Install

Search comfyui-inpaint-cropstitch-nb2 in ComfyUI Manager, or:

cd ComfyUI/custom_nodes
git clone https://github.com/amortegui84/comfyui-inpaint-cropstitch-nb2

Restart. FAL-backed, so FAL_KEY (or the node's api_key) is required; a 401 on first run means the key isn't reaching the process - set it before launch and fully restart ComfyUI.

Categoryinpaint/api

Inputs (23)

NameTypeDefaultDescription
promptSTRINGRetouch only the masked region. Preserve the rest of the image.
image_1IMAGE
api_keySTRING
api_key_env_varSTRINGFAL_KEY
openai_api_keySTRING
openai_api_key_env_varSTRINGOPENAI_API_KEY
image_2optIMAGE
image_3optIMAGE
image_4optIMAGE
image_5optIMAGE
image_6optIMAGE
mask_imageoptIMAGE
region_infooptSTRING
size_modeoptCOMBOpreset4 options: preset, aspect_ratio, custom, auto_from_region
image_sizeoptCOMBOauto7 options: auto, square_hd, square, portrait_4_3, portrait_16_9, landscape_4_3, +1
aspect_ratiooptCOMBO16:99 options: 1:1, 16:9, 9:16, 4:5, 5:4, 3:2, +3
resolutionoptCOMBO1K3 options: 1K, 2K, 4K
widthoptINT192016–4096
heightoptINT108016–4096
qualityoptCOMBOhigh3 options: low, medium, high
num_imagesoptINT11–4
output_formatoptCOMBOpng3 options: png, webp, jpeg
sync_modeoptBOOLEANfalse

Outputs (2)

NameTypeDescription
imagesIMAGE
infoSTRING