Gemini Image Edit
Edit any image with a sentence — mask optional
- image
- mask
- reference_image
- reference_image_2
- reference_image_3
- image
"Make the sky stormy," "turn this product into a steampunk version," "swap the person's face with this reference." Where local inpainting needs a mask and a careful prompt, this node takes an image and a sentence and returns an edited version, because the Gemini image model understands both. It's the editing complement to the AIS_Gemini_ImageGen generator, and it uses the same closed model family - which is both the appeal and the price.
Required inputs: api_key, model (the same three image-capable models, default gemini-3.1-flash-image-preview), custom_model override, image (the image to edit, as an IMAGE tensor), and edit_instruction - the sentence describing what to change.
Then the pieces that make editing actually controllable:
mask- a MASK input. Here's the honest mechanic, straight from the tooltip: Gemini doesn't do pixel-perfect masking. It uses the mask as visual guidance alongside your instruction, not as a hard boundary. White = edit, black = keep, and any MASK source works (SAM, Grounding DINO, segmentation, alpha channels, background removal). You get a loose regional edit, not surgical inpainting.reference_image/reference_image_2/reference_image_3- supply a face to swap in, a texture to match, a style to borrow. Reference-based editing is where this node is genuinely hard to beat locally.system_instruction- extra framing for the model.aspect_ratioandimage_size- control the output dimensions (AUTO by default, which keeps things simple).
One output: image.
When to use it - and when not to
The sweet spot is the "in my head" edit: you can describe the change, so the model does the reasoning and the pixel-pushing together. Face swaps and character-consistency edits with a reference image are the strongest use case. The trap is treating it as free inpainting. If you need surgical, pixel-accurate edits to one region - a precise inpaint where only the marked pixels change - this is the wrong tool; use a local inpaint model. Gemini's edits can quietly rewrite more of the image than you asked for, which is fine for a creative pass and wrong for a preservation job.
Installing it
Part of the ComfyUI API Toolkit pack. Manager: search "API Toolkit". Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/IxMxAMAR/ComfyUI-API-Toolkit
cd ComfyUI-API-Toolkit
pip install -r requirements.txt
Restart. Needs google-genai>=0.8.0.
Gotchas
- Every edit is a paid API call, and the pack re-runs on each queue - iterate cheaply by working at lower
image_sizefirst. - Your source images leave the machine and Google's moderation applies. No celebrity faces, no copyrighted subjects, no workarounds; there are no weights to patch.
- The mask is guidance, not a contract. If the model edits outside the mask, lower your expectations for precision or switch to a local inpaint for that pass.
Inputs (12)
| Name | Type | Default | Description |
|---|---|---|---|
| api_key | STRING | Gemini API key. Leave blank to use GEMINI_API_KEY env var. | |
| model | COMBO | gemini-3.1-flash-image-preview | Image-capable Gemini model for editing. |
| custom_model | STRING | Override with a custom model ID. | |
| image | IMAGE | The image to edit. | |
| edit_instruction | STRING | Describe what edits to make to the image. | |
| maskopt | MASK | Optional mask — which areas to edit. White = edit, black = keep. Works with any MASK source: SAM, Grounding DINO, segmentation, alpha channels, RMBG. Gemini doesn't do pixel-perfect masking — it uses this as visual guidance alongside your instructions. | |
| reference_imageopt | IMAGE | Optional reference image (e.g., a face to swap into the masked region). | |
| reference_image_2opt | IMAGE | Optional second reference image. | |
| reference_image_3opt | IMAGE | Optional third reference image. | |
| system_instructionopt | STRING | System instruction for the editing model. | |
| aspect_ratioopt | COMBO | AUTO | Output image aspect ratio. |
| image_sizeopt | COMBO | AUTO | Output image resolution. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |