Skip to content

Nano Banana (Gemini Image Models)

Gemini image models on sale: gemini-3.1-flash-image-preview, gemini-3-pro-image-preview, and gemini-3.1-flash-lite-image. They are image-generation models served by Gemini channels, and there are two ways to reach them (check supported_endpoint_types in Models for the exact list on each model):

PathEndpointRequest body you send
OpenAI image formatPOST /v1/images/generationsOpenAI image JSON, described on OpenAI Image Format
Native GeminiPOST /v1beta/models/{model}:generateContentGemini contents + generationConfig

Use the native path when you already speak the Gemini protocol (Google GenAI SDK) and need full control over responseModalities and imageConfig; use /v1/images/generations when your client only speaks the OpenAI image API.

The envelope, authentication, and error body are the same as OpenAI Image Format. RouteAPI converts your image request into a Gemini generateContent call.

FieldTypeRequiredDescription
modelstringYesGemini image model ID such as gemini-3.1-flash-image-preview
promptstringYesSent as a single text part in a user turn
sizestringNoMapped to generationConfig.imageConfig.aspectRatio (see the table below)
nintegerNoValues greater than 1 are sent as generationConfig.candidateCount; 1 or omitted sends nothing
quality, response_format, style, user, watermark—NoNot converted on this path; they are ignored by the Gemini adaptor

RouteAPI fills responseModalities with ["TEXT", "IMAGE"] itself, so you do not pass it through this endpoint. Safety settings are applied from the platform’s Gemini settings.

Only these exact size values map to an aspect ratio:

sizeaspectRatio
256x256, 512x512, 1024x10241:1
1536x10243:2
1024x15362:3
1024x17929:16
1792x102416:9

A value that already contains : is passed through as an aspect ratio. Anything else (for example 2K or auto) sends no imageConfig at all, and the upstream default applies. Pixel dimensions are not requested on this path — the ratio is the only size control.

Terminal window
curl https://api.routeapi.ai/v1/images/generations \
-H "Authorization: Bearer $ROUTEAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-flash-image-preview",
"prompt": "A nano banana wearing sunglasses, studio product shot",
"size": "1536x1024"
}'

The response is converted to the OpenAI image object; only inline image parts survive, and any text the model returns is dropped.

{
"created": 1740000000,
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSUhEUgAA..."
}
]
}

URLs are not produced on this path — always read data[].b64_json. If the response contains no image part, the request fails with 500; if Gemini blocks the prompt, it fails with 400 and the block reason is recorded against the request.

POST /v1beta/models/{model}:generateContent
POST /v1beta/models/{model}:streamGenerateContent?alt=sse

Example:

Terminal window
curl https://api.routeapi.ai/v1beta/models/gemini-3-pro-image-preview:generateContent \
-H "x-goog-api-key: $ROUTEAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{ "role": "user", "parts": [{ "text": "Draw a cat astronaut on the moon" }] }
],
"generationConfig": {
"responseModalities": ["TEXT", "IMAGE"],
"imageConfig": { "aspectRatio": "16:9", "imageSize": "2K" }
}
}'
FieldTypeRequiredDescription
contentsarrayYesGemini conversation content; at least one entry. Roles are user and model
generationConfig.responseModalitiesarray of stringYes in practiceMust include IMAGE, otherwise the model answers with text only
generationConfig.imageConfigobjectNoImage options, passed through to Gemini. aspectRatio such as 1:1, 3:2, 16:9; imageSize such as 1K, 2K, 4K. Accepted values depend on the model
generationConfig.candidateCountintegerNoNumber of candidates; not supported by every image model
safetySettingsarrayNoGemini safety settings, forwarded as-is
systemInstructionobjectNoSystem instruction; the snake_case system_instruction is accepted too

generationConfig accepts both camelCase and snake_case spellings of its fields (for example responseModalities / response_modalities and imageConfig / image_config); if both are present, snake_case wins. imageConfig and its contents are passed through without validation, so an unsupported imageSize is reported by Gemini, not by RouteAPI.

To edit or reference an image, add an inline image part next to the text:

{
"contents": [
{
"role": "user",
"parts": [
{ "text": "Repaint this photo as a watercolor illustration" },
{
"inlineData": {
"mimeType": "image/png",
"data": "iVBORw0KGgoAAAANSUhEUgAA..."
}
}
]
}
],
"generationConfig": { "responseModalities": ["TEXT", "IMAGE"] }
}

inlineData carries Base64 image bytes; it is forwarded to Gemini unchanged. For files already uploaded to Google, the native fileData.fileUri part is also part of the forwarded request shape. If your client speaks the OpenAI chat format instead, image_url content parts are downloaded server-side and converted to inline parts before reaching Gemini.

Streaming is selected by the ?alt=sse query parameter, not by the action name: with it, the upstream action becomes streamGenerateContent and the response is a stream of Gemini server-sent events. Each chunk has the standard candidates[].content.parts structure. Use it when you want the image to arrive incrementally; otherwise :generateContent returns the whole response in one body.

The native path returns Gemini’s own response shape unchanged:

{
"candidates": [
{
"content": {
"role": "model",
"parts": [
{ "text": "Here is the image." },
{
"inlineData": {
"mimeType": "image/png",
"data": "iVBORw0KGgoAAAANSUhEUgAA..."
}
}
]
},
"finishReason": "STOP"
}
],
"usageMetadata": {
"promptTokenCount": 12,
"candidatesTokenCount": 1120,
"totalTokenCount": 1132
}
}

Read the image from parts[].inlineData; text parts usually accompany it. When Gemini blocks the request, promptFeedback.blockReason is set and candidates is empty.

Gemini image models are billed by tokens: generated images count as output tokens at the output price, and the prompt and reference images count as input tokens. See Model Pricing and the model detail page for the current rates.

  • OpenAI Image Format — the shared /v1/images envelope and edit behavior.
  • Seedream — ByteDance Seedream sizes and edit semantics.
  • Models — find image models and confirm image-generation support.
  • Model Pricing — token vs per-image billing.