Nano Banana

Image generation and editing through the unified OpenAI Images API.

Nano Banana uses the unified OpenAI Images API: standard paths, Bearer authentication, and the data response format. Availability depends on your connection and API key permissions.

Models

ModelID
Nano Banana Pronano-banana-pro
Nano Banana 2nano-banana-2

Generation

Set BASE_URL to your HTTPS API origin without a trailing slash or /v1, and set API_KEY from your credential store. Path: POST /v1/images/generations.

bash
curl --fail-with-body "${BASE_URL}/v1/images/generations" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"nano-banana-2","prompt":"A white teapot on a green background","n":1,"size":"1024x1024","response_format":"url"}'
FieldValue
modelOne of the IDs above
promptNonempty text description
n1; defaults to 1
sizeauto, 1024x1024, 2048x2048, 4096x4096; defaults to auto
response_formaturl or b64_json; defaults to url

auto uses the model's standard resolution and chooses the aspect ratio automatically. Arbitrary sizes are not supported.

OpenAI SDK

Use the official SDK with your address and key. Set the result format explicitly:

python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["API_KEY"],
    base_url=os.environ["BASE_URL"].rstrip("/") + "/v1",
    max_retries=0,
    timeout=600.0,
)
result = client.images.generate(
    model="nano-banana-2",
    prompt="A white teapot on a green background",
    n=1,
    size="1024x1024",
    response_format="url",
)
print(result.data[0].url)

References And Editing

Path: POST /v1/images/edits. Nano Banana 2 accepts 1–14 JPEG, PNG, or WebP images, each up to 10 MiB. Upload a file using the standard multipart image field; use image[] for multiple files:

bash
curl --fail-with-body "${BASE_URL}/v1/images/edits" \
  -H "Authorization: Bearer $API_KEY" \
  -F "model=nano-banana-2" \
  -F "prompt=Keep the object and replace the background with green" \
  -F "image=@reference.png" \
  -F "n=1" \
  -F "size=1024x1024" \
  -F "response_format=url"

For HTTPS references, send JSON to the same /v1/images/edits endpoint:

json
{
  "model": "nano-banana-2",
  "prompt": "Keep the object and replace the background with green",
  "images": [{ "image_url": "REFERENCE_URL" }],
  "n": 1,
  "size": "1024x1024",
  "response_format": "url"
}

The URL must download without additional authorization headers. Nano Banana Pro references are not supported on this connection yet.

Result

The request waits for generation to finish. With response_format=url, the image is returned in the standard data array:

json
{ "data": [{ "url": "RESULT_URL" }] }

With b64_json, read data[0].b64_json and decode Base64. If that field is absent, check data[0].url: a download failure may leave a URL in the response. Save the result before the URL expires. Configure your client timeout to allow for generation time.

Limits And Errors

These models support one output per request. Masks, Files API file_id, changing quality/output_format, and streaming are not supported on this connection; unsupported parameters are rejected before generation.

Errors use an OpenAI-compatible error object with a safe description. HTTP status distinguishes parameter, key, access, quota, and temporary availability errors.

After a disconnect or timeout, the generation outcome may be unknown. Disable automatic retries for paid requests and check the task history in your dashboard before sending another request: another generation can create a separate paid task.