Gemini image models (Nano Banana) support text-to-image, image editing, and multi-turn refinement. Call them through the native Gemini API or the OpenAI Chat Completions format. Examples on this page use gemini-3.1-flash-image; for other Gemini image models, see the Model Hub.| Method | Endpoint | Where the image is returned |
|---|
| Native Gemini (recommended) | POST /v1beta/models/{model}:generateContent | parts[].inlineData.data (Base64) |
| OpenAI-compatible | POST /v1/chat/completions | A Markdown image (data URL) in message.content |
Text-to-image#
Response (Base64 truncated):{
"candidates": [
{
"content": {
"role": "model",
"parts": [
{
"inlineData": { "mimeType": "image/jpeg", "data": "/9j/4AAQSkZJRgABAQEBLAEsAAD…" },
"thoughtSignature": "…"
}
]
},
"finishReason": "STOP"
}
],
"usageMetadata": {
"candidatesTokensDetails": [{ "modality": "IMAGE", "tokenCount": 1120 }]
},
"modelVersion": "gemini-3.1-flash-image"
}
Generation settings#
| Field | Description |
|---|
responseModalities | ["TEXT", "IMAGE"] returns text and images; ["IMAGE"] returns images only |
imageConfig.aspectRatio | Aspect ratio, for example 1:1, 16:9, 9:16, 4:3, 3:4 |
imageConfig.imageSize | Resolution tier, for example 1K (in our tests, 16:9 + 1K produced 1376×768) |
Edit an image#
Send the source image in inlineData together with the edit instruction:If you already have OpenAI code, call the model through Chat Completions. The image is returned as Markdown in content: .Response (Base64 truncated):{
"model": "gemini-3.1-flash-image",
"object": "chat.completion",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "" },
"finish_reason": "stop"
}
],
"usage": { "completion_tokens_details": { "image_tokens": 1120 } }
}
In the OpenAI-compatible format, put requirements such as aspect ratio in the prompt (for example "with a 16:9 aspect ratio"). For precise control over aspect ratio and resolution, use imageConfig in the native Gemini format.
FAQ#