apimaxDocs
DocsPricingConsole
API ReferenceIntegration GuideUser GuideChangelog

Music Series

Image Series

POSTNano Banana Synchronous Image Generation

Video series

Task Management

Error Code ReferenceQuery Task StatusGET

Account Management

Query Quota UsageGET

Docs / Image Series / Nano Banana / Sync - OpenAI Compatible

Sync - OpenAI CompatiblePOSTImage GenerationNano-BananaGeminiSyncgemini-3-pro-imagegemini-3.1-flash-imagegemini-3.1-flash-lite-imagegemini-nano-banana-2.1

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.

POSThttps://api.apimax.ai/v1/images/generations
Try it
Bearer API KeyJSONServer-side call

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_format defaults to b64_json (Base64); specifying url returns 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 endpoint POST /v1/images/edits is supported, uploading image or image[] 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:

text
Authorization: Bearer YOUR_API_KEY

Endpoints#

  • Text-to-image and JSON reference images: POST /v1/images/generations
  • OpenAI-compatible multipart image editing: POST /v1/images/edits

Supported models#

ModelDescription
nano-banana-2 / gemini-3.1-flash-imageNano Banana 2 — both names equivalent
nano-banana-pro / gemini-3-pro-imageNano Banana Pro — both names equivalent
nano-banana-2-lite / gemini-3.1-flash-lite-imageNano Banana 2 Lite — both names equivalent
nano-banana-2.1 / gemini-nano-banana-2.1Nano Banana 2.1 — both names equivalent

Request parameters#

ParameterTypeRequiredDefaultDescription
modelstringYes—Name of the image generation model; see the supported models above — the two names of each model are equivalent
promptstringYes—The prompt describing the image to generate or edit
nintegerNo1Number of images requested (1-128); these models produce only 1 image per request, and billing follows the number actually generated
sizestringNoUpstream defaultOpenAI pixel size or W:H aspect ratio; see the mapping below
qualitystringNoUpstream defaultClarity tier; see the mapping below
response_formatstringNob64_jsonb64_json returns Base64; url returns a hosted image link
image_urlsarrayNo—Reference image list (image-to-image/editing); supports http(s) URLs and data URLs, up to 20 images
image / imagesstring/arrayNo—Edits-style reference image fields, equivalent to image_urls
aspect_ratiostringNo—Specifies the aspect ratio directly; takes precedence over size
image_sizestringNo—Specifies the clarity tier directly; takes precedence over quality
image_configobjectNo—Fully overrides the Gemini imageConfig (e.g. {"aspectRatio":"21:9","imageSize":"4K"}); highest precedence

size mapping#

OpenAI sizeAspect ratio
256x256 / 512x512 / 1024x10241:1
1536x10243:2
1024x15362:3
1024x17929:16
1792x102416: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#

ValueMapping
1K / 2K / 4KPassed through unchanged
hd / high2K
standard / medium / low / auto1K
EmptyNot sent; the upstream default tier applies

Pricing differs by tier; see the model pricing page for details.

Request examples#

Minimal text-to-image:

json
{
  "model": "nano-banana-2",
  "prompt": "A cat playing on the grass"
}

Image-to-image / image editing:

bash
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.

bash
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#

json
{
  "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=true does 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 codecodeMeaning
400invalid_requestInvalid parameters, or content blocked by upstream safety filters
401unauthorizedToken is invalid or expired
403insufficient_user_quotaInsufficient quota; please top up
403(empty string)Token does not have access to this model
429rate_limit_exceededToo many requests
500internal_errorInternal server error

Next steps

All docs
Midjourney API OverviewMidjourney MJ Proxy-compatible API: endpoints, actions, per-call pricing, task states and error codes.Nano Banana 2.1 Image GenerationGoogle Nano Banana 2.1 (Gemini) async image generation. Excels at multi-image blending, real-person references, and text rendering, with a thinking level option.Nano Banana 2 Lite Image GenerationAsynchronous 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 Pro Image GenerationAsynchronous image generation with Google Nano Banana 2 (Gemini), excelling at multi-image fusion, real-person references, and text rendering, with support for reasoning levels.GPT Image 2 Image Generation/v1/images/async-generationsNano Banana 2 Image GenerationGoogle Nano Banana 2 (Gemini) async image generation. Excels at multi-image blending, real-person references, and text rendering, with support for thinking levels.
On this page
OverviewAuthenticationEndpointsSupported modelsRequest parameterssize mappingquality mappingRequest examplesOpenAI-compatible multipart image editingResponseBehavior notesError codes (HTTP)Next steps
API

POST /v1/images/generations