Nano Banana 2.1 — Gemini generateContent
Overview
Use gemini-nano-banana-2.1 to generate an image from text or edit up to 14 reference images with the Gemini request format. Each synchronous request returns one image as Base64 in an inlineData response part.
Endpoint
POST /v1beta/models/gemini-nano-banana-2.1:generateContent
The base URL is https://api.uniall.ai. The main examples use Google's official model ID gemini-nano-banana-2.1. The compatible URL /v1beta/models/nano-banana-2.1:generateContent also remains available.
Authentication
Use your UniAI user API key:
x-goog-api-key: <UNIAI_API_KEY>
Content-Type: application/json
Request Parameters
Send one user entry in contents. Use camelCase field names.
| Parameter | Type | Required | Description |
|---|---|---|---|
contents | array | Yes | Exactly one user-content entry. |
contents[].role | string | Yes | user. |
contents[].parts[].text | string | Yes | Non-empty generation or editing instruction. |
contents[].parts[].inlineData | object | Conditional | Reference image for editing; add a part for each image, up to 14. |
contents[].parts[].inlineData.mimeType | string | Conditional | image/png, image/jpeg, or image/webp. |
contents[].parts[].inlineData.data | string | Conditional | Raw Base64 image bytes without a Data URL prefix. |
generationConfig.imageConfig.imageSize | string | No | 1K, 2K, or 4K; defaults to 1K. |
generationConfig.imageConfig.aspectRatio | string | No | One of the 14 ratios below. If omitted, the ratio follows the reference image or generated content. |
generationConfig.thinkingConfig.thinkingLevel | string | No | MINIMAL, MEDIUM, or HIGH; defaults to MEDIUM. |
generationConfig.responseModalities | string[] | No | Defaults to ["IMAGE"]; also accepts ["TEXT", "IMAGE"]. Text appears only if final text is actually generated. ["TEXT"] alone is unsupported. |
generationConfig.candidateCount | integer | No | Only 1 is accepted; each request returns one image. |
Resolution And Reference Images
Supported aspect ratios:
1:1 1:4 1:8 2:3 3:2 3:4 4:1
4:3 4:5 5:4 8:1 9:16 16:9 21:9
Resolution is a tier, not a fixed longest-edge pixel count. For example, a non-square 1K result can be 1376 × 768. 0.5K, 512, and 8K are unsupported.
Editing requires 1 to 14 PNG, JPEG, or WebP reference images. Keep them in parts in the order described by your prompt. Order and duplicate entries are preserved; duplicates count toward the limit. Set mimeType to the actual image type and put only raw Base64 in data.
Request Examples
Text To Image
curl -X POST "https://api.uniall.ai/v1beta/models/gemini-nano-banana-2.1:generateContent" \
-H "x-goog-api-key: <UNIAI_API_KEY>" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{
"role": "user",
"parts": [
{"text": "Create a spring latte poster with a cream background and clear typography"}
]
}
],
"generationConfig": {
"responseModalities": ["IMAGE"],
"imageConfig": {"imageSize": "2K", "aspectRatio": "16:9"},
"thinkingConfig": {"thinkingLevel": "HIGH"},
"candidateCount": 1
}
}'
Image Editing
Replace <BASE64_IMAGE_BYTES> with the reference image's raw Base64 bytes before sending this request.
curl -X POST "https://api.uniall.ai/v1beta/models/gemini-nano-banana-2.1:generateContent" \
-H "x-goog-api-key: <UNIAI_API_KEY>" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{
"role": "user",
"parts": [
{"text": "Keep the cup shape and color; replace the background with a bright cafe"},
{
"inlineData": {
"mimeType": "image/png",
"data": "<BASE64_IMAGE_BYTES>"
}
}
]
}
],
"generationConfig": {
"responseModalities": ["IMAGE"],
"imageConfig": {"imageSize": "2K", "aspectRatio": "4:5"},
"thinkingConfig": {"thinkingLevel": "MEDIUM"},
"candidateCount": 1
}
}'
Add another inlineData part for each additional reference image. To make a later edit, use the previous output image as a reference in a new independent request.
Response Example
{
"candidates": [
{
"content": {
"role": "model",
"parts": [
{
"inlineData": {
"mimeType": "image/png",
"data": "<BASE64_IMAGE_BYTES>"
}
}
]
},
"finishReason": "STOP"
}
]
}
| Response field | Description |
|---|---|
candidates[].content.parts[].inlineData | Final image. Base64-decode data and save it according to the returned mimeType. |
candidates[].content.parts[].text | Optional final text when requesting ["TEXT", "IMAGE"] and final text is actually generated. Text is not guaranteed. |
usageMetadata | May be present when actual usage metadata is available; do not require it to read the image. |
Find the part containing inlineData rather than assuming the first part is an image. The response is synchronous and has no task ID or polling step. A client timeout does not confirm that generation stopped; avoid automatically submitting the request again.
Capability Limits And Common Errors
- Search is unavailable. Omit
tools,enable_web_search, andenable_image_search; supplying them is rejected even when a search flag isfalse. - Only a single user-content entry with text and image references is supported. Multi-turn history, thinking signatures or summaries, video/PDF input, Files, Interactions, and Batch APIs are unavailable in this image integration.
quality, custom pixelsizeorcustom_size, masks, transparent backgrounds,seed, and streaming output are unsupported.- Do not use
/v1/chat/completionsor/v1/images/tasksfor Nano Banana 2.1. - An editing request without a reference image, more than 14 references, a Data URL prefix inside
inlineData.data, an unsupported image size, text-only output, or acandidateCountother than1is invalid. - Thinking control is available only for the new 2.1 integration. It is not enabled for
nano-banana-2,nano-banana-pro, or fixed-resolution compatibility models.