Nodes/ComfyUI API Toolkit/Gemini Inpaint
ComfyUI Node

Gemini Inpaint

Gemini fills the mask, not your VRAM

By IxMxAMAR·Created 5 months ago·Updated 2 months ago· 1
Gemini Inpaint
  • image
  • mask
  • reference_image
  • image
api_key
modelgemini-3.1-flash-image-preview
custom_model
prompt
system_instruction

Normal ComfyUI inpainting means loading an SD/Flux checkpoint, drawing a mask, and letting the sampler repaint the hole with whatever the model's LatentInpaint machinery thinks belongs there. This node is the other way to get the same job done: you hand the masked image to a Gemini model on Google's servers, it reasons about the hole, and it hands back a finished image. No local model, no VRAM - but also no local model, no free calls.

It's the right tool when the repaint needs actual understanding rather than texture diffusion. Swap an object, remove a person and backfill the scene, place a specific item into an area - the Gemini image models handle these more semantically than a diffusion inpaint pass, which is exactly the trade the community makes when it routes a job to a closed API. And because it's in the graph, you can chain it the usual way: mask it, inpaint it, upscale it locally.

How it works

This is the Nano Banana family doing multimodal inpainting through generate_content. The node serializes your source image to JPEG, converts your ComfyUI mask to a black-and-white JPEG, and sends both to the model as image parts with a text prompt - plus a system instruction telling it to fill the white area "seamlessly, matching the surrounding context." The response comes back as an image stream, which is decoded into a normal ComfyUI IMAGE tensor.

The mask convention is the one thing to get right: white = fill, black = keep. The tooltip spells it out, and the node accepts any ComfyUI MASK you can produce - SAM or Grounding DINO segments, an alpha channel, a hand-painted mask - so you're not locked into one way of selecting the region.

Inputs and outputs that matter

  • image - your source.
  • mask - white fills, black keeps. Wire in anything that outputs MASK.
  • prompt - describe what should fill the masked area. "A red ceramic vase with flowers" beats "something nice."
  • model - defaults to gemini-3.1-flash-image-preview (Nano Banana 2), with gemini-3-pro-image-preview and gemini-2.5-flash-image available. Pro is the quality pick if you're getting sloppy edges.
  • reference_image - the sleeper input. Give it an image of a specific object or face and tell the prompt to place that in the hole. That's how you do "swap my face onto this character" without any local identity model.

The output is a single image (IMAGE). Wire it straight into a SaveImage or keep the pipeline going.

How to install it

Same as every node in this pack - you install the whole ComfyUI-API-Toolkit once, and this node comes along:

cd ComfyUI/custom_nodes
git clone https://github.com/IxMxAMAR/ComfyUI-API-Toolkit
cd ComfyUI-API-Toolkit
pip install -r requirements.txt

Or search "API Toolkit" in ComfyUI Manager. The Gemini service needs google-genai>=0.8.0; there are no weights to download because there's nothing local. You'll need a Gemini API key in the node or as the GEMINI_API_KEY env var.

Common issues

The recurring gotcha is thinking the mask is inverted - you'll instantly know if you painted it backwards because the model will rewrite your whole image. White fills, black keeps.

Second: if the result looks stitched or the edges don't match, that's the model's seam, not a bug you can patch. Two fixes that actually work - switch to the Pro model, and be specific in the prompt about matching the surrounding colors/lighting. Also note this is a paid image call, and the pack forces re-execution on every queue (IS_CHANGED on all API nodes), so every Queue hit spends credits even if nothing changed. And keep Google's filter in mind: this is a closed, moderated model, so anything the filter refuses locally isn't getting painted in by Gemini either.

CategoryAPI Toolkit/Gemini/Image

Inputs (8)

NameTypeDefaultDescription
api_keySTRINGGemini API key. Leave blank to use GEMINI_API_KEY env var.
modelCOMBOgemini-3.1-flash-image-previewImage-capable Gemini model for inpainting.
custom_modelSTRINGOverride with a custom model ID.
imageIMAGEThe source image to inpaint.
maskMASKMask (white = fill this area, black = keep). Accepts any ComfyUI MASK — from SAM, Grounding DINO, alpha channels, etc.
promptSTRINGDescribe what should fill the masked area.
reference_imageoptIMAGEOptional reference image (e.g., object/face to place in the masked area).
system_instructionoptSTRINGSystem instruction for the inpainting model.

Outputs (1)

NameTypeDescription
imageIMAGE