Images
Nano Banana 2.1 Image Generation & Editing
Updated
Download MarkdownChoose a request format
The public model ID is gemini-nano-banana-2.1-c. All three formats use the same model. Keep your existing Images or Chat request structure, or choose Gemini generateContent for native Base64 output.
Use https://api.unifyllm.top and Authorization: Bearer <YOUR_API_KEY>.
| Format | Endpoint | Image output | Use case |
|---|---|---|---|
| Gemini | /v1beta/models/{model}:generateContent | inlineData Base64 | Native content and image bytes |
| Images | /v1/images/generations | data[0].url | Existing Images generation clients |
| Images edits | /v1/images/edits | data[0].url | Edit with uploads, public URLs, or data URLs |
| Chat | /v1/chat/completions | Markdown image URL, JSON or SSE | Single-turn images in chat clients |
Images: generation and editing
- Generation parameters and cURL / JavaScript / Python examples: send model, prompt, and size as JSON. Returns one image URL.
- Edit with file upload: use image in multipart; repeat image[] for ordered references. Let the HTTP client set the boundary.
- Edit with JSON image references: use image for one reference or images for several. Public URLs and image data URLs are accepted. Do not combine conflicting reference fields.
1{2 "model": "gemini-nano-banana-2.1-c",3 "prompt": "A green ceramic cup on a white background. No text.",4 "size": "1920x1080"5}size and actual image dimensions
Images and Chat derive resolution and aspect ratio from size. Width and height must be positive integers. A long edge up to 1536 requests 1K; a larger edge requests 2K, with the nearest supported aspect ratio.
- size does not accept "1K", "2K", "4K", or "16:9". Native imageSize uses 1K / 2K instead.
- 4096x2304 still requests 2K, never 4K. A disabled tier returns an error rather than a silent downgrade.
- size selects resolution and composition. Actual pixels can differ: a public gateway test requested 1920x1080 and received 2752×1536, without resizing or cropping.
| size | Tier | Aspect ratio |
|---|---|---|
| auto | Default 1K | 1:1 for text; upstream chooses with references |
| 1024x1024 | 1K | 1:1 |
| 1536x1024 | 1K | 3:2 |
| 1920x1080 | 2K | 16:9 |
| 1600x1000 | 2K | 3:2, nearest |
| 4096x2304 | 2K | 16:9 |
Parameters that have no effect
Images and Chat accept the following fields for client compatibility, but ignore their values and do not forward them upstream.
| Field | Actual behavior |
|---|---|
| n | One valid image per request |
| response_format | Returns an image URL even for b64_json |
| quality / input_fidelity | Not used as generation controls |
| mask | No mask-based editing; not treated as a reference |
| background | Does not guarantee transparency |
| output_format / output_compression | Preserves the generated format without requested transcoding or compression |
Gemini native: Base64 image output
Native parameters, request examples, and response structure
- contents contains exactly one current user message. Add inlineData or public fileData image references in parts.
- responseModalities must include IMAGE. imageSize supports 1K and 2K, not explicit 4K.
- Inspect candidates[].content.parts[], skip thought=true parts, then decode inlineData.data using its mimeType.
- Opaque fields such as thoughtSignature remain unchanged. This route still does not restore multi-turn state. Only generateContent is supported, not streamGenerateContent.
1{2 "contents": [3 {4 "role": "user",5 "parts": [6 {7 "text": "A red ceramic teapot on a white background."8 }9 ]10 }11 ],12 "generationConfig": {13 "responseModalities": [14 "IMAGE"15 ],16 "imageConfig": {17 "imageSize": "1K",18 "aspectRatio": "1:1"19 }20 }21}Chat: current-turn input only
Only the last user message in messages is read. Top-level prompt and other history are not included. To edit a previous result, explicitly put its URL or data URL in the current image_url. Replace the example URL with your own public image.
Chat parameters, JSON output, and SSE examples
- stream=false: read the Markdown image URL from choices[0].message.content.
- stream=true: chat.completion.chunk starts after successful generation and storage, followed by finish_reason=stop and data: [DONE]. There are no waiting-period progress events or Base64 chunks.
- Network chunks can split SSE events. Reassemble complete data: events instead of calling response.json() on the stream.
1{2 "model": "gemini-nano-banana-2.1-c",3 "messages": [4 {5 "role": "user",6 "content": [7 {8 "type": "text",9 "text": "Change the cup to green; preserve the white background."10 },11 {12 "type": "image_url",13 "image_url": {14 "url": "https://example.com/reference.jpg"15 }16 }17 ]18 }19 ],20 "size": "auto",21 "stream": false22}References, timeouts, and result storage
- The model defaults to up to 14 references and 40 MB of original bytes combined; account or platform limits may be tighter. Prompt text is limited to 12,000 characters.
- Use file uploads, public URLs, or image data URLs. Private addresses and account-scoped Files API file_id are unsupported. Images must be readable supported formats such as PNG/JPEG/WebP.
- Base64 increases size. The default whole-request limit is 64 MB, so original file size alone is not sufficient.
- Generation can take tens of seconds or longer. Configure suitable connection and read timeouts. A client timeout does not prove generation failed; do not blindly resubmit paid requests.
- Download the complete returned URL without an API key. Preserve id, sig, and the query string. Cleanup or signature changes can invalidate old links, so save the image to your own storage promptly.
Verified coverage and troubleshooting
The integration task on 2026-11-27 completed the following real requests through api.unifyllm.top and downloaded and decoded the resulting images. This records that test scope, not a latency or capability guarantee.
- 400: check size, resolution tier, aspect ratio, references, and current prompt.
- 401: check the key and model access. 413: reduce the encoded request size. 429: reduce concurrency and follow Retry-After.
- 500 can indicate upstream rejection, timeout, no valid image, or storage failure. Keep the time, request ID, and error for support.
- Missing usage is not a zero-cost statement. Check the model, usage, and charge in the console. Retry the same image URL first if download fails.
| Scenario | Verified result |
|---|---|
| Native 1K generation | HTTP 200 / Base64 / 1024×1024 |
| Images generation, 1920x1080 | HTTP 200 / URL / 2752×1536 |
| Single-reference multipart edit | HTTP 200 / URL / 1024×1024 |
| Chat SSE generation | HTTP 200 / URL / [DONE] / 1024×1024 |