# Gemini Native Image Generation

Use gemini-nano-banana-2.1-c with single-turn generateContent. Returns native Base64 images with 1K/2K resolution tiers.

- Source: https://www.unifyllm.com/docs/api-reference/nano-banana-image/
- Language: en
- Updated: 2026-11-27

## Endpoint

```http
POST https://api.unifyllm.top/v1beta/models/{model}:generateContent
```

Use the authentication and headers shown in the request examples. Content-Type: application/json

[Integration guide](https://www.unifyllm.com/docs/gemini-image/)

## Model and response format

These are UnifyLLM compatibility rules for gemini-nano-banana-2.1-c. Use https://api.unifyllm.top with the endpoint paths shown below. Check the corresponding documentation for other image models.

- Native output uses candidates[].content.parts[].inlineData Base64. Thought parts and opaque signatures are preserved; skip thought=true parts when extracting the image.

- One upstream generation submission per request; paid POST requests are not automatically retried.

- Default reference limits are 14 images and 40 MB of original bytes combined; platform or account limits may be tighter. Supported PNG/JPEG/WebP images must be readable.

## Resolution and aspect ratio

Dimensions select a resolution tier and composition; exact pixels are not promised. The public gateway test on 2026-11-27 requested 1920x1080 and received 2752×1536. The result is not resized or cropped.

| Input | Example | Mapped result |
| --- | --- | --- |
| imageSize | 1K / 2K | Enabled tiers only; no 4K |
| aspectRatio | 1:1, 2:3, 3:2, 4:3, 3:4, 16:9, 9:16 | Must be enabled for the model |

## Single-turn input and reference limits

- Only generateContent is supported, not streamGenerateContent. contents must contain one current user content; multi-turn state is not restored.

- URL references must be publicly accessible; private addresses are rejected. Replace example.com URLs and Base64 placeholders. Do not put API keys in image URLs.

- responseModalities must include IMAGE. inlineData/inline_data aliases are accepted; conflicting aliases are rejected.

- The default whole-request limit is 64 MB including Base64 and JSON overhead. The original-image limit is not the final encoded request size.

## Usage, errors, and saving results

- usage / usageMetadata is returned only when provided upstream. Images use input_tokens/output_tokens; Chat uses prompt_tokens/completion_tokens. Missing usage is not a zero-cost statement.

- 400 usually means invalid parameters or model capabilities; 401 is authentication; 413 is request size; 429 is capacity or rate limiting. Upstream rejection, timeout, no valid image, or storage failure may return 500. Keep the request ID and error for diagnosis.

- Generation can take time. Chat stream=true starts only after successful generation and storage, without waiting-period progress. Read SSE through data: [DONE]; do not parse the entire stream as one JSON object.

- URLs are not permanent archives: cleanup or signature changes can invalidate them. Download promptly and preserve id, sig, and the original query string.

## Parameters

| Field | Location | Type | Required | Description | Allowed values | Example |
| --- | --- | --- | --- | --- | --- | --- |
| model | path | string | yes | Public model ID. The example uses gemini-nano-banana-2.1-c; availability depends on your key. |  | gemini-nano-banana-2.1-c |
| contents | body | array | yes | Exactly one current user content; role may be omitted. Include non-empty text and optional reference images in parts. Multi-turn history is not supported. |  |  |
| contents[].parts[].inlineData | body | object | no | Base64 image with mimeType and raw Base64 data, without a data URL prefix. inline_data / mime_type are accepted. |  |  |
| contents[].parts[].fileData | body | object | no | A public HTTP(S) or image data URL in fileUri. Account-scoped Files API file_id is unsupported. file_data / file_uri are accepted. |  |  |
| generationConfig.responseModalities | body | array | no | Defaults to ["IMAGE"]. ["TEXT","IMAGE"] is allowed; IMAGE is required. |  |  |
| generationConfig.imageConfig.imageSize | body | string | no | Only model-enabled 1K and 2K are supported; default 1K. Explicit 4K is rejected. | 1K, 2K | 1K |
| generationConfig.imageConfig.aspectRatio | body | string | no | Supported ratios are listed below. When omitted, text-to-image uses the default ratio; reference editing lets the upstream choose. | 1:1, 2:3, 3:2, 4:3, 3:4, 16:9, 9:16 |  |
| generationConfig.candidateCount | body | integer | no | Forced to 1. Other supported native generationConfig properties are preserved. Do not send conflicting camelCase and snake_case objects. |  |  |
| systemInstruction / safetySettings | body | object / array | no | Native fields are preserved; their effect depends on the model. They do not restore chat history. |  |  |

## Native text to image

```json
{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "A red ceramic teapot on a white background. No text."
        }
      ]
    }
  ],
  "generationConfig": {
    "responseModalities": [
      "IMAGE"
    ],
    "imageConfig": {
      "imageSize": "1K",
      "aspectRatio": "1:1"
    }
  }
}
```

### cURL

```bash
curl --fail-with-body --max-time 300 'https://api.unifyllm.top/v1beta/models/gemini-nano-banana-2.1-c:generateContent' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "A red ceramic teapot on a white background. No text."
        }
      ]
    }
  ],
  "generationConfig": {
    "responseModalities": [
      "IMAGE"
    ],
    "imageConfig": {
      "imageSize": "1K",
      "aspectRatio": "1:1"
    }
  }
}'
```

### JavaScript

```javascript
const response = await fetch("https://api.unifyllm.top/v1beta/models/gemini-nano-banana-2.1-c:generateContent", {
  method: "POST",
  headers: {
  "Authorization": "Bearer <YOUR_API_KEY>",
  "Content-Type": "application/json"
},
  body: JSON.stringify({
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "A red ceramic teapot on a white background. No text."
        }
      ]
    }
  ],
  "generationConfig": {
    "responseModalities": [
      "IMAGE"
    ],
    "imageConfig": {
      "imageSize": "1K",
      "aspectRatio": "1:1"
    }
  }
}),
  signal: AbortSignal.timeout(300_000),
});
if (!response.ok) throw new Error(await response.text());
const data = await response.json();
console.log(data);
// Generated image: skip thought=true parts, then decode inlineData.data.
```

### Python

```python
import json
import requests

payload = json.loads("{\n  \"contents\": [\n    {\n      \"role\": \"user\",\n      \"parts\": [\n        {\n          \"text\": \"A red ceramic teapot on a white background. No text.\"\n        }\n      ]\n    }\n  ],\n  \"generationConfig\": {\n    \"responseModalities\": [\n      \"IMAGE\"\n    ],\n    \"imageConfig\": {\n      \"imageSize\": \"1K\",\n      \"aspectRatio\": \"1:1\"\n    }\n  }\n}")
response = requests.post(
    "https://api.unifyllm.top/v1beta/models/gemini-nano-banana-2.1-c:generateContent",
    headers={"Authorization": "Bearer <YOUR_API_KEY>"},
    json=payload,
    timeout=(10, 300),
)
response.raise_for_status()
print(response.json())
```

## Native reference image

```json
{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "Change the teapot to blue; preserve its shape and white background."
        },
        {
          "inlineData": {
            "mimeType": "image/jpeg",
            "data": "<BASE64_IMAGE_BYTES>"
          }
        }
      ]
    }
  ],
  "generationConfig": {
    "responseModalities": [
      "IMAGE"
    ],
    "imageConfig": {
      "imageSize": "1K"
    }
  }
}
```

### cURL

```bash
curl --fail-with-body --max-time 300 'https://api.unifyllm.top/v1beta/models/gemini-nano-banana-2.1-c:generateContent' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "Change the teapot to blue; preserve its shape and white background."
        },
        {
          "inlineData": {
            "mimeType": "image/jpeg",
            "data": "<BASE64_IMAGE_BYTES>"
          }
        }
      ]
    }
  ],
  "generationConfig": {
    "responseModalities": [
      "IMAGE"
    ],
    "imageConfig": {
      "imageSize": "1K"
    }
  }
}'
```

### JavaScript

```javascript
const response = await fetch("https://api.unifyllm.top/v1beta/models/gemini-nano-banana-2.1-c:generateContent", {
  method: "POST",
  headers: {
  "Authorization": "Bearer <YOUR_API_KEY>",
  "Content-Type": "application/json"
},
  body: JSON.stringify({
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "Change the teapot to blue; preserve its shape and white background."
        },
        {
          "inlineData": {
            "mimeType": "image/jpeg",
            "data": "<BASE64_IMAGE_BYTES>"
          }
        }
      ]
    }
  ],
  "generationConfig": {
    "responseModalities": [
      "IMAGE"
    ],
    "imageConfig": {
      "imageSize": "1K"
    }
  }
}),
  signal: AbortSignal.timeout(300_000),
});
if (!response.ok) throw new Error(await response.text());
const data = await response.json();
console.log(data);
// Generated image: skip thought=true parts, then decode inlineData.data.
```

### Python

```python
import json
import requests

payload = json.loads("{\n  \"contents\": [\n    {\n      \"role\": \"user\",\n      \"parts\": [\n        {\n          \"text\": \"Change the teapot to blue; preserve its shape and white background.\"\n        },\n        {\n          \"inlineData\": {\n            \"mimeType\": \"image/jpeg\",\n            \"data\": \"<BASE64_IMAGE_BYTES>\"\n          }\n        }\n      ]\n    }\n  ],\n  \"generationConfig\": {\n    \"responseModalities\": [\n      \"IMAGE\"\n    ],\n    \"imageConfig\": {\n      \"imageSize\": \"1K\"\n    }\n  }\n}")
response = requests.post(
    "https://api.unifyllm.top/v1beta/models/gemini-nano-banana-2.1-c:generateContent",
    headers={"Authorization": "Bearer <YOUR_API_KEY>"},
    json=payload,
    timeout=(10, 300),
)
response.raise_for_status()
print(response.json())
```

## Response examples

### Native Base64 result — HTTP 200

```json
{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [
          {
            "inlineData": {
              "mimeType": "image/jpeg",
              "data": "<BASE64_GENERATED_IMAGE>"
            }
          }
        ]
      },
      "finishReason": "STOP",
      "index": 0
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 28,
    "candidatesTokenCount": 1120,
    "totalTokenCount": 1148
  },
  "modelVersion": "gemini-nano-banana-2.1-c"
}
```

## Related endpoints

- [Gemini Image — Images API](https://www.unifyllm.com/docs/api-reference/gemini-image-create/)
- [Gemini Image Edit — Upload](https://www.unifyllm.com/docs/api-reference/gemini-image-edit/)
- [Gemini Image — Chat Format](https://www.unifyllm.com/docs/api-reference/gemini-image-chat/)
