apimaxDocs
DocsPricingConsole
API ReferenceIntegration GuideUser GuideChangelog

Music Series

Image Series

DOCNative nano-banana format (synchronous)

Video series

Task Management

Error Code ReferenceQuery Task StatusGET

Account Management

Query Quota UsageGET

Docs / Image Series / Nano Banana / Sync - Native Format

Sync - Native FormatImage GenerationNano-BananaGeminiSyncNativegemini-3-pro-imagegemini-3.1-flash-imagegemini-3.1-flash-lite-imagegemini-nano-banana-2.1

Native nano-banana format (synchronous)

Synchronous image generation in Google Gemini Nano Banana's native generateContent format. Supports text-to-image, image-to-image, and aspect_ratio/image_size configuration, returning inline_data base64 directly.

APIhttps://api.apimax.ai/v1beta/models/{model}:generateContent
Try it
Bearer API KeyJSONServer-side call

Nano Banana is Google Gemini's native image generation capability, currently offered as gemini-3.1-flash-image (Nano Banana 2) / gemini-3-pro-image (Nano Banana Pro) / gemini-3.1-flash-lite-image (Nano Banana 2 Lite), gemini-nano-banana-2.1 (Nano Banana 2.1), plus gemini-2.5-flash-image (first-generation Nano Banana). This API uses the native Gemini `generateContent` format: the call is synchronous and returns the result directly (base64 inlined in the response), with no task polling needed.

- This API is in the native Gemini format (/v1beta/models/<model>:generateContent), which differs from the OpenAI-compatible format. For OpenAI-style async tasks (/v1/images/async-generations returning a task_id to poll), see Nano Banana 2 async generation. - The generated image is inlined directly in the response parts as inline_data (base64); decode and save it promptly. - This model generates only 1 image per request.

Authentication#

All endpoints require Bearer token authentication (the gateway accepts both x-goog-api-key and Authorization: Bearer). Create your key on the API Key management page and add it to the request header:

text
Authorization: Bearer YOUR_API_KEY

Create a task#

POST /v1beta/models/{model}:generateContent

  • Set {model} to any of the models below; for each model, the gemini-* name and its nano-banana-* alias are equivalent:
  • gemini-3.1-flash-image / nano-banana-2 (Nano Banana 2)
  • gemini-3-pro-image / nano-banana-pro (Nano Banana Pro)
  • gemini-3.1-flash-lite-image / nano-banana-2-lite (Nano Banana 2 Lite)
  • gemini-nano-banana-2.1 / nano-banana-2.1 (Nano Banana 2.1)
  • gemini-2.5-flash-image (first-generation Nano Banana)
  • The request body is application/json and structurally identical to Gemini generateContent.

The simplest text-to-image request only needs a text parts entry inside contents and declares image output in generationConfig.responseModalities:

json
{
  "contents": [
    {
      "role": "user",
      "parts": [{ "text": "A cat playing on the grass" }]
    }
  ],
  "generationConfig": {
    "responseModalities": ["TEXT", "IMAGE"]
  }
}

Specify aspect ratio and clarity (image_config uses snake_case; the gateway converts it to camelCase before passing it upstream):

json
{
  "contents": [
    { "role": "user", "parts": [{ "text": "A cinematic wide-angle shot of a futuristic city skyline at dusk" }] }
  ],
  "generationConfig": {
    "responseModalities": ["IMAGE"],
    "image_config": {
      "aspect_ratio": "16:9",
      "image_size": "2K"
    }
  }
}

Image-to-image / image editing (pass reference images as inline_data inside parts):

json
{
  "contents": [
    {
      "role": "user",
      "parts": [
        { "text": "Add a cute kitten next to her" },
        {
          "inline_data": {
            "mime_type": "image/png",
            "data": "<BASE64_IMAGE_DATA>"
          }
        }
      ]
    }
  ],
  "generationConfig": {
    "responseModalities": ["IMAGE"]
  }
}

Request parameters#

The top level of the request body consists of contents (the conversation) and generationConfig (generation settings).

contents#

FieldTypeRequiredDescription
contentsarrayYesArray of conversation entries, each containing role and parts
contents[].rolestringNouser / model
contents[].parts[]arrayYesContent blocks, either text or inline_data

parts (content blocks)#

FieldTypeDescription
textstringText prompt describing the image to generate or edit
inline_dataobjectReference image (image-to-image / editing), containing mime_type and data (base64)
inline_data.mime_typestringImage MIME type: image/png, image/jpeg, image/webp
inline_data.datastringBase64-encoded image (without the data: prefix)

generationConfig#

FieldTypeRequiredDefaultDescription
responseModalitiesarrayYes—Output modalities; use ["IMAGE"] or ["TEXT","IMAGE"] for image generation
image_configobjectNo—Image configuration (snake_case; the gateway converts it to camelCase)
image_config.aspect_ratiostringNo1:1Aspect ratio; see the values below
image_config.image_sizestringNo1KClarity 1K/2K/4K (3.1 Flash Image also supports 512)
Field naming: Native Gemini REST uses snake_case (inline_data, mime_type, image_config, aspect_ratio, image_size); the gateway accepts snake_case and converts it to camelCase before passing it upstream. Do not mix in imageConfig/aspectRatio (camelCase), or the request will fail.

aspect_ratio#

ValueDescription
1:1Square (default)
16:9, 9:16Landscape / portrait
21:9, 9:21Ultrawide / ultratall
4:3, 3:4, 3:2, 2:3Common ratios
4:5, 5:4Portrait / landscape (social media)
1:4, 4:1, 1:8, 8:1Ultra-flat ratios (3.1 Flash Image only)

Request examples#

Text-to-image:

bash
curl -s -X POST   "https://api.apimax.ai/v1beta/models/gemini-3.1-flash-image:generateContent"   -H "Authorization: Bearer <token>"   -H "Content-Type: application/json"   -d '{
    "contents": [
      { "role": "user", "parts": [{ "text": "A cat playing on the grass" }] }
    ],
    "generationConfig": {
      "responseModalities": ["IMAGE"],
      "image_config": { "aspect_ratio": "1:1", "image_size": "2K" }
    }
  }'

Image-to-image (Python requests, converting a local image to base64):

python
import requests, base64

with open("input.png", "rb") as f:
    img_b64 = base64.b64encode(f.read()).decode("utf-8")

url = "https://api.apimax.ai/v1beta/models/gemini-3.1-flash-image:generateContent"
headers = {"Authorization": "Bearer <token>", "Content-Type": "application/json"}
payload = {
    "contents": [{
        "role": "user",
        "parts": [
            {"text": "Add a cute kitten next to her"},
            {"inline_data": {"mime_type": "image/png", "data": img_b64}},
        ],
    }],
    "generationConfig": {"responseModalities": ["IMAGE"]},
}
resp = requests.post(url, headers=headers, json=payload)
print(resp.json())

Response example#

Returns the Gemini GenerateContentResponse structure synchronously; the generated image is inlined as inline_data inside candidates[].content.parts[]:

json
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "inline_data": {
              "mime_type": "image/png",
              "data": "iVBORw0KGgoAAAANSUhEUgAA..."
            }
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP"
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 12,
    "candidatesTokenCount": 4160,
    "totalTokenCount": 4172
  }
}

Base64-decode candidates[0].content.parts[].inline_data.data to get the image binary. If parts also contains text, it is explanatory text returned by the model.

Error codes#

Status codeMeaning
400Invalid request parameters (missing responseModalities, unreachable inline_data, unsupported MIME type, mistakenly using camelCase field names, etc.)
401Authentication failed; check your API key
403Insufficient account balance; top up and try again
403The token does not have access to this model
429Too many requests; try again later
500Internal server error; try again later

Common errors:

  • extra_body.google.imageConfig is not supported, use extra_body.google.image_config instead: The field mistakenly uses camelCase; use the snake_case image_config instead.
  • imageConfig.aspectRatio is not supported: Same as above; use aspect_ratio instead.

Next steps

All docs
Relink Audio URLsSynchronously fetch ready-to-use audio URLs by Suno clip_id.Upsample Style TagsPolish and expand style tags and lyrics into a fuller style description.Get Style Inspiration SuggestionsGet random style or inspiration suggestions from the Suno upstream.Method 1: Create a Voice from an Existing SongCreate a vocal voice directly from a song clip already generated in this pool.Upload AudioImport user audio as a Suno-owned clip; returns an async upload task ID. With copyright=true the request switches to the copyright pipeline.Query Quota UsageUse an API key to query the remaining credits, used credits, and unlimited-quota status of the current key and its owning user.
On this page
OverviewAuthenticationCreate a taskRequest parameterscontentsparts (content blocks)generationConfigaspectratioRequest examplesResponse exampleError codesNext steps
API

API /v1beta/models/{model}:generateContent