Docs / Image Series / Nano Banana / Async
Docs / Image Series / Nano Banana / Async
Google Nano Banana 2 (Gemini) async image generation. Excels at multi-image blending, real-person references, and text rendering, with support for thinking levels.
Nano Banana 2 (nano-banana-2) is a next-generation image generation model built on Google Gemini. It excels at text-to-image, image-to-image, and image editing, with outstanding multi-image blending, real-person references, and text rendering. This API is compatible with the OpenAI Images API format and uses an async task mode: it returns a task ID after submission, which you then poll for results.
- The async mode uses a dedicated endpoint,POST /v1/images/async-generations: it returns atask_idafter submission, and you retrieve the result with the task query API. -modelacceptsnano-banana-2orgemini-3.1-flash-image; the two names are equivalent. - Generated image links are pre-signed URLs valid for about 24 hours; save them promptly. - This model generates only 1 image per request (nis fixed at 1).
All endpoints require Bearer token authentication. Create your key on the API Key management page and add it to the request header:
Authorization: Bearer YOUR_API_KEYPOST /v1/images/async-generations
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
model | string | Yes | nano-banana-2 | Model name; use nano-banana-2 or gemini-3.1-flash-image — both equivalent |
prompt | string | Yes | — | Prompt describing the image to generate or edit. Up to about 2000 tokens |
size | string | No | auto | Aspect ratio of the generated image; see the supported values below |
resolution | string | No | 2K | Clarity tier 1K/2K/4K; tiers are priced differently |
image_urls | array | No | — | List of reference image URLs for image-to-image / image editing. Up to 14 images, each < 20MB |
model_params | object | No | — | Model extension parameters; see below |
callback_url | string | No | — | HTTPS callback URL invoked when the task finishes |
Defaults to auto (the model decides automatically). Supported values:
auto, 1:1, 1:4, 4:1, 1:8, 8:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9
| Value | Description |
|---|---|
1K | About 1MP; fastest speed, lowest cost |
2K | About 4MP (default); balances quality and cost |
4K | About 8MP; richest detail, highest cost |
.jpeg, .jpg, .png, .webp.png or .jpg)| Field | Type | Default | Description |
|---|---|---|---|
thinking_level | string | auto | Thinking level: auto = automatic / min = minimal reasoning, fastest / high = deep reasoning, best quality |
The request body is structurally identical to the synchronous OpenAI Images API. Simplest text-to-image:
{
"model": "nano-banana-2",
"prompt": "A cat playing on the grass"
}Specify aspect ratio and clarity:
{
"model": "nano-banana-2",
"prompt": "A cinematic wide-angle shot of a futuristic city skyline at dusk",
"size": "16:9",
"resolution": "4K"
}Image-to-image / multi-image blending (with reference images) + deep reasoning:
{
"model": "nano-banana-2",
"prompt": "Combine these two people into the same poster, cyberpunk style",
"size": "3:4",
"resolution": "2K",
"image_urls": [
"https://example.com/person1.png",
"https://example.com/person2.png"
],
"model_params": {
"thinking_level": "high"
},
"callback_url": "https://your-domain.com/webhook/image-done"
}Task information is returned immediately after a successful submission (HTTP 200):
{
"id": "task_V1StGXR8_Z5jdHi6B",
"object": "image.generation.task",
"type": "image",
"status": "queued",
"progress": 0,
"created": 1757165031,
"model": "nano-banana-2",
"task_info": {
"can_cancel": true,
"estimated_time": 45
}
}id is the task identifier (task_ prefix), used for subsequent queries.
GET /v1/tasks/{id}
curl 'https://api.apimax.ai/v1/tasks/task_V1StGXR8_Z5jdHi6B' \
--header 'Authorization: Bearer <token>'We recommend polling every 2–5 seconds until status becomes completed or failed.
Completed (`completed`):
{
"id": "task_V1StGXR8_Z5jdHi6B",
"object": "image.generation.task",
"type": "image",
"status": "completed",
"progress": 100,
"created": 1757165031,
"completed_at": 1757165076,
"model": "nano-banana-2",
"data": [
{
"url": "https://cdn.example.com/img/.../0.png?X-Amz-Signature=...",
"url_expires_at": 1757168676
}
],
"usage": {
"input_tokens": 18,
"output_tokens": 1290,
"total_tokens": 1308
}
}The pre-signed URL is re-signed on every query, so polling also "refreshes" expired links.
Failed (`failed`):
{
"id": "task_V1StGXR8_Z5jdHi6B",
"object": "image.generation.task",
"type": "image",
"status": "failed",
"failed_at": 1757165076,
"model": "nano-banana-2",
"error": {
"code": "upstream_error",
"message": "gemini blocked: SAFETY"
}
}| Status | Meaning |
|---|---|
queued | Queued, waiting to execute |
in_progress | Generating |
completed | Generation completed; data contains the image links |
failed | Generation failed; see error |
| Code | Meaning |
|---|---|
upstream_error | Upstream returned 4xx (content safety block / invalid prompt) |
upstream_unavailable | Upstream still returned 5xx after multiple retries |
storage_error | Failed to upload the result to cloud storage |
internal_error | Internal gateway error |
When a task fails, the pre-deducted quota is automatically refunded.
| Status code | code | Meaning |
|---|---|---|
| 400 | invalid_request | Missing prompt/model or otherwise invalid parameters |
| 400 | model_not_supported | The model is not in the async-supported list |
| 401 | unauthorized | Invalid or expired token |
| 403 | insufficient_user_quota | Insufficient quota; please top up |
| 403 | (empty string) | The token does not have access to this model |
| 429 | rate_limit_exceeded | Too many requests |
| 500 | internal_error | Internal server error |
After callback_url is set, the gateway POSTs a callback whenever the task completes / fails / is canceled. The callback body uses the same format as the task query API.