Nodes/ComfyUI-NanoBanana2/NanoBanana - Inpaint
ComfyUI Node

NanoBanana - Inpaint

Fill the masked hole with anything Gemini can imagine

By IxMxAMAR·Created 6 months ago·Updated about a month ago· 4
NanoBanana - Inpaint
  • image
  • mask
  • reference_image
  • network
  • image
api_key
modelgemini-3.1-flash-image-preview
custom_model
prompt
system_instruction

Inpainting is the bread-and-butter edit of image work: mask a region, tell the model what belongs there, get back a seamlessly filled result. This node does exactly that, but the "model" is a Gemini image model running on Google's servers instead of a local diffusion checkpoint. Which means the mask source doesn't matter - SAM, Grounding DINO, an alpha channel, a hand-drawn blob - anything that produces a ComfyUI MASK feeds it, and Gemini figures out the rest.

The win over a local inpaint: understanding. "Put a cat here, sitting on the ledge, looking at the camera" goes in as one instruction and Gemini reasons about what that should look like in context, instead of you juggling prompts and CFG. The cost: it's a paid API call per inpaint, the mask is guidance rather than a hard boundary, and you're subject to Google's filters.

How it works

The node builds a multimodal prompt: the source image as lossless PNG, your mask as a second PNG (white = fill, black = keep), an optional reference image if you want something specific placed in the hole (a face, an object), and your prompt describing what should occupy the masked area. It runs through generate_content on an image-capable Gemini model and returns the filled image.

The mechanism detail worth knowing: masks get auto-resized to match the source image dimensions, because Gemini returns a 400 error on dimension mismatch - SAM and friends frequently produce masks at a different size than your image, and the pack handles that silently. It also encodes the mask as PNG to keep edges crisp; JPEG would smear them a couple of pixels and you'd see the boundary.

Key inputs:

  • image - the source.
  • mask - white = fill, black = keep.
  • prompt - what goes in the hole.
  • reference_image - optional, e.g. an object or face to place in the masked area.
  • system_instruction - optional; the pack ships a sensible default ("you are an expert image inpainter...") if you leave it empty.

Output: image, a standard IMAGE tensor ready for preview or further nodes.

Installation

One of the image nodes in NanoBanana2:

cd ComfyUI/custom_nodes
git clone https://github.com/IxMxAMAR/ComfyUI-NanoBanana2
pip install google-genai

ComfyUI Manager: search NanoBanana2. Requires a Gemini API key from aistudio.google.com, or GEMINI_API_KEY env var.

Gotchas

Two things trip people up. First, resolution and realism limits - Gemini image models have a maximum canvas, and heavily upscaled or huge inputs can push past what the model handles well; if your result looks mushy, try a smaller working copy. Second, the model can "helpfully" redraw outside the masked region if your prompt is loose about what should change - phrase the prompt as filling the area, not reinterpreting the scene. And remember the filters: if a prompt trips a safety category you get a descriptive refusal, not an image.

CategoryNanoBanana2/Image

Inputs (9)

NameTypeDefaultDescription
api_keySTRINGNanoBanana - 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.
networkoptNB_NETWORKOptional. Wire a NanoBanana - Network Route node here to route this request through that proxy (e.g. US egress).

Outputs (1)

NameTypeDescription
imageIMAGE