Nodes/ComfyUI API Toolkit/Gemini Image Edit
ComfyUI Node

Gemini Image Edit

Edit any image with a sentence — mask optional

By IxMxAMAR·Created 5 months ago·Updated 2 months ago· 1
Gemini Image Edit
  • image
  • mask
  • reference_image
  • reference_image_2
  • reference_image_3
  • image
api_key
modelgemini-3.1-flash-image-preview
custom_model
edit_instruction
system_instruction
aspect_ratioAUTO
image_sizeAUTO

"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_ratio and image_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_size first.
  • 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.
CategoryAPI Toolkit/Gemini/Image

Inputs (12)

NameTypeDefaultDescription
api_keySTRINGGemini API key. Leave blank to use GEMINI_API_KEY env var.
modelCOMBOgemini-3.1-flash-image-previewImage-capable Gemini model for editing.
custom_modelSTRINGOverride with a custom model ID.
imageIMAGEThe image to edit.
edit_instructionSTRINGDescribe what edits to make to the image.
maskoptMASKOptional 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_imageoptIMAGEOptional reference image (e.g., a face to swap into the masked region).
reference_image_2optIMAGEOptional second reference image.
reference_image_3optIMAGEOptional third reference image.
system_instructionoptSTRINGSystem instruction for the editing model.
aspect_ratiooptCOMBOAUTOOutput image aspect ratio.
image_sizeoptCOMBOAUTOOutput image resolution.

Outputs (1)

NameTypeDescription
imageIMAGE