Guide

How to use the Nano Banana API: request, polling, Python and cost

Prices checked Nov 26, 2026 · 5 min read

How to use the Nano Banana API: one request returning a finished image

To use the Nano Banana API, send one POST /v1/tasks with model set to nano-banana-2-1 and a prompt inside input. You receive a task id, then either poll GET /v1/tasks/{id} or give us a callback_url. When the task succeeds, output.urls holds the image. On TapModels a Nano Banana 2.1 image costs $0.02 at 1K, $0.03 at 2K and $0.045 at 4K, and a failed task costs nothing.

The request

Image generation is asynchronous, like every media model here. Auth is a bearer key (Authorization: Bearer sk_live_...) and the base URL is https://api.tapmodels.com/v1.

{
  "model": "nano-banana-2-1",
  "input": {
    "prompt": "A matte white ceramic mug on grey stone, soft window light",
    "aspect_ratio": "4:3",
    "resolution": "2K",
    "output_format": "png"
  },
  "callback_url": "https://your.app/hooks/tapmodels"
}

The reply is 202 with { "id": "task_...", "status": "queued", "estimated_credits": 3 }. Credits are held at submit and charged on success. If the task fails, the hold is released and credits_charged is 0.

Parameters and their valid values

These come from the model's catalog entry. The live schema is at GET /v1/models/nano-banana-2-1.

FieldRequiredValid valuesDefault
promptyesText describing the imagenone
image_inputnoUp to 10 reference images, for edits or combiningnone
aspect_rationo1:1, 4:3, 3:4, 16:9, 9:16, 21:91:1
resolutionno1K, 2K, 4K1K
output_formatnojpg, pngjpg

Reference images are files you first upload with POST /v1/files (multipart, up to 30 MB). Then pass the returned URL. An invalid value returns 422 invalid_input, and the message names the field.

Python example

Nano Banana does not use the OpenAI chat endpoint, so plain requests is enough.

import os, time, requests

BASE = "https://api.tapmodels.com/v1"
H = {"Authorization": f"Bearer {os.environ['TAPMODELS_API_KEY']}"}

r = requests.post(f"{BASE}/tasks", headers=H, json={
    "model": "nano-banana-2-1",
    "input": {"prompt": "A matte white ceramic mug on grey stone, soft window light",
              "resolution": "2K", "aspect_ratio": "4:3"},
})
r.raise_for_status()
task = r.json()

while task["status"] in ("queued", "running"):
    time.sleep(3)
    task = requests.get(f"{BASE}/tasks/{task['id']}", headers=H).json()

if task["status"] == "succeeded":
    print(task["output"]["urls"], task["credits_charged"])
else:
    print(task["error"])

Output files are kept for 14 days, so download what you want to keep.

Curl example

curl https://api.tapmodels.com/v1/tasks \
  -H "Authorization: Bearer $TAPMODELS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"nano-banana-2-1","input":{"prompt":"A matte white ceramic mug on grey stone, soft window light","resolution":"2K"}}'

curl https://api.tapmodels.com/v1/tasks/task_123 \
  -H "Authorization: Bearer $TAPMODELS_API_KEY"

Polling or callback_url

Polling every three seconds works for a script. For a web app, pass callback_url and skip the loop. When the task reaches a final status, we POST the task object to your URL with an X-Signature header (t=<unix>,v1=<hex hmac-sha256 of "t.body">, signed with your account's webhook secret). We retry non-2xx replies with backoff for 24 hours, so make your handler idempotent.

Editing and combining images

Nano Banana 2.1 is listed for text to image and image editing, with the same endpoint for both. To edit, upload the source picture first.

curl https://api.tapmodels.com/v1/files \
  -H "Authorization: Bearer $TAPMODELS_API_KEY" \
  -F "file=@mug.jpg"

The reply holds a url and an expires_at. Put that URL in image_input and write the change as a plain instruction: "Put this mug on a walnut desk, keep the handle shape". You can send up to 10 reference images to combine them. Uploaded files are kept for 14 days, the same as outputs.

Two habits keep editing cost down. First, send the smallest resolution that lets you judge the edit, because each retry is billed at the resolution you asked for. Second, change one thing per request, since a prompt that asks for five edits is the one you will rerun three times.

Batching many images

The submit limit is 20 new tasks per 10 seconds per account, so a loop of 500 requests needs a short pause or a retry on 429. Credits are held when each task is submitted, so a big batch holds credits up front: 500 tasks at 2K hold 1,500 credits ($15.00) until they finish. If your balance minus held credits is lower than a new task's estimate, that submit returns 402 insufficient_credits. Top up before a large run, or set a spend limit on the key so a bug in your loop cannot spend more than you planned.

Nano Banana API cost and pricing

List price is the provider's published rate as recorded in our catalog on 2026-11-26. Credits are 100 per dollar.

ResolutionTapModelsList priceLower by
1K$0.02$0.0336about 40%
2K$0.03$0.0504about 40%
4K$0.045$0.113about 60%

Price depends on resolution only. Adding reference images does not change it.

Worked example: you generate 500 product shots at 2K.

  • TapModels: 500 x $0.03 = $15.00 (1,500 credits)
  • At list price: 500 x $0.0504 = $25.20

If you draft at 1K first and finish only 100 of them at 4K, the cost is 500 x $0.02 + 100 x $0.045 = $10.00 + $4.50 = $14.50. Resolution drives the price, so draft small. Compare it with other image models in Nano Banana vs Seedream, or use the media cost calculator.

Common errors

HTTPCodeWhat to do
401unauthorizedCheck the key is present and not revoked
402insufficient_creditsBalance minus held credits is below the estimate: top up
402key_limit_reachedThe key's spend limit would be exceeded: raise it
403model_not_allowedThe key's allowed_models excludes this model
422invalid_inputA field is outside the valid values above
429rate_limitedWait for Retry-After, then retry
task failedupstream_errorResubmit: 0 credits were charged

The default limit is 20 new tasks per 10 seconds per account.

Next step: see all image prices on the Nano Banana pricing page, or read the full request fields in the docs.

Frequently asked questions

How do I use the Nano Banana API?

Send POST /v1/tasks with model nano-banana-2-1 and an input object holding a prompt. You get a task id back with status queued. Poll GET /v1/tasks/{id} until the status is succeeded, then read the image URLs in output.urls. Or pass a callback_url and we post the result to you.

How much does the Nano Banana API cost?

On TapModels, Nano Banana 2.1 costs $0.02 per image at 1K, $0.03 at 2K and $0.045 at 4K. The price depends on the resolution you request, not on the number of reference images. Failed tasks are not charged.

Can the Nano Banana API edit images?

Yes. Nano Banana 2.1 is listed for both text to image and image editing. Upload a file to /v1/files, pass its URL in the image_input field, and describe the change in the prompt. The catalog allows up to 10 reference images per request.

Is there a Python SDK for the Nano Banana API?

We do not ship a separate SDK. Media models use plain HTTP, so the requests library is enough: one POST to create the task and a loop that polls it. Chat models use the OpenAI-compatible endpoint, but images do not.

Sources