Docs / Image Series / Nano Banana / Sync - OpenAI Compatible
Nano Banana Synchronous Image Generation
Gemini image models (the nano-banana series) support OpenAI-compatible synchronous image generation and multipart image editing, return base64 by default, and work with the OpenAI SDK.
Gemini image models (the nano-banana series) can be called synchronously through the official OpenAI image generation endpoint POST /v1/images/generations: the request and response both use the standard OpenAI Images API format, so the OpenAI SDK and other image generation clients work without any adaptation.
- Synchronous mode: the request blocks until the image is ready and the response returns the image data directly — no task polling required. -response_formatdefaults tob64_json(Base64); specifyingurlreturns a gateway-hosted image link, which you should save promptly. - Text-to-image, image-to-image, and image editing (reference images) are supported; these models generate only 1 image per request, and billing follows the number of images actually generated. - The OpenAI-compatible editing endpointPOST /v1/images/editsis supported, uploadingimageorimage[]files via multipart/form-data.
Authentication#
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_KEYEndpoints#
- Text-to-image and JSON reference images:
POST /v1/images/generations - OpenAI-compatible multipart image editing:
POST /v1/images/edits
Supported models#
| Model | Description |
|---|---|
nano-banana-2 / gemini-3.1-flash-image | Nano Banana 2 — both names equivalent |
nano-banana-pro / gemini-3-pro-image | Nano Banana Pro — both names equivalent |
nano-banana-2-lite / gemini-3.1-flash-lite-image | Nano Banana 2 Lite — both names equivalent |
nano-banana-2.1 / gemini-nano-banana-2.1 | Nano Banana 2.1 — both names equivalent |
Request parameters#
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
model | string | Yes | — | Name of the image generation model; see the supported models above — the two names of each model are equivalent |
prompt | string | Yes | — | The prompt describing the image to generate or edit |
n | integer | No | 1 | Number of images requested (1-128); these models produce only 1 image per request, and billing follows the number actually generated |
size | string | No | Upstream default | OpenAI pixel size or W:H aspect ratio; see the mapping below |
quality | string | No | Upstream default | Clarity tier; see the mapping below |
response_format | string | No | b64_json | b64_json returns Base64; url returns a hosted image link |
image_urls | array | No | — | Reference image list (image-to-image/editing); supports http(s) URLs and data URLs, up to 20 images |
image / images | string/array | No | — | Edits-style reference image fields, equivalent to image_urls |
aspect_ratio | string | No | — | Specifies the aspect ratio directly; takes precedence over size |
image_size | string | No | — | Specifies the clarity tier directly; takes precedence over quality |
image_config | object | No | — | Fully overrides the Gemini imageConfig (e.g. {"aspectRatio":"21:9","imageSize":"4K"}); highest precedence |
size mapping#
| OpenAI size | Aspect ratio |
|---|---|
256x256 / 512x512 / 1024x1024 | 1:1 |
1536x1024 | 3:2 |
1024x1536 | 2:3 |
1024x1792 | 9:16 |
1792x1024 | 16:9 |
You can also pass a W:H format (e.g. 4:3) directly, which is forwarded to the upstream as-is; other custom sizes send no aspect ratio and fall back to upstream defaults.
quality mapping#
| Value | Mapping |
|---|---|
1K / 2K / 4K | Passed through unchanged |
hd / high | 2K |
standard / medium / low / auto | 1K |
| Empty | Not sent; the upstream default tier applies |
Pricing differs by tier; see the model pricing page for details.
Request examples#
Minimal text-to-image:
{
"model": "nano-banana-2",
"prompt": "A cat playing on the grass"
}Image-to-image / image editing:
curl https://api.apimax.ai/v1/images/generations --header 'Authorization: Bearer YOUR_API_KEY' --header 'Content-Type: application/json' --data '{
"model": "nano-banana-2",
"prompt": "Change the background to a seaside sunset",
"image_urls": ["https://example.com/photo.png"],
"aspect_ratio": "3:2",
"quality": "4K"
}'OpenAI-compatible multipart image editing#
POST /v1/images/edits uses multipart/form-data. Reference images can be uploaded as image or image[] files, up to 20 per request, each no larger than 10 MiB.
curl https://api.apimax.ai/v1/images/edits \
--header 'Authorization: Bearer YOUR_API_KEY' \
--form 'model=nano-banana-2' \
--form 'prompt=Change the background to a seaside sunset' \
--form 'image[]=@./photo.png' \
--form 'response_format=url'When response_format is omitted, b64_json is returned; specifying url returns a gateway-hosted link. mask is not currently converted to Gemini Nano Banana input — describe the area to edit in the prompt instead.
Response#
{
"created": 1757165031,
"data": [
{
"url": "",
"b64_json": "<Base64 image data>",
"revised_prompt": ""
}
]
}When response_format is url, data[].url returns a gateway-hosted link and b64_json is empty.
Behavior notes#
- Synchronous wait: the request blocks until the upstream finishes generating;
stream=truedoes not enable streaming and still returns synchronous JSON. - Content safety: if the upstream blocks the request (e.g.
SAFETY,PROHIBITED_CONTENT), HTTP 400 is returned and the error message carries the upstream block reason. - Billing: priced per image (rates vary by clarity tier), settled by the number of images actually generated; no image, no charge.
Error codes (HTTP)#
| Status code | code | Meaning |
|---|---|---|
| 400 | invalid_request | Invalid parameters, or content blocked by upstream safety filters |
| 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 |

