> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mixroute.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Gemini Native (Image, Streaming)

> Native Gemini image streaming requests and response handling.

Stream Gemini image-generation responses using the native streamGenerateContent endpoint. Request fields are the same as generateContent.

`POST https://api.mixroute.ai/v1/models/{model}:streamGenerateContent?alt=sse`

## Models

| Model ID | Capabilities and Limits |
| - | - |
| `gemini-nano-banana-2.1` | Nano Banana 2.1; 1K/2K/4K output; MINIMAL/MEDIUM/HIGH thinking, default MEDIUM. |
| `gemini-3.1-flash-image` | Nano Banana 2; 512, 1K, 2K, 4K output; MINIMAL/HIGH thinking. |
| `gemini-3.1-flash-image-preview` | Nano Banana 2; 512, 1K, 2K, 4K output; MINIMAL/HIGH thinking. |
| `gemini-3-pro-image` | Nano Banana Pro; 1K, 2K, 4K output and image/text reasoning. |
| `gemini-3-pro-image-preview` | Nano Banana Pro; 1K, 2K, 4K output and image/text reasoning. |
| `gemini-3.1-flash-lite-image` | Nano Banana 2 Lite; 1K output only; no Google Search grounding. |
| `gemini-2.5-flash-image` | Original Nano Banana; approximately 1K output. Omit imageSize. |

The request body uses the same fields and model restrictions as [Gemini image generation](/api-reference/endpoint/nano-banana). Use `alt=sse` in the query string; do not add a body stream parameter.

## Examples

Use your MixRoute key in the `MIXROUTE_API_KEY` environment variable. Requests use `Authorization: Bearer ...`. Replace source-image placeholders with accessible images or local files before editing.

```bash theme={null}
curl --no-buffer --request POST "https://api.mixroute.ai/v1/models/gemini-nano-banana-2.1:streamGenerateContent?alt=sse" \
  --header "Authorization: Bearer $MIXROUTE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "A clean product photograph of a red ceramic mug on a white background."
        }
      ]
    }
  ],
  "generationConfig": {
    "responseModalities": [
      "TEXT",
      "IMAGE"
    ],
    "imageConfig": {
      "aspectRatio": "1:1",
      "imageSize": "1K"
    }
  }
}'
```

### Python

```python theme={null}
import base64
import json
import os
from pathlib import Path
import requests

payload = json.loads(r'''
{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "A clean product photograph of a red ceramic mug on a white background."
        }
      ]
    }
  ],
  "generationConfig": {
    "responseModalities": [
      "TEXT",
      "IMAGE"
    ],
    "imageConfig": {
      "aspectRatio": "1:1",
      "imageSize": "1K"
    }
  }
}
''')

def events(lines):
    data = []
    for line in lines:
        if line == "":
            if data:
                yield "\n".join(data)
                data.clear()
        elif line.startswith("data:"):
            value = line[5:]
            data.append(value[1:] if value.startswith(" ") else value)
    if data:
        yield "\n".join(data)

url = "https://api.mixroute.ai/v1/models/gemini-nano-banana-2.1:streamGenerateContent?alt=sse"
image_index = 0
with requests.post(url, headers={"Authorization": "Bearer " + os.environ["MIXROUTE_API_KEY"]}, json=payload, stream=True, timeout=(30, 180)) as response:
    response.raise_for_status()
    response.encoding = "utf-8"
    for data in events(response.iter_lines(decode_unicode=True)):
        if not data.strip():
            continue
        if data.strip() == "[DONE]":
            break
        chunk = json.loads(data)
        if "error" in chunk:
            raise RuntimeError(chunk["error"])
        for candidate in chunk.get("candidates", []):
            for part in candidate.get("content", {}).get("parts", []):
                if part.get("thought"):
                    continue
                if "inlineData" in part:
                    inline = part["inlineData"]
                    if inline.get("data"):
                        extension = {"image/png": "png", "image/jpeg": "jpg", "image/webp": "webp"}.get(inline.get("mimeType"), "bin")
                        Path(f"image_{image_index}.{extension}").write_bytes(base64.b64decode(inline["data"], validate=True))
                        image_index += 1
                elif "text" in part:
                    print(part["text"], end="")
```

## Response

Read text and image parts from candidates\[].content.parts\[]. Images normally use inlineData with mimeType and Base64 data; preserve thoughtSignature when reusing model turns. Check promptFeedback and finishReason when an image is absent. usageMetadata contains token usage, not image-generation settings.

[Gemini synchronous image requests](/api-reference/endpoint/nano-banana)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.