GuideImage GenerationNano banana
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.
OpenAI Chat Format (OpenAI Chat Format / Gemini Image)
This endpoint wraps the request in the standard OpenAI Chat Completions structure, letting you trigger Gemini's image generation capability through chat instructions.
📌 Basics
- Endpoint:
POST /v1/chat/completions - Authentication:
Bearer Token - Content type:
application/json
📥 Request Parameters (Request Body)
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Model name, e.g. gemini-3-pro-image-preview. |
| messages | array | Yes | Chat context list. |
| └─ role | string | Yes | Role (user, assistant, system). |
| └─ content | string | Yes | Prompt content, e.g. "draw a cat". |
| stream | boolean | Yes | Whether to enable streaming output (recommended false for image generation). |
| extra_body | object | No | Extension parameters (for Gemini-specific features). |
object | No | Google official configuration extension. | |
| └─ └─ image_config | object | No | Image generation configuration. |
| └─ └─ └─ aspect_ratio | string | No | Aspect ratio, e.g. 16:9, 1:1. |
| └─ └─ └─ image_size | string | No | Quality level, e.g. 2K, 4K. |
📤 Response
Status code: 200 OK
| Field | Type | Description |
|---|---|---|
| id | string | Unique request ID. |
| object | string | Object type, always chat.completion. |
| choices | array | List of generation results. |
| └─ message | object | Contains role and content (images are usually returned as Markdown Base64). |
| └─ finish_reason | string | Finish reason, e.g. stop. |
| usage | object | Token usage statistics. |
📝 Request Example
{
"model": "gemini-3-pro-image-preview",
"stream": false,
"messages": [
{
"role": "user",
"content": "draw a cat"
}
],
"extra_body": {
"google": {
"image_config": {
"aspect_ratio": "16:9",
"image_size": "2K"
}
}
}
}📝 Response Example
{
"id": "chatcmpl-20251211...",
"model": "gemini-3-pro-image-preview",
"object": "chat.completion",
"created": 1765440499,
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": ""
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 4,
"completion_tokens": 1359,
"total_tokens": 1363
}
}💡 Developer Tips
- Extracting the image: The image in the response is usually embedded in
contentas Markdown,. Clients should extract the Base64 part for display. - Parameter compatibility:
extra_bodyis the standard OpenAI SDK extension field for passing configuration specific to downstream models; it does not break the standard OpenAI protocol structure. - Mock testing: For local debugging you can use the mock address
http://127.0.0.1:4523/mock/7707339.
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.
Edit Images
OpenAI image edit endpoint guide: inpaint or extend an image with a prompt and mask, covering form-data parameters, PNG alpha requirements and a cURL example.