Nodes/comfyui-gemini-apikey/Nano Banana 2 (API Key)
ComfyUI Node

Nano Banana 2 (API Key)

Nano Banana 2 in ComfyUI, billed straight to your Google API key

By mortyhuang·Created 6 months ago·Updated 6 months ago· 0
Nano Banana 2 (API Key)
  • images
  • files
  • IMAGE
  • STRING
prompt
modelNano Banana 2 (Gemini 3.1 Flash Image)
seed42
aspect_ratioauto
resolution1K
response_modalitiesIMAGE
thinking_levelMINIMAL
system_promptYou are an expert image-generation engine. You must ALWAYS produce an image. Interpret all user input—regardless of format, intent, or abstraction—as literal visual directives for image composition. If a prompt is conversational or lacks specific visual details, you must creatively invent a concrete visual scenario that depicts the concept. Prioritize generating the visual representation above any text, formatting, or conversational requests.

This node drops Nano Banana 2 (a.k.a. Gemini 3.1 Flash Image) into your ComfyUI graph and bills it to your Gemini API key. No open weights exist for it, so you were never going to run it locally - the only question was which door you use to call it. This one is the bring-your-own-key door, which matters if you already have a key from Google AI Studio and don't feel like going through Comfy's Partner Node storefront with its prepaid credits.

Why you'd reach for it

Nano Banana is the closed image model the open ecosystem keeps borrowing for a start frame: generate the image on Google's API, then feed it to Wan or LTX for motion - that hybrid is one of the most common workflows in the space. The official Partner Nodes handle the closed models fine, but they want you logged into a Comfy account and paying in prepaid credits. This node skips all that and talks to Google directly. If you've already got a GEMINI_API_KEY lying around for other Gemini work, this is arguably the more direct route. It also costs you nothing to run locally - no VRAM, no model files - because everything happens on Google's servers.

How it works

Mechanically it's a thin HTTP client wearing a node costume. You type a prompt, it POSTs to generativelanguage.googleapis.com/v1beta/models/gemini-3.1-flash-image-preview:generateContent with your key in the x-goog-api-key header, and decodes the base64 image that comes back into a normal ComfyUI tensor. Downstream, your graph can't tell it from a local sampler's output. The node is honest about being a network call: your prompt and any reference images leave the machine, every generation is metered, and every image carries Google's invisible SynthID watermark.

The inputs that matter

Most of them you'll leave alone. The ones a beginner actually touches:

  • prompt - a multiline text box, and the whole point of the node. Write it like a normal image prompt.
  • seed - passed to the API, so you get repeatable-ish results. Don't expect local-sampler determinism from a closed cloud model; treat it as "same prompt, roughly same vibe."
  • aspect_ratio - auto plus ten presets from 1:1 to 21:9. Set it and skip worrying about resolution math.
  • resolution - 1K, 2K, or 4K. Higher costs more per image.
  • response_modalities - IMAGE (default) or IMAGE+TEXT. Pick IMAGE+TEXT if you want the model's own description of what it made.
  • thinking_level - MINIMAL or HIGH. HIGH makes it reason about the prompt first; expect it to be slower and pricier.

Optional inputs: images accepts reference images (up to 14 - feed a batch in via a Batch Images node for multi-image editing), system_prompt overrides the built-in "always produce an image" instruction, and files expects a GEMINI_INPUT_FILES object from a Gemini Input Files node - note that this pack doesn't ship a producer for that type, so it'll sit empty unless another pack provides one.

Outputs

Two outputs: IMAGE, which you wire straight into a preview or Save Image node, and STRING, which holds any text the model returned (the caption/description when you run IMAGE+TEXT).

Install

The usual dance:

cd ComfyUI/custom_nodes
git clone https://github.com/mortyhuang/comfyui-gemini-apikey

Restart ComfyUI (or search "comfyui-gemini-apikey" in ComfyUI Manager and let it do it for you). Then give it a key:

{ "api_key": "YOUR_ACTUAL_KEY_HERE" }

…saved at ComfyUI/user/gemini_config.json. The code also honors a GEMINI_API_KEY environment variable if you'd rather keep the key out of a file. The only dependencies are requests, torch, numpy and Pillow - all already in a stock ComfyUI, so there's no heavy install and no model download. Get the key itself from Google AI Studio; if it errors with "Gemini API Key missing," that file is what's missing.

The fine print

Per-call cost adds up faster than you expect, especially at 2K/4K, and Nano Banana's aggressive content filter is unremovable - there are no weights to patch. This is also a tiny pack (basically zero community footprint) that ships a credential and phones home by design, exactly the shape the ecosystem has been burned by once. Read the ~300 lines of source before first run, or stick to the official Partner Node if you'd rather trust Comfy's vetting. For a model with no open weights, it's a fair trade - just know what you're signing.

Categoryapi node/image/Gemini

Inputs (10)

NameTypeDefaultDescription
promptSTRINGText prompt describing the image.
modelCOMBONano Banana 2 (Gemini 3.1 Flash Image)1 options: Nano Banana 2 (Gemini 3.1 Flash Image)
seedINT420–2147483647
aspect_ratioCOMBOauto11 options: auto, 1:1, 2:3, 3:2, 3:4, 4:3, +5
resolutionCOMBO1K3 options: 1K, 2K, 4K
response_modalitiesCOMBOIMAGE2 options: IMAGE, IMAGE+TEXT
thinking_levelCOMBOMINIMAL2 options: MINIMAL, HIGH
imagesoptIMAGEOptional reference image(s). To include multiple images, use the Batch Images node (up to 14).
filesoptGEMINI_INPUT_FILESOptional file(s) from Gemini Input Files node.
system_promptoptSTRINGYou are an expert image-generation engine. You must ALWAYS produce an image. Interpret all user input—regardless of format, intent, or abstraction—as literal visual directives for image composition. If a prompt is conversational or lacks specific visual details, you must creatively invent a concrete visual scenario that depicts the concept. Prioritize generating the visual representation above any text, formatting, or conversational requests.

Outputs (2)

NameTypeDescription
IMAGEIMAGE
STRINGSTRING