Skip to main content

Nano Banana API Docs and Tutorial: Key, Model IDs, and Code

Nano Banana is the Gemini API's image model family, used with an AI Studio key. Start new code on gemini-nano-banana-2.1; Nano Banana 2 is now deprecated.

LaoZhang AI TeamPublishedUpdated 21 min read
On this page
Nano Banana API docs and tutorial cover: GEMINI_API_KEY from Google AI Studio, four image model IDs, start with gemini-3.1-flash-image, and the October 2, 2026 legacy shutdown

The official Nano Banana API is the Gemini API. Google's own wording is that "Nano Banana is the name for Gemini's native image generation capabilities," and the documentation lives on the Gemini API image generation page. You authenticate with a key from Google AI Studio, pick one of five image models, and send the request to the Interactions API or to the older generateContent endpoint.

As of October 8, 2026, the short version looks like this:

  • Key: create it in Google AI Studio. New keys have been authorization keys since May 28, 2026, and the key belongs to a Google Cloud project that owns billing and quota.
  • Model: start with gemini-nano-banana-2.1 (Nano Banana 2.1), generally available since October 6, 2026. Use gemini-3.1-flash-lite-image for cheap single-shot 1K output and gemini-3-pro-image when the exact wording inside the image has to come out right.
  • What changed on October 6: Nano Banana 2 (gemini-3.1-flash-image) is deprecated on the Gemini API with no shutdown date announced. It still works, and moving to 2.1 is mostly a model-ID change, but 2.1 has no 512px size and thinks more by default.
  • API surface: Google's image docs show Interactions API code only. generateContent "remains fully supported," so existing integrations don't have to move today.
  • Old IDs: every -preview image ID is already shut down. For gemini-2.5-flash-image, the original Nano Banana, Google's deprecations table now lists March 15, 2027, while its pricing page still warns of October 2, 2026.

Sites titled "Nano Banana API documentation" that hand out their own tokens are separate services. They put Google's models, or other models, behind their own REST endpoints, so their request format, pricing, and limits are theirs, not Google's. Everything below refers to Google's Gemini API unless a section says otherwise.

Which Google page answers which question

Google splits the Nano Banana material across several pages. Knowing which one owns which question saves most of the time spent hunting through tutorials:

You need to…Open this Google pageWhat you'll find there
See every image feature with codeImage generationModel list, text-to-image, editing, multi-turn, reference images, grounding, thinking levels, sizes and aspect ratios, prompting guide, limitations
Check one model's specsGemini Nano Banana 2.1 model pageModel code, input and output types, token limits, Batch and Flex support
Create or fix a keyUsing Gemini API keysStandard vs. authorization keys, project import, key restrictions, environment variables
Check what an image costsPricingPer-model image output prices, thinking-token prices, Batch prices, search grounding charges
Understand 429 errors and tiersRate limitsPer-project limits, images per minute (IPM), usage tiers
Check whether a model ID still worksDeprecationsRelease and shutdown dates, plus the recommended replacement for every model ID
See what changed and whenGemini API changelogRelease and deprecation announcements, such as the 2.1 launch on October 6, 2026
Learn the Interactions API itselfInteractions overview and Migrate to InteractionsSDK versions, server-side history, storage and retention, generateContent equivalents
Keep generateContent codegenerateContent referenceresponseModalities, imageConfig, aspectRatio, imageSize

Nano Banana Pro has extra material of its own, including JSON-structured prompts, YAML configs, and PDF input. That is covered in Nano Banana Pro API Guide: JSON, YAML, Image Saving, and PDFs. If you need the models through Google Cloud rather than an AI Studio key, see Vertex AI Nano Banana API: Model IDs, Setup, and Cost per Image. For help choosing between those two, read Gemini API vs Vertex AI API: Which Google Gemini Route Should You Use?.

Pick a model before you write code: start with Nano Banana 2.1

The five models share one request format, so switching later is a one-line change. They do differ in what they accept and return, though. This table sets the capabilities from Google's image generation guide next to its Standard paid-tier prices as of October 8, 2026:

Nano Banana 2.1Nano Banana 2 LiteNano Banana ProNano Banana 2 (deprecated)Nano Banana (legacy)
Model IDgemini-nano-banana-2.1gemini-3.1-flash-lite-imagegemini-3-pro-imagegemini-3.1-flash-imagegemini-2.5-flash-image
Google's positioning"Primary high-efficiency workhorse," GA October 6, 2026Fastest and cheapest; "not optimized for multiple reference inputs or multi-turn sequential editing"Most complex visual tasks, professional assets"Previous-generation"; deprecated October 6, 2026, no shutdown dateLegacy; conflicting shutdown dates (see below)
Output sizes1K, 2K, 4K1K only1K, 2K, 4K512px, 1K, 2K, 4K1024px
Aspect ratios14: the 10 standard ratios plus 1:4, 4:1, 1:8, 8:110 standard ratios10 standard ratios14, same as 2.110 standard ratios
Reference imagesUp to 10 object + 4 character images (14 total)Up to 14 object imagesUp to 6 object + 5 character + 3 style images (14 total)Up to 10 object + 4 character imagesWorks best with up to 3
Grounding with Google SearchWeb search and image searchNot supportedWeb searchWeb search and image searchNot listed
Video as inputYesYesNoYesNo
thinking_level settingminimal, medium (default), highminimal (default) or highThinks by default, no level settingminimal (default) or highNot listed
Standard price per image$0.0336 (1K), $0.0504 (2K), $0.113 (4K)$0.0336 (1K)$0.134 (1K or 2K), $0.24 (4K)$0.045 (512px), $0.067 (1K), $0.101 (2K), $0.151 (4K)$0.039

The 10 standard ratios are 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, and 21:9. Prices are Google's per-image equivalents for image output on the Gemini API pricing page. The API has no free tier for image output on any of these models. Batch halves the price, for example $0.0168 per 1K image on Nano Banana 2.1. Thinking tokens are billed on top of the image price: per 1 million text and thinking tokens, 2.1 charges $7.50, Lite $1.50, Nano Banana 2 $3, and Pro $12. Every generated image carries a SynthID watermark.

A workable rule:

  • Start with gemini-nano-banana-2.1. It handles generation, editing, multi-turn changes, consistency for up to 4 characters and 10 objects, 4K output, wide panoramic ratios, video input, and web plus image search grounding. Google's guide recommends it for all new projects in place of Nano Banana 2, and its 1K image output costs half of Nano Banana 2's ($0.0336 against $0.067).
  • Drop to gemini-3.1-flash-lite-image when the job is single-shot 1K images at volume with no grounding, references, or follow-up edits. Its 1K image price matches 2.1's, so the saving comes from the tokens around the image: Lite bills text and thinking at a fifth of 2.1's rate and defaults to minimal thinking, while 2.1 defaults to medium.
  • Move to gemini-3-pro-image when exact wording inside the image matters: dense or small text, brand copy, style references, or illustrated text-and-image output. In a 9-prompt test of Nano Banana 2.1, Pro, and GPT Image 2.5 run on October 8, 2026 at 1K with one draw per prompt, Pro kept the requested wording while 2.1 changed it in 3 of the text tasks. Pro costs $134 per 1,000 images at 1K or 2K, against $33.60 in image output for 1,000 1K images on 2.1.
  • Leave gemini-3.1-flash-image when you next touch the code. Nano Banana 2 keeps working and has no announced shutdown date, but 2.1 is cheaper per image at every size it supports. The migration section below lists the three things to check.
  • Plan to leave gemini-2.5-flash-image now. Google's own pages disagree on its shutdown date, which is reason enough not to build on it.

Nano Banana model picker: Nano Banana 2 at $0.067 per 1K image for a first build, Lite at $0.0336 for 1K volume, Pro at $0.134 for dense text and brand work, and gemini-2.5-flash-image to move off before October 2, 2026

The full 2.1 cost picture, including thinking tokens and the gap between the per-image price and the cost of a whole call, is in Nano Banana 2.1 API Pricing: Per-Image Price vs Cost per Call. For a side-by-side of all four current models, see Nano Banana 2 Lite vs 2 vs 2.1 vs Pro: Which Model to Use Now.

Step 1: Get a Gemini API key

  1. Sign in to Google AI Studio and accept the terms. New users automatically get a default Google Cloud project and an API key.
  2. If you already use Google Cloud, AI Studio won't create a project for you. Open Dashboard → Projects, click Import projects, choose your project, then create the key on the API Keys page.
  3. To generate images, link a billing account to that project. Google's pricing page lists image output as "Not available" on the free tier for every Nano Banana model, and linking billing is also what moves the project to usage Tier 1. Generating images with Nano Banana in the AI Studio playground counts as a paid feature too, so it doesn't offer a free way around this.

A few rules decide whether the key works once it's in your code:

  • Keys created since May 28, 2026 are authorization keys. They are bound to a service account and limited to the Gemini API by default. The Gemini API rejects unrestricted standard keys, so an old key copied from a 2025 project may fail until you add restrictions or create a new one.
  • Limits belong to the project, not the key. Rate limits, including images per minute (IPM), apply per project, and daily quotas reset at midnight Pacific time. A second key in the same project adds no capacity. Google's Gemini API rate limits page, last updated September 2, 2026, has no Nano Banana 2.1 row yet, so read your live numbers in AI Studio. Nano Banana 2 Limits: How Gemini Usage and API Rate Limits Work explains tiers and where to find those numbers.
  • If "Create API key" is grayed out with "You do not have permission to create a key in this project," your Google Cloud role is missing key and service account permissions. Ask an admin for a role such as Project Editor, or create a project that isn't tied to an organization.
  • Availability depends on region. The Gemini API only serves Google's listed available regions. Russia, mainland China, and Hong Kong are not on that list.

Store the key as an environment variable instead of in source code:

bash
export GEMINI_API_KEY="your-key-here"

Google's Python and JavaScript clients read GEMINI_API_KEY or GOOGLE_API_KEY automatically. If both are set, GOOGLE_API_KEY wins, which is a common reason a "new" key seems to be ignored.

Step 2: Install an SDK that has the Interactions API

The Interactions API needs google-genai 2.3.0 or later in Python and @google/genai 2.3.0 or later in JavaScript. Older releases of the same packages don't have client.interactions.

bash
pip install -U "google-genai>=2.3.0"
npm install @google/genai@latest

Java and Go clients exist too, and the image generation page shows them next to every example. REST needs nothing but curl, plus jq if you want to pull the image out of the response in the shell.

Step 3: Generate your first image with gemini-nano-banana-2.1

All three versions below send a text prompt to Nano Banana 2.1 and save the returned image. They follow the examples on Google's image generation page as of October 8, 2026, and they haven't been run against Google's endpoint. Run them with your own key before building on them.

Python

python
import base64
from google import genai

client = genai.Client()  # reads GEMINI_API_KEY

interaction = client.interactions.create(
    model="gemini-nano-banana-2.1",
    input="A nano banana dish plated in a fancy restaurant with a Gemini theme",
    response_format={"type": "image", "aspect_ratio": "16:9", "image_size": "2K"},
)

with open("generated_image.png", "wb") as f:
    f.write(base64.b64decode(interaction.output_image.data))

JavaScript

javascript
import { GoogleGenAI } from "@google/genai";
import * as fs from "node:fs";

const ai = new GoogleGenAI({}); // reads GEMINI_API_KEY

const interaction = await ai.interactions.create({
  model: "gemini-nano-banana-2.1",
  input: "A nano banana dish plated in a fancy restaurant with a Gemini theme",
  response_format: { type: "image", aspect_ratio: "16:9", image_size: "2K" },
});

if (interaction.output_image) {
  fs.writeFileSync("generated_image.png", Buffer.from(interaction.output_image.data, "base64"));
}

REST

bash
curl -s -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-nano-banana-2.1",
    "input": "A nano banana dish plated in a fancy restaurant with a Gemini theme",
    "response_format": {"type": "image", "aspect_ratio": "16:9", "image_size": "2K"}
  }' > response.json

jq -r '[.steps[] | select(.type == "model_output") | .content[] | select(.type == "image") | .data] | last' response.json \
  | base64 --decode > generated_image.png

The response has an id and a steps array. The image sits in a step of type model_output, as a content block of type image with base64 data. The SDK shortcut output_image returns the last image in the response, so the jq filter keeps the last one too. Keep the id: you need it for follow-up edits.

First Nano Banana request in four steps, from an AI Studio key and GEMINI_API_KEY to interactions.create and a saved PNG, with the response showing the id and the base64 image inside a model_output step

If the call returns 200 but no file appears, check whether you asked for text only, or whether your code reads a field that doesn't exist in the current schema. Nano Banana API Returns No Image? Find the Cause in the Response walks through each case. For 429, 503, and refusals, see Nano Banana API Not Working? Fix 429, 503, No Image, and Request Denied, and for how long a 429 lasts, Gemini Image 429 Rate Limit: How Long It Lasts and How to Fix It.

What live Nano Banana 2.1 calls returned

The live calls that have been made went through LaoZhang API rather than Google's endpoint. On October 8, 2026, seven requests sent gemini-nano-banana-2.1 through LaoZhang's Gemini-native generateContent route, one sample per setting:

Disclosure: laozhang.ai is our own service. Its prices are platform pricing, not an independent comparison.

  • Every call returned HTTP 200 in 19–35 seconds.
  • Pixel sizes matched Google's size table: 2752×1536 for 16:9 at 2K, and 5504×3072 for 16:9 at 4K, an 8.6 MB file.
  • The image bytes were JPEG on every call, even with no MIME type requested, so check the returned mime_type before you name the file .png.
  • Thinking tokens were reported on every call, including two calls set to minimal (587 and 936 thinking tokens).
  • An imageSize of "512" was not rejected. It came back as a 1024×1024 image and was billed. The same request had returned HTTP 400 the day before, so don't rely on either behavior.

These are single samples through a gateway that may handle requests differently from Google's endpoint. They show the request shape works and what the output looks like, not speed or reliability on Google's side.

Step 4: Control size, aspect ratio, and output format

Output settings live in response_format:

FieldValuesRules
type"image", or an array such as [{"type": "text"}, {"type": "image"}]By default the model returns text and an image. Passing an image format returns images only. Pass the array to get both.
aspect_ratio"1:1", "16:9", "9:16", "21:9", "8:1" and the others in the model tableWithout it, output matches the size of your input image, or falls back to 1:1. The 1:4, 4:1, 1:8, and 8:1 ratios work on Nano Banana 2.1 and Nano Banana 2 only.
image_size"1K", "2K", "4K"The K must be uppercase. Google rejects lowercase values such as "1k". Lite supports only "1K".
mime_typeFor example "image/jpeg"Optional. Google's examples use it to get JPEG output.

The 512px (0.5K) size exists only on Nano Banana 2. Google's guide states it is not supported on Nano Banana 2.1. If your app used 512px previews, a 1K preview on 2.1 costs $0.0336, which is less than Nano Banana 2's $0.045 for 512px. If you still need 512px on Nano Banana 2, its exact Interactions value is garbled on Google's page ("512px (05.K)"), so copy it from the "Generate images up to 4K" section of the image generation page rather than guessing. The generateContent reference lists it as 512.

Size is also a cost choice. On Nano Banana 2.1, a 2K image costs 1.5 times a 1K image ($0.0504 ÷ $0.0336) and a 4K image about 3.4 times ($0.113 ÷ $0.0336), so generate drafts at 1K and render finals larger.

Edit, iterate, and combine reference images

Edit an existing image

Send the instruction and the image together as a list of content blocks:

python
import base64
from google import genai

client = genai.Client()

with open("cat.png", "rb") as f:
    cat_b64 = base64.b64encode(f.read()).decode("utf-8")

interaction = client.interactions.create(
    model="gemini-nano-banana-2.1",
    input=[
        {"type": "text", "text": "Show my cat eating a nano banana in a fancy restaurant under the Gemini constellation"},
        {"type": "image", "data": cat_b64, "mime_type": "image/png"},
    ],
)

with open("cat_edit.png", "wb") as f:
    f.write(base64.b64decode(interaction.output_image.data))

JavaScript uses the same blocks: { type: "image", mime_type: "image/png", data: base64Image }. For large files, Google's Image understanding page covers uploads through the Files API.

Change the image over several turns

The Interactions API keeps conversation history on Google's servers. To change the previous result, pass its id as previous_interaction_id instead of sending the image again:

python
first = client.interactions.create(
    model="gemini-nano-banana-2.1",
    input="A colorful kids' cookbook-style infographic explaining photosynthesis as a recipe",
    response_format={"type": "image", "aspect_ratio": "16:9"},
)

second = client.interactions.create(
    model="gemini-nano-banana-2.1",
    input="Update this infographic to be in Spanish. Do not change any other elements of the image.",
    previous_interaction_id=first.id,
    response_format={"type": "image", "aspect_ratio": "16:9", "image_size": "2K"},
)

The same follow-up in REST, reading the ID from the first response:

bash
PREVIOUS_INTERACTION_ID=$(jq -r '.id' response.json)

curl -s -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{
    \"model\": \"gemini-nano-banana-2.1\",
    \"input\": \"Update this infographic to be in Spanish. Do not change any other elements of the image.\",
    \"previous_interaction_id\": \"$PREVIOUS_INTERACTION_ID\",
    \"response_format\": {\"type\": \"image\", \"aspect_ratio\": \"16:9\", \"image_size\": \"2K\"}
  }" > response-2.json

This relies on storage, which is on by default (store=true). Google keeps interactions for 55 days on the paid tier and 1 day on the free tier. Setting store=false opts out of retention, but then previous_interaction_id no longer works and you have to resend the image yourself. Multi-turn editing is also where Lite is weakest, so keep these chains on Nano Banana 2.1 or Pro. Multi-turn character consistency is one of the improvements Google lists for 2.1 over Nano Banana 2.

Combine several reference images

Add one image block per reference. Google's example turns five portraits into a single office group photo:

python
import base64
from pathlib import Path
from google import genai

client = genai.Client()

blocks = [{"type": "text", "text": "An office group photo of these people, they are making funny faces."}]
for path in ["p1.png", "p2.png", "p3.png", "p4.png", "p5.png"]:
    blocks.append({
        "type": "image",
        "mime_type": "image/png",
        "data": base64.b64encode(Path(path).read_bytes()).decode("utf-8"),
    })

interaction = client.interactions.create(
    model="gemini-nano-banana-2.1",
    input=blocks,
    response_format={"type": "image", "aspect_ratio": "5:4", "image_size": "2K"},
)

The limits in the model table are per request. Nano Banana 2.1 keeps up to 4 characters consistent and up to 10 objects faithful, 14 references in total. Pro is the only model with style-reference slots.

Grounding, thinking, video input, and Batch

Once basic generation works, these features are the next thing most integrations reach for.

Grounding with Google Search lets the model look up current facts before drawing, such as a five-day forecast chart or a recent event:

python
interaction = client.interactions.create(
    model="gemini-nano-banana-2.1",
    input="Visualize the 5-day weather forecast for San Francisco as a clean, modern chart with what to wear each day",
    tools=[{"type": "google_search"}],
    response_format={"type": "image", "mime_type": "image/jpeg", "aspect_ratio": "16:9"},
)

The response adds google_search_call and google_search_result steps, with url_citation annotations on the text. On Nano Banana 2.1 and Nano Banana 2 you can also add Google Image Search with "search_types": ["web_search", "image_search"] inside the tool. When you use image search, you must display the search_suggestions HTML from the result in your UI. Grounding on 2.1 and Nano Banana 2 doesn't use real-world images of people from web search, and Lite doesn't support grounding at all. Search is billed separately: the pricing page gives 5,000 free search requests a month shared across Gemini 3.x models, then $14 per 1,000.

Thinking is always on for the Gemini 3 image models and can't be turned off. The model may render up to two interim "thought images," which aren't charged, but thinking tokens are billed. You choose the level in generation_config:

python
interaction = client.interactions.create(
    model="gemini-nano-banana-2.1",
    input="A futuristic city built inside a giant glass bottle floating in space",
    generation_config={"thinking_level": "high"},
)

Nano Banana 2.1 accepts minimal, medium, and high, and defaults to medium. Nano Banana 2 and Lite accept only minimal and high, and default to minimal. That difference matters when you migrate: the same request without a level thinks more on 2.1. Set minimal explicitly when latency matters, and try high for complex compositions. In the LaoZhang calls described above, minimal still produced thinking tokens, and one 2K pair took 34.8 seconds on high against 24.7 seconds on minimal.

Text and images together. When you ask for an illustrated explanation, for example with gemini-3-pro-image, one response can mix text and several images. output_image returns only the last one, so walk the steps instead:

python
for step in interaction.steps:
    if step.type == "model_output":
        for block in step.content:
            if block.type == "text":
                print(block.text)
            elif block.type == "image":
                ...  # base64.b64decode(block.data) and save each image

Video as input. Nano Banana 2.1, Nano Banana 2, and Lite accept a public YouTube URL or a Files API upload as an input block of type video. That's useful for thumbnails, posters, and summary graphics. Pro and the legacy model don't accept video.

Batch. Every image feature above also runs through the Batch API. You get higher rate limits and half the price, and turnaround can take up to 24 hours. It suits catalog renders and overnight jobs, not an app waiting on a user's click. The 2.1 model page lists Batch as supported and Flex and Priority inference as not supported. The rate limits page doesn't yet list a Batch quota for 2.1.

For prompt wording itself, including templates for product shots, text-heavy graphics, and edits, see How to Prompt Nano Banana: Practical Guide and 50 Tested Templates.

Maintaining older Nano Banana code

Much of the Nano Banana code in circulation was written for model IDs and schemas that no longer exist. Code, scripts, or ComfyUI workflows that still send a -preview image ID fail on the Gemini API. If you inherited any of it, check these breakpoints in order. The replacements follow Google's deprecations table as of October 8, 2026:

Old code has…What happenedChange it to
gemini-2.0-flash-preview-image-generationShut down November 14, 2025gemini-nano-banana-2.1
gemini-2.5-flash-image-previewShut down January 15, 2026gemini-nano-banana-2.1
gemini-3-pro-image-previewShut down June 25, 2026gemini-3-pro-image
gemini-3.1-flash-image-previewShut down June 25, 2026gemini-nano-banana-2.1
gemini-3.1-flash-image (Nano Banana 2)Deprecated October 6, 2026; no shutdown date announcedgemini-nano-banana-2.1
gemini-2.5-flash-imageDeprecations table lists shutdown March 15, 2027; the pricing page still warns of October 2, 2026gemini-3.1-flash-lite-image for plain 1K output, or gemini-nano-banana-2.1 for edits and references
imagen-4.0-* modelsShut down on the Gemini API August 17, 2026gemini-nano-banana-2.1
image_size="512" or 512px on 2.12.1 doesn't support 512px"1K" on 2.1, or keep that call on Nano Banana 2
Interactions code reading interaction.outputs[-1]The legacy outputs schema was removed June 8, 2026interaction.steps, or the output_image and output_text shortcuts
Interactions code with generation_config={"image_config": {...}} or response_mime_typeRemoved or moved in the same schema changeresponse_format={"type": "image", "aspect_ratio": ..., "image_size": ...}
image_size="1k"Lowercase is rejected"1K", "2K", "4K"
A key created before May 28, 2026 with no restrictionsThe Gemini API rejects unrestricted standard keysAdd API restrictions, or create a new key in AI Studio
An SDK that lacks client.interactionsInteractions needs 2.3.0 or laterUpgrade google-genai or @google/genai

Moving from Nano Banana 2 to Nano Banana 2.1

Google's guide uses the same request shape for both models, so the model ID is the main change. Check three things when you switch:

  1. 512px is gone. Calls that ask for 512px need "1K" on 2.1.
  2. Thinking defaults to medium. Nano Banana 2 defaulted to minimal. Set "thinking_level": "minimal" if you want to stay close to the old latency, and expect thinking tokens either way.
  3. The bill moves in two directions. Image output drops at every size: $0.067 to $0.0336 at 1K, $0.101 to $0.0504 at 2K, and $0.151 to $0.113 at 4K. Text and thinking tokens rise from $3 to $7.50 per million, and input from $0.50 to $1.50 per million.

If your generateContent code sets temperature, topP, topK, or seed, remove them for 2.1. Google's Vertex AI documentation says those parameters return an API error on 2.1, and ComfyUI's 2.1 node doesn't send temperature or top_p. The Gemini API docs don't say whether the same rule applies there, so seeds aren't a safe way to get reproducible images on 2.1. The Nano Banana 2 API pricing page for the deprecated model covers what Nano Banana 2 still costs while you plan the switch.

On gemini-2.5-flash-image: Google's pages disagree on when it ends, so test it with your own key before relying on it and plan the move now. The image guide and the deprecations table both recommend moving to Nano Banana 2 Lite. Moving from 2.5 to Lite changes price only slightly ($0.039 to $0.0336 per image) and keeps 1K output, but Lite isn't built for multi-reference or multi-turn edits. If your old flow relied on those, move to Nano Banana 2.1.

Keeping generateContent

generateContent still works with the current model IDs. If your integration is built on it, the minimum fix is the model ID. In Python, the image settings go in image_config, not response_format:

python
from google import genai
from google.genai import types

client = genai.Client()

response = client.models.generate_content(
    model="gemini-nano-banana-2.1",
    contents="A nano banana dish plated in a fancy restaurant with a Gemini theme",
    config=types.GenerateContentConfig(
        response_modalities=["IMAGE"],
        image_config=types.ImageConfig(aspect_ratio="16:9", image_size="2K"),
    ),
)

for part in response.candidates[0].content.parts:
    if part.inline_data:
        with open("generated_image.png", "wb") as f:
            f.write(part.inline_data.data)

The REST equivalent posts to v1beta/models/{model}:generateContent. It puts responseModalities and imageConfig (aspectRatio, imageSize) under generationConfig, and returns the image as inlineData in candidates[].content.parts[]:

bash
curl -s -X POST \
  "https://generativelanguage.googleapis.com/v1beta/models/gemini-nano-banana-2.1:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{"parts": [{"text": "A nano banana dish plated in a fancy restaurant with a Gemini theme"}]}],
    "generationConfig": {
      "responseModalities": ["IMAGE"],
      "imageConfig": {"aspectRatio": "16:9", "imageSize": "2K"}
    }
  }'

Snippets that put responseFormat inside a generateContent config mix up the two APIs. Use imageConfig there. The Python form above follows the fields in Google's generateContent reference rather than a copied Google example, and it hasn't been run against Google's endpoint. The generateContent reference lists 512 among the imageSize values, but that option belongs to Nano Banana 2, not 2.1. Moving to Interactions pays off when you want server-side multi-turn history, typed steps, or background execution, and Google recommends it for all new work.

Other ways to call Nano Banana

The Gemini API with your own key is the direct route. Three other setups come up often:

  • A gateway with per-call pricing. LaoZhang API's Nano Banana 2.1 documentation lists gemini-nano-banana-2.1 at $0.045 per call at any size or thinking level, with Nano Banana 2 at $0.055, Lite at $0.025, and Pro at $0.09. It uses the Gemini-native generateContent format and an OpenAI-compatible route, not the Interactions API. Against Google's prices, a flat call costs more than a plain 1K image ($0.0336 plus thinking tokens) and less than a 4K image ($0.113 plus thinking tokens). The trade-offs, including where the request format and features differ from Google's, are in Nano Banana API: Google vs. LaoZhang Cost and Image Delivery.
  • ComfyUI. The ComfyUI Nano Banana 2.1 Partner Node needs ComfyUI 0.39.1 or newer, a Comfy account, and a prepaid credit balance. It bills in Comfy credits, not Google's per-image prices, and its model menu also runs Nano Banana 2 and Lite.
  • Inside a coding agent. To generate images from Claude Code instead of your own app, see Nano Banana in Claude Code: Skill or MCP Setup That Still Works.

Disclosure: laozhang.ai is our own service. Its prices are platform pricing, not an independent comparison.

If you don't need an API at all, Gemini Image Generation Guide: Pick the Right Tool and Model covers the no-code options. In the Gemini app, Google's product page says Nano Banana 2 is free and Nano Banana 2.1 comes with a Google AI plan, while Google's help center still describes image generation with Nano Banana 2 and doesn't mention 2.1 yet. Neither page publishes a daily image count. Gemini Free Image Limit: How Many Images You Can Make and Upload explains how the app's usage limit works instead.

FAQ

Where is the official Nano Banana API documentation?

It's the Gemini API image generation page at ai.google.dev/gemini-api/docs/image-generation, supported by Google's model page for Nano Banana 2.1 and its pages on API keys, pricing, rate limits, and deprecations. Google doesn't run a separate "Nano Banana API" product. Sites that use that name and issue their own tokens are third-party services.

Is the Nano Banana API free?

Not for image output. Google's pricing page lists image output as "Not available" on the free tier for every Nano Banana model, and image generation in the AI Studio playground is a paid feature as well. Free image generation is in the Gemini app, not the API. Gemini Image API Free? No Free Tier, but $5 Buys Up to 148 Images works through what a small prepaid balance buys.

Is there a separate Nano Banana API key?

No. A "Nano Banana API key" is a Gemini API key from Google AI Studio. The same key calls every Gemini model, including gemini-nano-banana-2.1, gemini-3.1-flash-lite-image, and gemini-3-pro-image. Creating the key costs nothing, but image output is billed per image, so the Google Cloud project behind the key needs a linked billing account before any Nano Banana call succeeds. Step 1 above covers the authorization-key rules, and Google AI Studio API Key: Is It Free? Create, Secure, Verify covers key restrictions and a first test request. Keys issued by sites that call themselves a "Nano Banana API" belong to those sites, not to Google.

How much does the Nano Banana API cost per image?

On Google's Standard tier as of October 8, 2026: $0.0336 at 1K, $0.0504 at 2K, and $0.113 at 4K on Nano Banana 2.1; $0.0336 at 1K on Nano Banana 2 Lite; and $0.134 at 1K or 2K and $0.24 at 4K on Nano Banana Pro. Batch halves those prices, and text and thinking tokens are billed on top of the image price. Nano Banana 2.1 API Pricing: Per-Image Price vs Cost per Call works through what a whole call costs, and Nano Banana API Cost: Lite, Nano Banana 2, Pro, Free Reality, and Which Route To Use compares the lanes for a budget.

Which Nano Banana model ID should I use?

Use gemini-nano-banana-2.1 unless you have a reason not to. Pick gemini-3.1-flash-lite-image for the cheapest 1K images without grounding, references, or multi-turn editing, and gemini-3-pro-image when exact in-image text, brand, or style-reference work matters. Avoid every -preview ID, gemini-2.5-flash-image, and the deprecated gemini-3.1-flash-image in new code.

Is Nano Banana 2 being shut down?

On the Gemini API, gemini-3.1-flash-image was deprecated on October 6, 2026, with no shutdown date announced, and Google recommends migrating to gemini-nano-banana-2.1. A date of October 29, 2026 appeared on Google's pages at launch and has since been removed. On Vertex AI, the same model has a separate lifecycle with retirement listed as "May 28, 2027 or later."

Does Nano Banana 2.1 support 512px images?

No. Google's guide says 512px (0.5K) is supported on Nano Banana 2 but not on Nano Banana 2.1, which offers 1K, 2K, and 4K. A 1K image on 2.1 costs $0.0336, less than Nano Banana 2's 512px price of $0.045.

Is generateContent deprecated for Nano Banana?

No. Google says generateContent "remains fully supported," and the current model IDs, including gemini-nano-banana-2.1, work there. Google's image docs show Interactions API examples only and recommend Interactions for new development.

Did gemini-2.5-flash-image shut down on October 2, 2026?

Google's pages disagree. The Gemini API deprecations table now lists its shutdown as March 15, 2027, while the pricing page still carries a warning that it "will be shut down on October 2, 2026." Treat it as ending soon either way: switch to gemini-3.1-flash-lite-image for simple 1K images, or to gemini-nano-banana-2.1 if you use references or follow-up edits.

Where are the Nano Banana Pro docs?

Pro uses the same image generation page and the same code with model="gemini-3-pro-image". Pro-specific topics such as JSON-structured prompts, YAML configs, and PDF input are covered in Nano Banana Pro API Guide: JSON, YAML, Image Saving, and PDFs.

Sources12

External pages this guide links to, in the order they appear. Last updated Oct 21, 2026.

  1. 1.Gemini API image generation pageai.google.dev/gemini-api/docs/image-generation
  2. 2.Gemini Nano Banana 2.1 model pageai.google.dev/gemini-api/docs/models/gemini-nano-banana-2.1
  3. 3.Using Gemini API keysai.google.dev/gemini-api/docs/api-key
  4. 4.Pricingai.google.dev/gemini-api/docs/pricing
  5. 5.Rate limitsai.google.dev/gemini-api/docs/rate-limits
  6. 6.Deprecationsai.google.dev/gemini-api/docs/deprecations
  7. 7.Gemini API changelogai.google.dev/gemini-api/docs/changelog
  8. 8.Interactions overviewai.google.dev/gemini-api/docs/interactions-overview
  9. 9.Migrate to Interactionsai.google.dev/gemini-api/docs/migrate-to-interactions
  10. 10.generateContent referenceai.google.dev/api/generate-content
  11. 11.Google AI Studioaistudio.google.com
  12. 12.ComfyUI Nano Banana 2.1 Partner Nodedocs.comfy.org/tutorials/partner-nodes/google/nano-banana-2-1
More in API Guides