Skip to content

Nano Banana 2.1 ​

Image and video tasks share GET /v1/tasks/{id} to query status and GET /v1/tasks/{id}/content to download results. Image results use roles image_0–image_3; select the returned role when downloading.

Google · generation and editing · up to 16 references · 1–4 outputs · 1K / 2K / 4K

Create a task with POST https://api.tokenlio.ai/v1/images/generations, poll its status, then download the images. Generation and editing use the same JSON endpoint.

Before you start

gemini-nano-banana-2.1 is the API model ID used in the examples below. Confirm the ID, availability and prices in the model catalog; usable models depend on your Workspace and Key permissions.

1. Quick request ​

Provide your Tokenlio API Key through TOKENLIO_API_KEY. Creation, polling and content requests require Authorization: Bearer <TOKENLIO_API_KEY>.

bash
BASE_URL='https://api.tokenlio.ai'
curl "$BASE_URL/v1/images/generations" \
  -H "Authorization: Bearer $TOKENLIO_API_KEY" \
  -H 'Content-Type: application/json' \
  --data '{"model":"gemini-nano-banana-2.1","prompt":"A ginger cat by a window, afternoon light, watercolor illustration","size":"1:1","resolution":"1k","n":1}'

Example 202 response:

json
{
  "id": "dfc68868-d388-4d83-a173-d44e47a8bec7",
  "model": "gemini-nano-banana-2.1",
  "status": "queued",
  "assets": []
}

Save id. 202 means accepted, not finished. This endpoint does not return images or data[].b64_json immediately. Do not parse it as an OpenAI synchronous image response; follow the task workflow below.

2. Request parameters ​

ParameterTypeRequired / defaultDescription
modelstringRequiredgemini-nano-banana-2.1
promptstringRequiredNon-empty prompt; also required when sending references
sizestringautoauto or one of the 14 ratios below
resolutionstring1k1k / 2k / 4k; upper and lower case are accepted and normalized
ninteger1Number of output images, 1–4
image_urlsstring[]OptionalUp to 16 reference image URLs; base64 entries are not supported

Send only these fields. Unknown fields, duplicate fields, null and wrongly typed values (for example "n": "2" or "n": 2.5) are rejected with 400.

Size and resolution ​

  • Automatic: "size": "auto".
  • Ratios: 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9, 1:4, 4:1, 1:8, 8:1. Ratio and resolution determine output dimensions together.
  • Exact pixels such as "size": "1600x1200" are not supported, and neither are the GPT Image ratios 2:1, 1:2, 3:1, 1:3, 9:21. These values are rejected with 400 and are never silently converted to a supported size.
  • resolution accepts 1k / 2k / 4k in any letter case; values are normalized to lowercase before the task is created. The default is 1k. Values such as 0.5k are rejected.

Reference generation ​

json
{
  "model": "gemini-nano-banana-2.1",
  "prompt": "Keep the product in the first image and use the colors of the second image to create a clean product poster",
  "image_urls": [
    "https://YOUR_PUBLIC_CDN/product.png",
    "https://YOUR_PUBLIC_CDN/style.jpg"
  ],
  "size": "3:2",
  "resolution": "2k",
  "n": 2
}

POST this JSON to the same /v1/images/generations endpoint and explain each reference image's purpose in the prompt. Do not reuse video-specific input fields.

No quality, format, mask or background controls ​

Nano Banana 2.1 has no quality, output format, compression, background, moderation or mask parameter. Keep requests to model, prompt, size, resolution, n and image_urls.

  • The platform defaults quality: "auto", output_format: "png" and moderation: "low" are accepted as no-ops and ignored. An empty string for these three fields is treated as omitted. They never select an output format, so do not rely on them.
  • Any other non-empty value for quality, output_format or moderation is rejected with 400.
  • output_compression is rejected with 400 whenever it is present, including the value 0.
  • A non-empty background or mask_url is rejected with 400. Send image_urls and describe the edit in prompt instead of a mask.
  • Output files are PNG or JPEG depending on the generated result; the two can differ within one batch. Read the Content-Type of the downloaded bytes and choose the file extension to match. Do not assume PNG.

Input limits ​

Provide public HTTPS/443 direct URLs without login, custom headers or redirects for references. Local/private addresses, Cookie-protected pages and HTML pages are unsuitable. Reference images must not be base64 data or Data URIs. Keep URLs valid and content unchanged during processing.

PNG / JPEG / WebP references are recommended, with each side at most 6000 pixels. Download or format errors may surface during task processing; 202 does not mean all inputs have passed validation.

The JSON body limit is 8 MiB. Do not send stream, response_format, seed, negative_prompt or video-only task parameters.

3. Poll the task ​

Use the same API Key that created the task:

bash
TASK_ID='dfc68868-d388-4d83-a173-d44e47a8bec7'
curl "$BASE_URL/v1/tasks/$TASK_ID" \
  -H "Authorization: Bearer $TOKENLIO_API_KEY"

Poll every 5–15 seconds, backing off after transient errors. Query the original task instead of creating another one.

statusMeaning and action
queuedWaiting; keep polling
processingStill processing; keep polling
succeededFinished; read images from assets
failedFailed; inspect error.code and error.message

id and model identify the original task. assets is empty until results are available. An optional message provides guidance; if it says not to resubmit, keep querying the same id or contact support with that ID.

Example success response with two images:

json
{
  "id": "dfc68868-d388-4d83-a173-d44e47a8bec7",
  "model": "gemini-nano-banana-2.1",
  "status": "succeeded",
  "assets": [
    { "role": "image_0", "url": "https://SIGNED_DOWNLOAD_URL/image-0" },
    { "role": "image_1", "url": "https://SIGNED_DOWNLOAD_URL/image-1" }
  ]
}

assets[].role starts at image_0, up to image_3, one entry per returned image. assets[].url expires; query the task again to obtain fresh links. Task responses contain only the task identity, status, result assets and error details.

4. Download images ​

Use assets[].url directly, without adding your API Key. Alternatively, use the authenticated content endpoint with an explicit returned role:

bash
curl --location "$BASE_URL/v1/tasks/$TASK_ID/content?role=image_0" \
  -H "Authorization: Bearer $TOKENLIO_API_KEY" \
  -o image-0.bin
file --mime-type image-0.bin

The content endpoint returns a 307 redirect, not URL JSON. Change role for other images. Rename each saved file by the reported Content-Type: image/png → .png, image/jpeg → .jpg. Do not assume a fixed format or a fixed suffix.

Protect credentials and image links

Do not use --location-trusted. Custom clients must remove Authorization when following cross-host redirects. Do not publish or log API Keys or signed links; anyone holding a valid link can download the image. Signed URLs are temporary — query the task again when one expires instead of storing it as a permanent address.

Retries, pricing and errors ​

  • Disable automatic POST retries. Without Idempotency-Key, each POST creates a separate task, even with identical parameters, and may incur another charge. If creation times out without an ID, check console usage records first.
  • Optionally send one Idempotency-Key header: 1–128 non-whitespace printable ASCII characters. The same API Key, identifier and normalized parameters return the original task; reusing the identifier with different parameters returns 409. Changing only the letter case of resolution is the same request. Use a new identifier for a new task.
  • The model catalog lists a reference price per image for 1K, 2K and 4K. Each tier is the reference price of one image at that resolution, not a total for the whole request and not a fixed quote, price lock or upper bound. Reference images, prompt content and model reasoning can change the final cost. When n is greater than 1, billing is per image; the actual charge is shown in console usage records after the task finishes.
  • Image tasks do not accept max_charge_amount. Failures do not charge the customer.
  • The default image task timeout is 10 minutes. Such a task ends as status=failed with error.code TASK_TIMEOUT and error.message describing the timeout.
  • 400: check fields, integer types, size/ratio, resolution and unsupported controls; do not retry unchanged.
  • 401 / 403: check Key validity and permission to use the model.
  • 402: insufficient balance; add funds before creating new tasks.
  • 404: check the task ID and use the Key that created it.
  • 409: check for a conflicting idempotency identifier or a download attempted before results are ready.
  • 429: reduce request frequency/concurrent tasks and check usage limits.
  • 5xx: retry queries with backoff; for creation, first establish whether the task was accepted to avoid duplicates.

For HTTP errors, inspect error.type / error.message. For a task with status=failed, inspect error.code / error.message. Keep the task ID for troubleshooting; HTTP 200 alone does not mean image generation succeeded.

Access leading AI models through one unified API