> ## 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 3.1 Flash Image Preview

> Gemini 3.1 Flash Image Preview：圖片生成模型。包含 MixRoute 呼叫範例與參數。

Gemini 3.1 Flash Image Preview 是 Google 推出的圖片生成模型。

可透過 MixRoute 的 Gemini 原生端點呼叫 `gemini-3.1-flash-image-preview`，同時支援 OpenAI 相容端點。

## 核心能力

* 文字生成圖片 - 根據文字生成圖片
* Gemini 原生 API - 使用 generateContent
* 圖片輸出 - 在 responseModalities 中請求 IMAGE
* 內容片段 - 使用 Gemini 多模態輸入結構

## 輸出規格

| 屬性   | 取值                                                          |
| ---- | ----------------------------------------------------------- |
| 端點   | `/v1/models/gemini-3.1-flash-image-preview:generateContent` |
| 輸出模態 | `IMAGE`                                                     |
| 回應   | Gemini content parts 中的圖片資料                                 |

## 快速範例

### Gemini 原生 API

<Tabs>
  <Tab title="cURL">
    ```bash theme={null}
    curl "https://api.mixroute.ai/v1/models/gemini-3.1-flash-image-preview:generateContent" \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
      "contents": [
        {
          "parts": [
            {
              "text": "A minimal red circle centered on a white background"
            }
          ]
        }
      ],
      "generationConfig": {
        "responseModalities": [
          "TEXT",
          "IMAGE"
        ]
      }
    }'
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    import requests

    response = requests.post(
        "https://api.mixroute.ai/v1/models/gemini-3.1-flash-image-preview:generateContent",
        headers={"Authorization": "Bearer YOUR_API_KEY"},
        json={'contents': [{'parts': [{'text': 'A minimal red circle centered on a white '
                                               'background'}]}],
              'generationConfig': {'responseModalities': ['TEXT', 'IMAGE']}},
    )

    print(response.json())
    ```
  </Tab>
</Tabs>

### OpenAI 相容 API

<Tabs>
  <Tab title="cURL">
    ```bash theme={null}
    curl "https://api.mixroute.ai/v1/chat/completions" \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
      "model": "gemini-3.1-flash-image-preview",
      "messages": [
        {
          "role": "user",
          "content": "Explain quantum entanglement in simple terms."
        }
      ],
      "max_tokens": 256
    }'
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    from openai import OpenAI

    client = OpenAI(api_key="YOUR_API_KEY", base_url="https://api.mixroute.ai/v1")

    response = client.chat.completions.create(
        model="gemini-3.1-flash-image-preview",
        messages=[{"role": "user", "content": "Explain quantum entanglement in simple terms."}],
        max_tokens=256,
    )

    print(response.choices[0].message.content)
    ```
  </Tab>

  <Tab title="Streaming">
    ```python theme={null}
    from openai import OpenAI

    client = OpenAI(api_key="YOUR_API_KEY", base_url="https://api.mixroute.ai/v1")

    stream = client.chat.completions.create(
        model="gemini-3.1-flash-image-preview",
        messages=[{"role": "user", "content": "Write a short poem about the sea."}],
        max_tokens=256,
        stream=True,
    )

    for chunk in stream:
        print(chunk.choices[0].delta.content or "", end="")
    ```
  </Tab>
</Tabs>

## 參數

| 參數                                    | 類型     | 必填 | 說明                |
| ------------------------------------- | ------ | -- | ----------------- |
| `contents`                            | array  | 是  | 提示詞與可選多模態內容片段。    |
| `generationConfig.responseModalities` | array  | 是  | 包含 IMAGE 以請求圖片輸出。 |
| `generationConfig`                    | object | 否  | 其他生成參數。           |
