GuideImage GenerationNano banana
Gemini Chat Format
Call Nano Banana image models via Gemini's native generateContent endpoint: request fields, aspect ratio and size config, chain-of-thought output, examples.
Gemini Content Generation (Gemini Native Format)
This endpoint calls Gemini native multimodal models (such as the Nano Banana series). It supports text generation, image generation, and returning the model's chain-of-thought process.
📌 Basics
- Endpoint:
POST /v1beta/models/{model}:generateContent/ - Path parameters:
model: model name, e.g.gemini-3-pro-image-preview.
- Authentication:
Bearer Token - Content type:
application/json
📥 Request Parameters (Request Body)
| Parameter | Type | Required | Description |
|---|---|---|---|
| contents | array | Yes | List of conversation contents. |
| └─ role | string | No | Role (e.g. user). |
| └─ parts | array | Yes | List of message parts. |
| └─ └─ text | string | Yes | Prompt or text input. |
| generationConfig | object | Yes | Generation configuration object. |
| └─ responseModalities | array | Yes | Response modalities. Allowed values: TEXT, IMAGE. |
| └─ thinkingConfig | object | No | Thinking configuration. |
| └─ └─ includeThoughts | boolean | No | Whether to return the model's reasoning (chain of thought) during generation. |
| └─ imageConfig | object | Yes | Image generation configuration. |
| └─ └─ aspectRatio | string | Yes | Aspect ratio, e.g. 16:9, 1:1, 4:3. |
| └─ └─ imageSize | string | Yes | Image quality/size, e.g. 4K, 1024x1024. |
📤 Response
Status code: 200 OK
| Field | Type | Description |
|---|---|---|
| candidates | array | List of generated candidates. |
| └─ content | object | Contains the generated role and the parts (may include text or image data). |
| └─ finishReason | string | Reason generation stopped (e.g. STOP). |
| └─ safetyRatings | array | Safety evaluation ratings. |
| usageMetadata | object | Token usage metadata (Prompt, Candidates, Total). |
📝 Request Example (Generate an Image)
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "draw a futuristic city at sunset"
}
]
}
],
"generationConfig": {
"responseModalities": ["TEXT", "IMAGE"],
"imageConfig": {
"aspectRatio": "16:9",
"imageSize": "4K"
},
"thinkingConfig": {
"includeThoughts": true
}
}
}💡 Developer Tips
- Chain-of-thought output: By setting
includeThoughts: true, you can see how the model interprets your request and "plans" before drawing — very useful when debugging complex prompts. - Multimodal responses: When
responseModalitiesincludes bothTEXTandIMAGE, the model first returns descriptive text and then generates the corresponding image. - Model version: Make sure the
{model}parameter in the path matches the API permissions you currently have.
gpt-image-2 Model Tutorial
Tutorial for calling gpt-image-2 on AnyRouter: text-to-image and image edit endpoints, request parameters, cURL and Python examples, and response format.
OpenAI Chat Format
Use the OpenAI Chat Completions format to trigger Gemini image generation, with extra_body config for aspect ratio and size, and tips for parsing Base64 images.