Docs / Image Series / Nano Banana / Async
Docs / Image Series / Nano Banana / Async
Asynchronous image generation with Google Nano Banana 2 (Gemini), excelling at multi-image fusion, real-person references, and text rendering, with support for reasoning levels.
Nano Banana 2 Lite (nano-banana-2-lite) is a lightweight image generation model built on Google Gemini. It excels at text-to-image, image-to-image, and image editing, with outstanding multi-image fusion, real-person reference, and text rendering. This endpoint is compatible with the OpenAI Images API format and uses an asynchronous task mode: submitting a request returns a task ID, which you then poll for the result.
- Asynchronous mode uses a dedicated endpoint,POST /v1/images/async-generations, which returns atask_idon submission. Use the task query endpoint to fetch the result. -modelacceptsnano-banana-2-liteorgemini-3.1-flash-lite-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-lite | Model name; use nano-banana-2-lite or gemini-3.1-flash-lite-image — both equivalent |
prompt | string | Yes | — | The 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 enumeration below |
resolution | string | No | 1K | Clarity tier; Lite currently offers 1K only |
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 completes |
Defaults to auto (decided automatically by the model). 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 | ~1MP, the only tier currently offered for Lite |
.jpeg, .jpg, .png, .webp.png or .jpg)| Field | Type | Default | Description |
|---|---|---|---|
thinking_level | string | auto | Thinking/reasoning level: auto (automatic) / min (minimal reasoning, fastest) / high (deep reasoning, best quality) |
The request body has the same structure as the synchronous OpenAI Images API. Minimal text-to-image:
{
"model": "nano-banana-2-lite",
"prompt": "A cat playing on the grass"
}Specifying the aspect ratio and resolution:
{
"model": "nano-banana-2-lite",
"prompt": "A cinematic wide shot of a futuristic city skyline at dusk",
"size": "16:9",
"resolution": "1K"
}Image-to-image / multi-image fusion (with reference images) + deep reasoning:
{
"model": "nano-banana-2-lite",
"prompt": "Combine these two people into the same poster, cyberpunk style",
"size": "3:4",
"resolution": "1K",
"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"
}On successful submission, task information is returned immediately (HTTP 200):
{
"id": "task_V1StGXR8_Z5jdHi6B",
"object": "image.generation.task",
"type": "image",
"status": "queued",
"progress": 0,
"created": 1757165031,
"model": "nano-banana-2-lite",
"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>'Poll 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-lite",
"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 effectively "refreshes" expired links.
Failed (`failed`):
{
"id": "task_V1StGXR8_Z5jdHi6B",
"object": "image.generation.task",
"type": "image",
"status": "failed",
"failed_at": 1757165076,
"model": "nano-banana-2-lite",
"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 exception |
If 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 | Model is not in the asynchronous support list |
| 401 | unauthorized | Token is invalid or expired |
| 403 | insufficient_user_quota | Insufficient quota; please top up |
| 403 | (empty string) | Token does not have access to this model |
| 429 | rate_limit_exceeded | Too many requests |
| 500 | internal_error | Internal server error |
When callback_url is set, the gateway POSTs a callback whenever the task completes / fails / is canceled. The callback body has the same format as the task query endpoint.