Skip to main content
Nano Banana 2 renders text reliably, handles multi-reference composites well, and is the only Nano Banana model with a 512px preview size. On LaoZhang API the model ID is gemini-3.1-flash-image, and every call costs $0.055 from 512px to 4K, with no Google account needed.
Seeing more failed images? Check whether the model is healthy first. Image model status shows GPT Image and Nano Banana success rates every 5 minutes, with what to do when a rate drops.

What Nano Banana 2 supports

1K to 4K images cost less than Google’s standard price per output image:
  • 1K: $0.067 at Google, $0.055 on LaoZhang API
  • 2K: $0.101 at Google, $0.055 on LaoZhang API
  • 4K: $0.151 at Google, $0.055 on LaoZhang API
The model comes from Google’s official channel. Public pricing as of September 24, 2026, with Google’s prices checked on November 5, 2026; current prices are in Models and pricing. If you only need 1K to 4K, Nano Banana 2.1 costs $0.045 per call and takes the same request.
A night market food stall with a hand-painted NOODLES sign under lantern light, generated by Nano Banana 2

Output of the generate example below: 2K, 16:9

Parameters and limits

Google shut down gemini-3.1-flash-image-preview on June 25, 2026, according to its deprecations page. On LaoZhang API, the -preview IDs are mapped to the matching stable IDs; use the stable ID, gemini-3.1-flash-image, directly. To compare all five Nano Banana models, see the Nano Banana overview.

Before you call

1

Create an API key

In Token management, open the create-token dialog (创建令牌), set Billing mode (计费模式) to Usage first (按量优先, recommended) or Per-call (按次计费), and click Create (创建). Nano Banana 2 has only a per-call price, and a Usage-based (按量计费) key can’t call it; the billing rules explain when a request is charged.Create-token dialog in the LaoZhang API console with Billing mode set to Per-call (按次计费)
2

Set the key and install the dependencies

3

Add a save function for cURL

The cURL examples need jq. Define this shell function to save the last image in a Gemini-native response, which is the final result if interim images come back too, with the extension that matches its mimeType:
When the response holds no image, the function prints the error, promptFeedback, and finishReason fields instead.

Generate an image

The image comes back as Base64 in candidates[0].content.parts[].inlineData.data, and mimeType gives its format. Both examples decode it and save a PNG, JPEG, or WebP file to match. Larger sizes take longer to render, so keep a generous client timeout; the examples allow 300 seconds.

Output sizes

imageSize accepts four values from 512 to 4K, with the K in uppercase; 1K is the default. Google publishes these pixel dimensions for Nano Banana 2: At 512, a 1:1 image is 512×512; Google’s image generation guide lists the other 512px sizes.

Edit images

Send the instruction first, then the reference images as inlineData parts, and refer to the images by their order in the prompt (“the first image”, “the second image”). Nano Banana 2 accepts up to 14 references: at most 10 object images and 4 character images.
This request combines two local files. Build the body with jq so large images don’t exceed shell argument limits, and keep each mimeType consistent with its file:
Say what must stay unchanged, and describe one change per request when you need precise control. To keep people consistent across a series, pass their photos as character references (up to 4). Keep the whole request body, Base64-encoded images included, under 20 MB. For a large reference image or one already on a CDN, replace that image’s inlineData part with a fileData part that carries its URL:
The server downloads the image, so the URL must be reachable without a login; the full conditions are in Large images and image URLs. Add the googleSearch tool to base an image on current information, such as a forecast or recent results. Allow TEXT in responseModalities so any text the model writes alongside the image comes back too:
Nano Banana 2 and Nano Banana 2.1 are the only Nano Banana models that can also use Google Image Search results as visual references; the FAQ shows how to turn it on. If you show grounded results to end users, follow Google’s grounding guide on displaying search suggestions.

Use the OpenAI-compatible route

If your app already uses the OpenAI SDK, call Nano Banana 2 through chat completions. This route has no ratio or size settings, so a text-only prompt returns a 1K image in a frame the model picks. The image comes back as a Base64 data URL inside message.content. Save this script as nano_banana_2_chat.py:
Generate an image, then edit a local file:

Errors and billing

Send values from these lists:
  • The ratios 1:4, 4:1, 1:8, and 8:1 work only on Nano Banana 2 and Nano Banana 2.1.
  • Google rejects lowercase sizes such as 2k.
  • A request can return HTTP 200 without an image, for example when the prompt doesn’t ask for one or a safety check blocks the output. It is charged as one call. Check finishReason (and promptFeedback if present), then change the prompt or references before resending; see Avoid paying for empty responses.
  • HTTP 401 means the key or the Authorization: Bearer header is wrong. Retry 429 and 5xx responses with backoff, and check call logs before resending a request that timed out.
The billing rules apply to every Nano Banana model.

FAQ

How much does the Nano Banana 2 API cost per image?

$0.055 per call, and each call returns one image. Output size, thinking level, reference images, and editing don’t change the price, so you can budget by request count. Google’s standard price for the same model is $0.067 at 1K, $0.101 at 2K, and $0.151 at 4K per output image (checked November 5, 2026), so a 4K image costs about 64% less on LaoZhang API. If you don’t need 512px output, Nano Banana 2.1 takes the same request at $0.045 per call.

How do I request 512px output?

Set generationConfig.imageConfig.imageSize to the string 512 on the Gemini-native route. Only Nano Banana 2 accepts it; Output sizes lists the other values.

Why does Nano Banana 2 keep returning square images?

Set the ratio in generationConfig.imageConfig.aspectRatio on the Gemini-native route, for example "aspectRatio": "16:9", and the output always uses it. The 14 values are in Parameters and limits. Without aspectRatio, the shape isn’t fixed:
  • With a reference image, the output follows the reference image’s ratio.
  • With a text-only prompt, the model picks the shape, which may be 1:1 or a wide frame.
  • The OpenAI-compatible route has no ratio setting. Switch to the Gemini-native route when you need a fixed ratio, as in Generate an image.

How do I change the thinking level, and does it affect the price?

Nano Banana 2 and Nano Banana 2 Lite support two thinking levels, minimal (the default) and high, to trade latency for quality, and LaoZhang API passes the setting through. On the Gemini-native route, set it in generationConfig.thinkingConfig.thinkingLevel, for example "thinkingConfig": {"thinkingLevel": "high"}. The level doesn’t change the price: LaoZhang API bills per call only, so a high request still costs the Nano Banana 2 per-call price (Google itself bills thinking tokens on top). Nano Banana Pro always thinks, and its level can’t be changed.

How do I turn on image search grounding, and what are the limits?

Add searchTypes to the Google Search tool from Ground images in Google Search, and list both webSearch and imageSearch:
According to Google’s generateContent reference:
  • A tool without searchTypes uses web search only, and imageSearch alone uses image search only.
  • With both types listed, as above, either is allowed; the model decides whether to search and which type to use.
  • searchTypes must be an object; an array has no effect. When image search is used, groundingMetadata in the response includes imageSearchQueries.
Google lists these limits: only Nano Banana 2 and Nano Banana 2.1 support image search grounding, it can’t currently use real-world images of people found through web search, and you must display search suggestions when you show grounded results to end users. Grounded requests cost $0.014 per search on top of the per-call price; the model decides how many searches to run, and call logs show the count. See the Nano Banana billing rules.