> Markdown mirror of https://router.one/blog/nano-banana-2-api-guide for AI assistants and crawlers. Router One is an OpenAI-compatible LLM API gateway.
> Published: 2026-08-25 · Author: Router One Team

# Nano Banana 2 API Guide: gemini-3.1-flash-image-preview

_Call Nano Banana 2 (gemini-3.1-flash-image-preview) through one OpenAI-compatible Images API: text-to-image, reference-image edits, flat per-image pricing, and how to choose against Nano Banana Pro._

Nano Banana 2 is the community name for Google's Gemini 3.1 Flash Image model. On Router One it is listed as `gemini-3.1-flash-image-preview`, sits in the image category of the catalog next to its sibling Nano Banana Pro (`gemini-3-pro-image-preview`), and is called through the same OpenAI-compatible Images API as every other image model on the gateway — one key, one wallet, a cost trace per request.

This guide is the hands-on part: the exact request for text-to-image, the exact request for editing with a reference image, what the model does and does not accept, how it is billed, and how to decide between Nano Banana 2 and Nano Banana Pro without guessing.

## Names, IDs, and Prices

Two Google image models live in the catalog, and the nicknames are easy to mix up:

| Community name | Model ID on Router One | Unit price (Aug 2026) |
| --- | --- | --- |
| Nano Banana 2 | gemini-3.1-flash-image-preview | $0.50 per image |
| Nano Banana Pro | gemini-3-pro-image-preview | $0.50 per image |

Both are unit-priced: one flat USD amount per generated image, no token math on the output. Both are the same price on Router One at the time of writing — the live number is always on the [model page](https://router.one/models/gemini-3-1-flash-image-preview) — so the choice between them is about output, not budget. More on that below.

## Setup

Create an API key in the Router One dashboard and top up the wallet. From Mainland China the endpoint is reachable without a VPN, and Alipay works on the hosted checkout — see [Alipay top-ups](https://router.one/alipay-llm-api). Then point your client at the gateway:

```bash
export ROUTER_ONE_KEY=sk-your-router-one-key
export OPENAI_BASE_URL=https://api.router.one/v1
```

If you already use the key for chat models, nothing changes — the image endpoints are on the same key.

## Text-to-Image: POST /v1/images/generations

The request is the OpenAI Images API shape: a JSON body with `model` and `prompt`. Add `n` to get several candidates from one call.

```bash
curl -X POST https://api.router.one/v1/images/generations \
  -H "Authorization: Bearer $ROUTER_ONE_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "gemini-3.1-flash-image-preview",
       "prompt": "Isometric illustration of a night market, warm lantern light, no text",
       "n": 2}'
```

Two things about this model specifically:

- **`size`, `quality`, and `response_format` do not apply.** Send them and they are ignored; the prompt is what steers the output. Put composition and framing instructions in the prompt text.
- **The response can carry either `data[].b64_json` or `data[].url`.** Most images come back inline as base64, but a URL is possible. Handle both branches and save the file promptly rather than assuming one shape.

With the official OpenAI Python SDK:

```python
import base64, httpx
from openai import OpenAI

client = OpenAI(base_url="https://api.router.one/v1", api_key="sk-your-router-one-key")

result = client.images.generate(
    model="gemini-3.1-flash-image-preview",
    prompt="Isometric illustration of a night market, warm lantern light, no text",
    n=2,
)

for i, item in enumerate(result.data):
    png = base64.b64decode(item.b64_json) if item.b64_json else httpx.get(item.url).content
    with open(f"night-market-{i}.png", "wb") as f:
        f.write(png)
```

Every image the call returns is billed at the unit price — `n: 2` is two images and two units. The full field reference is in the [Images API docs](https://router.one/docs/images/createImageGeneration).

## Editing With a Reference Image: POST /v1/images/edits

Nano Banana 2 lists image input in the catalog, so you can hand it a picture and describe the change. That goes to the edits endpoint, which is `multipart/form-data` rather than JSON: the reference goes in the `image` field, the instruction in `prompt`.

```bash
curl -X POST https://api.router.one/v1/images/edits \
  -H "Authorization: Bearer $ROUTER_ONE_KEY" \
  -F model=gemini-3.1-flash-image-preview \
  -F image=@teapot.png \
  -F prompt="Place this teapot on a marble counter in soft morning light, keep the label readable"
```

Repeat `-F image=@...` to pass more than one reference — a product shot plus a style board, for example. The SDK call is `client.images.edit(model=..., image=open("teapot.png", "rb"), prompt=...)`, and the response has the same `data[]` shape as generations, so the same save-both-branches code works. Reference files are capped at 25 MB each.

Typical uses: restyling product photos, swapping backgrounds, turning a sketch into a rendered scene, or producing a consistent series from one hero image.

## Nano Banana 2 or Nano Banana Pro?

Because both models cost the same per image on Router One and take the same request, the honest answer is: run your own prompts through both. The gateway makes that a one-line change — same key, same endpoint, swap the `model` string — and every request lands in Dashboard → Logs with model, unit cost, latency, and status, so the comparison is a filter, not a spreadsheet.

Practical guidance from that kind of A/B:

- Start with **Nano Banana 2** for volume work — thumbnails, variations, iterating on a prompt until the composition is right.
- Send the shortlisted prompts to **Nano Banana Pro** and keep whichever output your reviewers prefer. If the Pro output is not visibly better for your use case, there is no cost reason to use it.
- Keep the same reference-image workflow for both; both accept edits.

## Keeping the Bill Predictable

Image pipelines are where usage surprises happen, and `n` multiplies quietly. The gateway's standard controls apply:

- **Per-key budgets.** Give the image pipeline its own key with a spend cap so a runaway batch stops at the cap instead of draining the wallet.
- **Per-request traces.** Unit cost per generation, in the same log as your chat traffic — finance sees what a campaign's assets actually cost.
- **Flat unit pricing.** Cost forecasting is images × unit price. No token estimation.

## FAQ

**Is Nano Banana 2 the same thing as gemini-3.1-flash-image-preview?**
Yes. Nano Banana 2 is the community name; `gemini-3.1-flash-image-preview` is the model ID you put in the request. Nano Banana Pro is the Pro tier of the same line, `gemini-3-pro-image-preview`.

**Is Nano Banana 2 cheaper than Nano Banana Pro on Router One?**
No. As of August 2026 both are $0.50 per image on Router One. Check the catalog for the live figure, and choose by output quality on your prompts rather than by price.

**Can I set the image size or quality?**
Not for this model. `size`, `quality`, and `response_format` are accepted but ignored on Nano Banana 2 — describe the framing you want in the prompt instead.

**How do I use my own image as the starting point?**
Use POST /v1/images/edits with `multipart/form-data`: the reference in the `image` field, the instruction in `prompt`. Generations is JSON and takes text only.

**Does the response contain a URL or base64?**
Either. Handle `data[].b64_json` and `data[].url` in the same loop and save the bytes as soon as you have them.

**Does it work from Mainland China?**
Yes. The endpoint is reachable without a VPN, and the wallet can be topped up with Alipay or a card on one hosted checkout, or with USDT/USDC on six chains.

## Conclusion

Nano Banana 2 is a one-line change for anyone already on the gateway: put `gemini-3.1-flash-image-preview` in `model`, send a prompt, save whichever of `b64_json` or `url` comes back. Edits with a reference image are one multipart call away, billing is per image, and the same key that runs your chat models runs this.

Start on the [image generation API page](https://router.one/image-generation-api) for the endpoint surface, check the [model page](https://router.one/models/gemini-3-1-flash-image-preview) for the live price, and [create a key at router.one](https://router.one/signup) to make the first call.

## See also

- Canonical page: https://router.one/blog/nano-banana-2-api-guide
- LLM API Payment: https://router.one/wechat-pay-llm-api
- All blog posts: https://router.one/blog
- Models and per-model token rates: https://router.one/models (markdown: https://router.one/models.md)
- Pricing: https://router.one/pricing
- API docs (markdown): https://router.one/docs.md
- Company facts: https://router.one/facts/company.md
