Skip to main content
Nano Banana 2 (gemini-3.1-flash-image) is Google’s general-purpose Gemini image model and the one Google recommends for most image work. This guide shows how to generate and edit images from 512px to 4K on LaoZhang API at a fixed price per call.

What Nano Banana 2 supports

Thinking and Google Search grounding aren’t limited to Pro. Nano Banana 2 reasons through a prompt before it renders, with a minimal (default) or high thinking level, and it can ground an image in Google web and image search results. 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 Nano Banana 2 with Standard, 2 Lite, and Pro, 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). 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 1:1 image at 1K. 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 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.

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.