Generate images synchronously with Google Gemini in the native Interactions API format. Supports text-to-image, image-to-image, multi-image composition, and multi-turn editing.
POST /v1/images/generations
Auth: {'type': 'bearer', 'description': 'Pass your API key in the `Authorization: Bearer sk-xxx` header.'}
**Gemini Banana (Nano Banana)** is a multimodal image generation model in the Google Gemini series, supporting: - **Text-to-image** (Text-to-Image) - **Image Editing** (Image-to-Image, input 1 reference images + text prompt) - **Multi-image composition** (Multi-Image Composition) — `gemini-3.1-flash-image-preview` supports up to **14 reference images** (10 object images + 4 character images) - **Multi-turn Editing** (server holds conversation history, iteratively modify via `previous_interaction_id` link) ## Invocation method Follows **Google Gemini Interactions API** (2026-05 new protocol, all fields snake_case) in body, returns synchronously. Client continues using our OpenAI-compatible path `https://api.router.ai/v1/images/generations`, no direct connection to Google required. ## Supported models | Model | Description | |---|---| | `gemini-3.1-flash-image-preview` | Nano Banana is the primary recommendation, 4 resolution (512px/1K/2K/4K), includes thinking mode, 14 aspect ratios | | `gemini-3-pro-image-preview` | Nano Banana Pro, featuring Thinking inference + high-fidelity text rendering | | `gemini-2.5-flash-image` | Nano Banana Classic (GA), high throughput, low latency, 1K per request | | `gemini-2.5-flash-image-preview` | Nano Banana Classic Preview (compatible with legacy SDK alias) | ## Output resolution configuration Specified via `response_format.image_size`: | image_size | Actual dimensions (including aspect_ratio=1:1) | Applicable models | |---|---|---| | `"512px"` | 512×512 (note **px suffix**) | Only `gemini-3.1-flash-image-preview` | | `"1K"` | 1024×1024 | All (recommended default) | | `"2K"` | 2048×2048 | gemini-3.1-flash / gemini-3-pro | | `"4K"` | 4096×4096 | gemini-3.1-flash / gemini-3-pro | **`aspect_ratio` values** (`gemini-3.1-flash` supports 14 types): `"1:1"` / `"16:9"` / `"9:16"` / `"3:2"` / `"2:3"` / `"4:3"` / `"3:4"` / `"5:4"` / `"4:5"` + `"1:4"` / `"4:1"` / `"1:8"` / `"8:1"` (only `gemini-3.1-flash`) When `response_format` is not provided, default is used (typically 1K 1:1). ## Field naming All REST API fields are **snake_case** (`response_format`, `mime_type`, `image_size`, `aspect_ratio`, `previous_interaction_id`, `generation_config`, `system_instruction`, etc.) ## Multi-turn editing chain (important) Server holds conversation history by default (`store: true`). When editing 1 images: 1. First POST retrieves `id` (`v1_xxx...`) 2. Second round includes the previous `id` in the `previous_interaction_id` field, re-POST (no need to resend images, server remembers) **Data retention**: paid tier 55 days, free tier 1 days. Reference: [Google Interactions Image Generation](https://ai.google.dev/gemini-api/docs/interactions/image-generation)
Authorization | string | required | Bearer sk-xxx |
Content-Type | string | required |
model | string | required | Model ID, see the list of supported models above |
input | string|array | required | Input content. A single string (`"a red apple"`) or an input block array (mix of text + image) |
type | string | Input block type (only in array form) | |
text | string | Text prompt (used when type=text) | |
mime_type | string | Image MIME type (used when type=image) | |
data | string | Base64-encoded image string (without data: URI prefix, used when type=image) | |
system_instruction | string | System prompt (optional, to control model behavior) | |
response_format | object | Output format (optional). Omitted defaults to 1K 1:1 | |
type | string | Response type, must be specified for image generation `image` | |
mime_type | string | Output image MIME type | |
image_size | string | Output resolution. `512px` only supports 3.1 Flash (note `px` suffix); other models support only 1K/2K/4K | |
aspect_ratio | string | Aspect ratio. 14 options (3.1 Flash supports all; other models support only 9 basic options) | |
generation_config | object | Generation parameters (optional) | |
thinking_level | string | Thinking intensity (gemini-3.1-flash / gemini-3-pro supported). Use `minimal` (default, fast) or `high` (high-quality reasoning) | |
temperature | number | Sampling temperature (0.0-2.0, affects generation diversity) | |
previous_interaction_id | string | Multi-turn linking. The `id` (`v1_xxx`) from the previous POST response; the server holds history, clients do not need to resend context | |
tools | array | Tool calling (optional). Note: `google_search` type tools will be removed by the gateway entry security filter layer; see the prompt for details | |
store | boolean | Whether the server holds conversation history. `true` (default, server memory) or `false` (client maintains history) |
200 — Generation succeeded. The response includes `id` for multi-turn interactions, `steps[]` with a model_output step containing the image, and `usage` broken down by modality.200 — Thinking-mode response. When generation_config.thinking_level is set, steps[] includes thought and model_output steps.200 — Generation failed. status=failed and steps[] is empty when upstream image safety filters block the request or the quota is insufficient.400 — Invalid request parameters (note: Interactions API error messages are concise and do not return fieldViolations)401 — Invalid or missing API Key503 — Upstream service temporarily unavailable# 1. 文生图 (T2I, input 单字符串, 默认 1K 1:1)
curl -X POST https://api.router.ai/v1/images/generations \
-H "Authorization: Bearer sk-xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-flash-image-preview",
"input": "Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme"
}'
# 2. T2I + 指定分辨率 2K 16:9 (response_format)
curl -X POST https://api.router.ai/v1/images/generations \
-H "Authorization: Bearer sk-xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-flash-image-preview",
"input": "a futuristic city at sunset, photorealistic, cinematic",
"response_format": {
"type": "image",
"mime_type": "image/jpeg",
"aspect_ratio": "16:9",
"image_size": "2K"
}
}'
# 3. I2I 图像编辑 (input 数组, text + image base64)
curl -X POST https://api.router.ai/v1/images/generations \
-H "Authorization: Bearer sk-xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-flash-image-preview",
"input": [
{"type": "text", "text": "Create a picture of my cat eating a nano-banana in a fancy restaurant under the Gemini constellation"},
{"type": "image", "mime_type": "image/jpeg", "data": "<BASE64_IMAGE_DATA>"}
]
}'
# 4. 多图合成 (Multi-Image Composition, 多张参考图)
curl -X POST https://api.router.ai/v1/images/generations \
-H "Authorization: Bearer sk-xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-flash-image-preview",
"input": [
{"type": "text", "text": "An office group photo of these people, they are making funny faces."},
{"type": "image", "mime_type": "image/png", "data": "<BASE64_DATA_IMG_1>"},
{"type": "image", "mime_type": "image/png", "data": "<BASE64_DATA_IMG_2>"},
{"type": "image", "mime_type": "image/png", "data": "<BASE64_DATA_IMG_3>"}
],
"response_format": {
"type": "image",
"mime_type": "image/jpeg",
"aspect_ratio": "5:4",
"image_size": "2K"
}
}'
# 5. 多轮编辑链 (上次 id 放入 previous_interaction_id, 无需重传图片)
curl -X POST https://api.router.ai/v1/images/generations \
-H "Authorization: Bearer sk-xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-flash-image-preview",
"input": "Update this infographic to be in Spanish. Do not change any other elements of the image.",
"previous_interaction_id": "v1_ChdEdGNPYXY3bkhNV00xZThQNjlyaXdBMBIXRHRjT2F2N25ITVdNMWU4UDY5cml3QTA",
"response_format": {
"type": "image",
"mime_type": "image/jpeg",
"aspect_ratio": "16:9",
"image_size": "2K"
}
}'
# 6. Thinking 模式 (gemini-3.1-flash / gemini-3-pro 支持; minimal 默认 / high 推理强度)
curl -X POST https://api.router.ai/v1/images/generations \
-H "Authorization: Bearer sk-xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3-pro-image-preview",
"input": "draw a step-by-step guide on how to bake a banana bread",
"generation_config": {
"thinking_level": "high"
},
"response_format": {
"type": "image",
"image_size": "1K"
}
}'