# Gemini Image — Chat Format

Use Chat Completions with gemini-nano-banana-2.1-c for single-turn image generation and editing, with JSON or result-only SSE output.

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

## Endpoint

```http
POST https://api.unifyllm.top/v1/chat/completions
```

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.

- Returns one stored image URL. Download that URL without an API key. A download failure is not a reason to resubmit generation.

- 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 |
| --- | --- | --- |
| size | auto | Default 1K; text-only defaults to 1:1, references let upstream choose |
| size | 1536x1024 | 1K / 3:2 |
| size | 1920x1080 | 2K / 16:9 |
| size | 1600x1000 | 2K / 3:2 (nearest) |
| size | 4096x2304 | Still 2K / 16:9, not 4K |

## Single-turn input and reference limits

- Images generation is text-only; use edits for references. Chat uses only the last user message and does not restore previous images.

- 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.

- n, response_format, quality, mask, input_fidelity, background, output_format, and output_compression are ignored. They do not enable multiple images, Base64, transparency, or format conversion.

- 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 | body | 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 |
| messages | body | array | yes | Only the last role=user message is used; other history and top-level prompt are ignored. content accepts text or text/image_url parts; current text is limited to 12,000 characters. |  |  |
| messages[].content[].image_url | body | object | no | Explicit reference image {"url":"public URL or data URL"} in the current user message. Images in previous replies are not restored. |  |  |
| size | body | string | no | auto or positive WIDTHxHEIGHT. Long edge ≤1536 requests 1K; >1536 requests 2K. The nearest supported aspect ratio is used; exact pixels are not guaranteed. 1K, 2K, 4K, and 16:9 are not valid size values. |  | 1920x1080 |
| stream | body | boolean | no | Defaults to false. true emits SSE only after generation and storage succeed; there is no generation progress stream. Ends with finish_reason=stop and data: [DONE]. |  | false |
| n / response_format / quality / mask / input_fidelity / background / output_format / output_compression | body | ignored | no | These parameters are ignored. One request generates one image. Images and Chat return a URL regardless of b64_json, transparency, or output format settings. mask is not a reference image. |  |  |

## Chat text to image

```json
{
  "model": "gemini-nano-banana-2.1-c",
  "messages": [
    {
      "role": "user",
      "content": "A yellow ceramic bowl on a white background. No text."
    }
  ],
  "size": "1024x1024",
  "stream": false
}
```

### cURL

```bash
curl --fail-with-body --max-time 300 'https://api.unifyllm.top/v1/chat/completions' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "gemini-nano-banana-2.1-c",
  "messages": [
    {
      "role": "user",
      "content": "A yellow ceramic bowl on a white background. No text."
    }
  ],
  "size": "1024x1024",
  "stream": false
}'
```

### JavaScript

```javascript
const response = await fetch("https://api.unifyllm.top/v1/chat/completions", {
  method: "POST",
  headers: {
  "Authorization": "Bearer <YOUR_API_KEY>",
  "Content-Type": "application/json"
},
  body: JSON.stringify({
  "model": "gemini-nano-banana-2.1-c",
  "messages": [
    {
      "role": "user",
      "content": "A yellow ceramic bowl on a white background. No text."
    }
  ],
  "size": "1024x1024",
  "stream": false
}),
  signal: AbortSignal.timeout(300_000),
});
if (!response.ok) throw new Error(await response.text());
const data = await response.json();
console.log(data);
```

### Python

```python
import json
import requests

payload = json.loads("{\n  \"model\": \"gemini-nano-banana-2.1-c\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"A yellow ceramic bowl on a white background. No text.\"\n    }\n  ],\n  \"size\": \"1024x1024\",\n  \"stream\": false\n}")
response = requests.post(
    "https://api.unifyllm.top/v1/chat/completions",
    headers={"Authorization": "Bearer <YOUR_API_KEY>"},
    json=payload,
    timeout=(10, 300),
)
response.raise_for_status()
print(response.json())
```

## Chat streaming image

```json
{
  "model": "gemini-nano-banana-2.1-c",
  "messages": [
    {
      "role": "user",
      "content": "A yellow ceramic bowl on a white background. No text."
    }
  ],
  "size": "1024x1024",
  "stream": true
}
```

### cURL

```bash
curl --fail-with-body --max-time 300 --no-buffer 'https://api.unifyllm.top/v1/chat/completions' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "gemini-nano-banana-2.1-c",
  "messages": [
    {
      "role": "user",
      "content": "A yellow ceramic bowl on a white background. No text."
    }
  ],
  "size": "1024x1024",
  "stream": true
}'
```

### JavaScript

```javascript
const response = await fetch("https://api.unifyllm.top/v1/chat/completions", {
  method: "POST",
  headers: {
  "Authorization": "Bearer <YOUR_API_KEY>",
  "Content-Type": "application/json"
},
  body: JSON.stringify({
  "model": "gemini-nano-banana-2.1-c",
  "messages": [
    {
      "role": "user",
      "content": "A yellow ceramic bowl on a white background. No text."
    }
  ],
  "size": "1024x1024",
  "stream": true
}),
  signal: AbortSignal.timeout(300_000),
});
if (!response.ok) throw new Error(await response.text());
const decoder = new TextDecoder();
for await (const chunk of response.body) {
  process.stdout.write(decoder.decode(chunk, { stream: true }));
}
// SSE may split across chunks. Parse complete data: events through [DONE].
```

### Python

```python
import json
import requests

payload = json.loads("{\n  \"model\": \"gemini-nano-banana-2.1-c\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"A yellow ceramic bowl on a white background. No text.\"\n    }\n  ],\n  \"size\": \"1024x1024\",\n  \"stream\": true\n}")
with requests.post(
    "https://api.unifyllm.top/v1/chat/completions",
    headers={"Authorization": "Bearer <YOUR_API_KEY>"},
    json=payload,
    timeout=(10, 300),
    stream=True,
) as response:
    response.raise_for_status()
    for line in response.iter_lines():
        if line:
            print(line.decode("utf-8"), flush=True)
```

## Chat reference image

```json
{
  "model": "gemini-nano-banana-2.1-c",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "Change the cup to green; keep the white background."
        },
        {
          "type": "image_url",
          "image_url": {
            "url": "https://example.com/reference.jpg"
          }
        }
      ]
    }
  ],
  "size": "auto",
  "stream": false
}
```

### cURL

```bash
curl --fail-with-body --max-time 300 'https://api.unifyllm.top/v1/chat/completions' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "gemini-nano-banana-2.1-c",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "Change the cup to green; keep the white background."
        },
        {
          "type": "image_url",
          "image_url": {
            "url": "https://example.com/reference.jpg"
          }
        }
      ]
    }
  ],
  "size": "auto",
  "stream": false
}'
```

### JavaScript

```javascript
const response = await fetch("https://api.unifyllm.top/v1/chat/completions", {
  method: "POST",
  headers: {
  "Authorization": "Bearer <YOUR_API_KEY>",
  "Content-Type": "application/json"
},
  body: JSON.stringify({
  "model": "gemini-nano-banana-2.1-c",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "Change the cup to green; keep the white background."
        },
        {
          "type": "image_url",
          "image_url": {
            "url": "https://example.com/reference.jpg"
          }
        }
      ]
    }
  ],
  "size": "auto",
  "stream": false
}),
  signal: AbortSignal.timeout(300_000),
});
if (!response.ok) throw new Error(await response.text());
const data = await response.json();
console.log(data);
```

### Python

```python
import json
import requests

payload = json.loads("{\n  \"model\": \"gemini-nano-banana-2.1-c\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": [\n        {\n          \"type\": \"text\",\n          \"text\": \"Change the cup to green; keep the white background.\"\n        },\n        {\n          \"type\": \"image_url\",\n          \"image_url\": {\n            \"url\": \"https://example.com/reference.jpg\"\n          }\n        }\n      ]\n    }\n  ],\n  \"size\": \"auto\",\n  \"stream\": false\n}")
response = requests.post(
    "https://api.unifyllm.top/v1/chat/completions",
    headers={"Authorization": "Bearer <YOUR_API_KEY>"},
    json=payload,
    timeout=(10, 300),
)
response.raise_for_status()
print(response.json())
```

## Response examples

### Chat image URL — HTTP 200

```json
{
  "id": "chatcmpl-gemini-example",
  "object": "chat.completion",
  "created": 1795730000,
  "model": "gemini-nano-banana-2.1-c",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "![生成图片](https://image.ezworkapi.top/gemini-img?id=EXAMPLE_IMAGE_ID&sig=EXAMPLE_SIGNATURE)"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 28,
    "completion_tokens": 1120,
    "total_tokens": 1148
  }
}
```

### SSE image result — HTTP 200

```sse
data: {"id":"chatcmpl-gemini-example","object":"chat.completion.chunk","model":"gemini-nano-banana-2.1-c","choices":[{"index":0,"delta":{"role":"assistant","content":"![生成图片](https://image.ezworkapi.top/gemini-img?id=EXAMPLE_IMAGE_ID&sig=EXAMPLE_SIGNATURE)"},"finish_reason":null}]}

data: {"id":"chatcmpl-gemini-example","object":"chat.completion.chunk","model":"gemini-nano-banana-2.1-c","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":28,"completion_tokens":1120,"total_tokens":1148}}

data: [DONE]


```

## Related endpoints

- [Gemini Image — Images API](https://www.unifyllm.com/docs/api-reference/gemini-image-create/)
- [Gemini Image Edit — JSON](https://www.unifyllm.com/docs/api-reference/gemini-image-edit-json/)
- [Gemini Native Image Generation](https://www.unifyllm.com/docs/api-reference/nano-banana-image/)
