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

# Chat 生图

> Gemini 生图（OpenAI Chat Completions）。文生图与图生图为同一接口。

**路径：** `POST https://api.omniall.ai/v1/chat/completions`

- **文生图**：`content` 为纯文本字符串，或仅含 `type: text`
- **图生图 / 多图参考**：`content` 数组含 `text` + 一条或多条 `image_url`
- **PDF / 短视频参考**（香蕉 2.1）：再加 `type: file` / `type: video_url`

推荐使用非流式 `stream: false`。鉴权：`Authorization: Bearer sk-...`


## 同一接口，多种用例

`POST /v1/chat/completions` 同时覆盖 **文生图** 与 **图生图**（以及多图 / PDF / 短视频参考）。区别只在 `messages` 里放什么，不是两个 API。

| 用例 | `messages[].content` |
| - | - |
| 文生图 | 纯文本字符串，或仅 `type: text` |
| 图生图 | `text` + `image_url`（可多张） |
| PDF 参考（香蕉 2.1） | `text` + `file` |
| 短视频参考（香蕉 2.1） | `text` + `video_url`（**字符串**） |

网关链路：Chat `messages` → 下载 URL / 解码 data URL → Gemini `inlineData` → 上游 `generateContent`。
远程 PDF / 视频 URL **可以传**；不会以 `fileUri` 原样透传给上游。

| 媒体 | content 类型 | 取值 |
| - | - | - |
| 图片 | `image_url` | HTTPS URL 或 `data:image/...;base64,...` |
| PDF | `file` | `filename` + `file_data`（HTTPS URL 或 `data:application/pdf;base64,...`） |
| 视频 | `video_url` | **字符串** HTTPS URL 或 `data:video/mp4;base64,...` |

### PDF URL（完整）

```json theme={null}
{
  "model": "gemini-nano-banana-2.1",
  "stream": false,
  "extra_body": {
    "google": {
      "image_config": {
        "aspect_ratio": "3:2",
        "image_size": "1K"
      }
    }
  },
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "读取该 PDF，按页列出编号、颜色和形状，再生成一张白底参考图。"
        },
        {
          "type": "file",
          "file": {
            "filename": "reference.pdf",
            "file_data": "https://example.com/reference.pdf"
          }
        }
      ]
    }
  ]
}
```

### 视频 URL（完整）

```json theme={null}
{
  "model": "gemini-nano-banana-2.1",
  "stream": false,
  "extra_body": {
    "google": {
      "image_config": {
        "aspect_ratio": "3:2",
        "image_size": "1K"
      }
    }
  },
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "观看视频，按场景顺序列出元素，再生成一张参考图。"
        },
        {
          "type": "video_url",
          "video_url": "https://example.com/clip.mp4"
        }
      ]
    }
  ]
}
```

```bash theme={null}
curl --fail-with-body --max-time 180 \
  "https://api.omniall.ai/v1/chat/completions" \
  -H "Authorization: Bearer sk-xxx" \
  -H "Content-Type: application/json" \
  --data-binary @request.json
```

说明：URL 须公网可下载；单文件下载默认约 64MB；优先短小 MP4 / 小 PDF。`video_url` 请用字符串，不要写成 `{ "url": "..." }`。

### 可选：Thinking

香蕉 2.1 支持思考档位 `minimal` / `medium`（默认）/ `high`。写在 `extra_body.google.thinking_config`（snake\_case）：

```json theme={null}
"extra_body": {
  "google": {
    "image_config": { "aspect_ratio": "3:2", "image_size": "1K" },
    "thinking_config": {
      "thinking_level": "high",
      "include_thoughts": false
    }
  }
}
```

`include_thoughts` 只控制是否返回思考正文；常规接入可省略整段 `thinking_config`。详见 [概述 · Thinking](/zh-CN/api-reference/image-gemini#可选thinking思考档位)。


## OpenAPI

````yaml zh-CN/openapi/gemini-chat-image-zh.yaml POST /v1/chat/completions
openapi: 3.1.0
info:
  title: Omniall AI — Gemini Chat 生图
  version: 1.2.0
  description: >
    通过同一 OpenAI Chat Completions 接口调用 Gemini 生图。


    **路径：** `POST https://api.omniall.ai/v1/chat/completions`


    文生图、图生图、多图参考、PDF / 短视频参考均为同一接口的不同用例，仅 `messages` 内容不同。


    模型示例：`gemini-nano-banana-2.1`、`gemini-3.1-flash-image-preview`、`gemini-3-pro-image-preview`。

    可用 `extra_body.google.image_config`
    控制画幅与分辨率（`aspect_ratio`、`image_size`：`1K`/`2K`/`4K`）。

    可选 Thinking（香蕉 2.1）：`extra_body.google.thinking_config.thinking_level` 为
    `minimal` / `medium`（默认）/ `high`；

    `include_thoughts` 仅控制是否返回思考正文（须用 snake_case）。


    `messages[].content` 部件类型：

    - 纯文本字符串，或 `type: text` — 文生图提示词 / 编辑指令

    - `image_url` — 参考图（HTTPS URL 或 data URL）

    - `file` — PDF 参考（`file_data` 为 HTTPS URL 或
    `data:application/pdf;base64,...`；须同时提供 `filename`）

    - `video_url` — 短视频（**字符串** HTTPS URL 或 `data:video/mp4;base64,...`）


    网关会下载远程 URL，转为 Gemini `inlineData` 再请求上游。

    鉴权：`Authorization: Bearer sk-...`
servers:
  - url: https://api.omniall.ai
security: []
paths:
  /v1/chat/completions:
    post:
      tags:
        - Gemini绘图
      summary: Chat 生图
      description: |
        Gemini 生图（OpenAI Chat Completions）。文生图与图生图为同一接口。

        **路径：** `POST https://api.omniall.ai/v1/chat/completions`

        - **文生图**：`content` 为纯文本字符串，或仅含 `type: text`
        - **图生图 / 多图参考**：`content` 数组含 `text` + 一条或多条 `image_url`
        - **PDF / 短视频参考**（香蕉 2.1）：再加 `type: file` / `type: video_url`

        推荐使用非流式 `stream: false`。鉴权：`Authorization: Bearer sk-...`
      operationId: geminiChatImageZh
      parameters:
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
            example: Bearer sk-...
          description: Bearer API Key，例如 `Bearer sk-...`。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - model
                - messages
              description: Gemini Chat 生图请求体（`POST /v1/chat/completions`）。
              properties:
                model:
                  type: string
                  description: >-
                    Gemini 图像模型
                    ID。示例：`gemini-nano-banana-2.1`、`gemini-3.1-flash-image-preview`。
                  example: gemini-3.1-flash-image-preview
                messages:
                  type: array
                  description: 对话消息。文生图多为一条 `user` 文本；图生图在 `content` 中同时放文本与媒体部件。
                  items:
                    type: object
                    properties:
                      role:
                        type: string
                        description: 消息角色。生图请求使用 `user`。
                        example: user
                      content:
                        oneOf:
                          - type: string
                            description: 纯文本提示词（文生图可直接传字符串）。
                          - type: array
                            description: >-
                              多模态内容：`text`、`image_url`、`file`（PDF）、`video_url`（短视频）。
                            items:
                              type: object
                              properties:
                                type:
                                  type: string
                                  enum:
                                    - text
                                    - image_url
                                    - file
                                    - video_url
                                text:
                                  type: string
                                image_url:
                                  type: object
                                  properties:
                                    url:
                                      type: string
                                      description: >-
                                        HTTPS 图片 URL 或
                                        `data:image/...;base64,...`。
                                  required:
                                    - url
                                file:
                                  type: object
                                  description: PDF / 文档部件。`filename` 与 `file_data` 均必填。
                                  properties:
                                    filename:
                                      type: string
                                      example: reference.pdf
                                    file_data:
                                      type: string
                                      description: >-
                                        HTTPS PDF URL 或
                                        `data:application/pdf;base64,...`。
                                  required:
                                    - filename
                                    - file_data
                                video_url:
                                  type: string
                                  description: >-
                                    视频字符串：HTTPS URL 或
                                    `data:video/mp4;base64,...`。
                    required:
                      - role
                      - content
                stream:
                  type: boolean
                  description: 是否流式返回。Chat 生图推荐 `false`（非流式，一次返回完整结果）。
                  default: false
                  example: false
                extra_body:
                  type: object
                  description: 提供方扩展。Gemini 配置放在 `extra_body.google` 下。
                  properties:
                    google:
                      type: object
                      properties:
                        image_config:
                          type: object
                          description: 图像输出配置（画幅、分辨率）。亦兼容 camelCase。
                          properties:
                            aspect_ratio:
                              type: string
                              enum:
                                - '1:1'
                                - '2:3'
                                - '3:2'
                                - '3:4'
                                - '4:3'
                                - '4:5'
                                - '5:4'
                                - '9:16'
                                - '16:9'
                                - '21:9'
                              example: '1:1'
                            image_size:
                              type: string
                              enum:
                                - 1K
                                - 2K
                                - 4K
                              example: 2K
                        thinking_config:
                          type: object
                          description: |
                            可选。香蕉 2.1 Thinking（snake_case）。
                            `thinking_level`：`minimal` / `medium`（默认）/ `high`。
                          properties:
                            thinking_level:
                              type: string
                              enum:
                                - minimal
                                - medium
                                - high
                              example: high
                            include_thoughts:
                              type: boolean
                              example: false
            examples:
              文生图:
                summary: 文生图（纯文本）
                value:
                  model: gemini-3.1-flash-image-preview
                  messages:
                    - role: user
                      content: 一只在樱花树下睡觉的橘猫，日系插画，柔和光线
                  stream: false
                  extra_body:
                    google:
                      image_config:
                        aspect_ratio: '1:1'
                        image_size: 2K
              图生图:
                summary: 图生图（图片 URL）
                value:
                  model: gemini-3.1-flash-image-preview
                  messages:
                    - role: user
                      content:
                        - type: text
                          text: 在同一画布下，生成此物品的三视图，必须白色背景
                        - type: image_url
                          image_url:
                            url: https://example.com/reference.jpg
                  stream: false
                  extra_body:
                    google:
                      image_config:
                        aspect_ratio: '16:9'
                        image_size: 2K
              多图参考:
                summary: 多图参考
                value:
                  model: gemini-3.1-flash-image-preview
                  messages:
                    - role: user
                      content:
                        - type: text
                          text: 参考以下图片的风格与布局，生成一张统一视觉的产品海报
                        - type: image_url
                          image_url:
                            url: https://example.com/ref-style.jpg
                        - type: image_url
                          image_url:
                            url: https://example.com/ref-layout.jpg
                  stream: false
                  extra_body:
                    google:
                      image_config:
                        aspect_ratio: '16:9'
                        image_size: 2K
              PDF_URL参考:
                summary: PDF URL 参考（香蕉 2.1）
                value:
                  model: gemini-nano-banana-2.1
                  messages:
                    - role: user
                      content:
                        - type: text
                          text: 读取该 PDF，按页列出编号、颜色和形状，再生成一张白底参考图。
                        - type: file
                          file:
                            filename: reference.pdf
                            file_data: https://example.com/reference.pdf
                  stream: false
                  extra_body:
                    google:
                      image_config:
                        aspect_ratio: '3:2'
                        image_size: 1K
              视频URL参考:
                summary: 视频 URL 参考（香蕉 2.1）
                value:
                  model: gemini-nano-banana-2.1
                  messages:
                    - role: user
                      content:
                        - type: text
                          text: 观看视频，按场景顺序列出元素，再生成一张参考图。
                        - type: video_url
                          video_url: https://example.com/clip.mp4
                  stream: false
                  extra_body:
                    google:
                      image_config:
                        aspect_ratio: '3:2'
                        image_size: 1K
      responses:
        '200':
          description: Chat Completions 响应（流式为 SSE）。图像通常出现在 assistant 消息的多模态内容中。
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
        '400':
          description: 请求无效
        '401':
          description: 未授权
        '429':
          description: 限流
        '500':
          description: 上游/网关错误

````

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