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

# Gemini 生成内容

> 以 Gemini 原生格式进行文本对话与图片 / PDF / 音频 / 视频识别

## 可填写的模型

| 模型 ID                    | 说明                    |
| ------------------------ | --------------------- |
| `gemini-3.1-pro-preview` | Gemini 旗舰，强多模态，超长上下文  |
| `gemini-2.5-pro`         | 高性能多模态，支持百万 token 上下文 |
| `gemini-2.5-flash`       | 快速轻量版，适合高频调用          |

完整列表见 [`GET /v1/models`](/zh/api-reference/models/list-models)。

## 多轮对话

在 `contents` 数组中交替填写 `role: user` 和 `role: model`
的消息即可构成多轮对话。

## 媒体识别

在 `parts` 中加入 `inlineData` 字段，提供 `mimeType`（如
`image/jpeg`、`application/pdf`、`audio/mpeg`、`video/mp4`）
和 base64 编码的文件数据。

## 流式输出

将路径中的 `:generateContent` 改为 `:streamGenerateContent?alt=sse`
即可切换为 Server-Sent Events 流式模式。

## 安全过滤

通过 `safetySettings` 数组调整各危害类别的过滤阈值。

## 系统指令

通过 `systemInstruction` 字段传入系统级提示，格式与 `contents`
中的 `parts` 相同。


## OpenAPI

````yaml /openapi/chat.zh.yaml post /v1beta/models/{model}:generateContent
openapi: 3.1.0
info:
  title: InfinityBlue API — 聊天（Chat）
  version: 1.0.0
  summary: 统一的 AI 模型 API 网关 — 聊天接口
  description: |
    InfinityBlue 是一个统一的 AI 模型 API 网关，以 **OpenAI、Google Gemini、
    Anthropic Claude 等原生格式** 对外提供兼容接口，背后聚合了 OpenAI、
    Google、DeepSeek、字节豆包（Seedance）、快手可灵（Kling）等厂商的模型。

    你无需为每家厂商单独接入——只要把 base URL 指向 InfinityBlue，
    沿用你熟悉的官方 SDK 即可调用全部模型。

    ## 认证

    所有请求都需要在请求头中携带 API Key：

    ```
    Authorization: Bearer YOUR_API_KEY
    ```

    在 [控制台](https://api.getinfinityblue.com/console) 创建和管理你的 API Key。

    ## 接口格式约定

    | 路径前缀 | 兼容格式 |
    | --- | --- |
    | `/v1/*` | OpenAI（Chat Completions、Responses、Images 等） |
    | `/v1/messages` | Anthropic Claude Messages |
    | `/v1beta/models/*` | Google Gemini 原生 |

    ## 模型选择

    在 `model` 参数中传入任意模型 ID 即可。完整可用列表见
    [`GET /v1/models`](/zh/api-reference/models/list-models)
    或 [模型价格页](https://api.getinfinityblue.com/pricing)。
  contact:
    name: InfinityBlue
    url: https://getinfinityblue.com
servers:
  - url: https://api.getinfinityblue.com
    description: 生产环境
security:
  - bearerAuth: []
tags:
  - name: 聊天（Chat）
    description: |
      文本对话、视觉理解、工具调用、流式输出与推理模型，
      通过统一的对话接口提供。
paths:
  /v1beta/models/{model}:generateContent:
    post:
      tags:
        - 聊天（Chat）
      summary: Gemini 生成内容（文本 / 媒体识别）
      description: |
        代理原生 Gemini `generateContent` 请求，支持文本对话与多媒体识别（图片、PDF、音频、视频）。

        路径格式：`/v1beta/models/{model_name}:generateContent`

        流式变体：`/v1beta/models/{model_name}:streamGenerateContent?alt=sse`

        ⚠️ 媒体内容仅支持通过 `inlineData` 以 base64 方式上传，
        不支持 `fileData.fileUri` 或 Google File API。
      operationId: geminiGenerateContent
      parameters:
        - name: model
          in: path
          description: 模型名称，例如 `gemini-2.5-pro`、`gemini-2.5-flash`。
          required: true
          schema:
            type: string
            examples:
              - gemini-2.5-pro
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GeminiGenerateContentRequest'
            examples:
              text_chat:
                summary: 文本聊天
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 你好，请用一句话介绍 Gemini。
              multi_turn:
                summary: 多轮对话
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 你好
                    - role: model
                      parts:
                        - text: 你好！有什么我可以帮你的吗？
                    - role: user
                      parts:
                        - text: 我家里有两条狗，它们总共有多少只爪子？
              image_recognition:
                summary: 图片识别
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 请描述这张图片中的乐器。
                        - inlineData:
                            mimeType: image/jpeg
                            data: <base64 编码的图片数据>
              pdf_recognition:
                summary: PDF 识别
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 请为这首诗续写几行。
                        - inlineData:
                            mimeType: application/pdf
                            data: <base64 编码的 PDF 数据>
              audio_recognition:
                summary: 音频识别
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 请描述这段音频文件的内容。
                        - inlineData:
                            mimeType: audio/mpeg
                            data: <base64 编码的音频数据>
              video_recognition:
                summary: 视频识别
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 请转录视频中的语音，并提供视觉描述。
                        - inlineData:
                            mimeType: video/mp4
                            data: <base64 编码的视频数据>
      responses:
        '200':
          description: 成功生成内容
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeminiGenerateContentResponse'
        '400':
          description: 请求参数错误
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: API Key 无效或缺失
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: 请求频率超限
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: 服务器内部错误
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    GeminiGenerateContentRequest:
      type: object
      description: Gemini generateContent 请求体，同时适用于文本对话与媒体识别。
      properties:
        contents:
          type: array
          description: |
            对话内容数组，按时间顺序排列。每个元素包含 `role`（`user` 或 `model`）
            和 `parts`（内容片段列表）。
          items:
            type: object
            properties:
              role:
                type: string
                enum:
                  - user
                  - model
                description: 消息角色。
              parts:
                type: array
                description: 内容片段列表，可包含文本、图片、PDF、音频、视频等。
                items:
                  type: object
                  properties:
                    text:
                      type: string
                      description: 文本内容。
                    inlineData:
                      type: object
                      description: Base64 编码的媒体数据，用于图片、PDF、音频、视频识别。
                      properties:
                        mimeType:
                          type: string
                          description: |
                            媒体 MIME 类型，例如 `image/jpeg`、`image/png`、
                            `application/pdf`、`audio/mpeg`、`video/mp4`。
                          examples:
                            - image/jpeg
                        data:
                          type: string
                          description: Base64 编码的媒体文件数据。
        generationConfig:
          type: object
          description: 生成参数配置。
          properties:
            temperature:
              type: number
              description: 采样温度，控制输出随机性。
            topP:
              type: number
              description: 核采样概率阈值。
            topK:
              type: integer
              description: Top-K 采样参数，模型每步只考虑概率最高的 K 个 token。
            maxOutputTokens:
              type: integer
              description: 响应中可生成的最大 token 数。
            stopSequences:
              type: array
              description: 停止序列列表，模型生成到其中任一序列时停止。
              items:
                type: string
        safetySettings:
          type: array
          description: 安全过滤设置，可调整各危害类别的过滤阈值。
          items:
            type: object
            properties:
              category:
                type: string
                description: 危害类别，例如 `HARM_CATEGORY_HARASSMENT`。
              threshold:
                type: string
                description: 过滤阈值，例如 `BLOCK_NONE`、`BLOCK_ONLY_HIGH`。
        tools:
          type: array
          description: 工具列表，用于函数调用（Function Calling）。
          items:
            type: object
        systemInstruction:
          type: object
          description: 系统级指令，格式与 `contents` 中的元素相同。
          properties:
            parts:
              type: array
              description: 系统指令内容片段列表。
              items:
                type: object
                properties:
                  text:
                    type: string
                    description: 系统指令文本。
    GeminiGenerateContentResponse:
      type: object
      description: Gemini generateContent 响应体。
      properties:
        candidates:
          type: array
          description: 模型生成的候选响应列表。
          items:
            type: object
            properties:
              content:
                type: object
                description: 响应内容。
                properties:
                  role:
                    type: string
                    description: 角色，通常为 `model`。
                  parts:
                    type: array
                    description: 内容片段列表。
                    items:
                      type: object
                      properties:
                        text:
                          type: string
                          description: 文本内容。
              finishReason:
                type: string
                description: 生成结束原因，例如 `STOP`、`MAX_TOKENS`、`SAFETY`。
              safetyRatings:
                type: array
                description: 各危害类别的安全评分。
                items:
                  type: object
                  properties:
                    category:
                      type: string
                      description: 危害类别。
                    probability:
                      type: string
                      description: 该类别的危害概率，例如 `NEGLIGIBLE`、`LOW`、`MEDIUM`、`HIGH`。
        usageMetadata:
          type: object
          description: Token 用量统计。
          properties:
            promptTokenCount:
              type: integer
              description: 提示词消耗的 token 数。
            candidatesTokenCount:
              type: integer
              description: 所有候选响应消耗的 token 数。
            totalTokenCount:
              type: integer
              description: 总消耗 token 数。
    ErrorResponse:
      type: object
      description: 标准错误响应。
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              description: 错误信息。
              examples:
                - 无效的时长。支持的范围为 4 到 15 秒。
            type:
              type: string
              description: 错误类型。
              examples:
                - invalid_request_error
            param:
              type:
                - string
                - 'null'
              description: 相关参数。
              examples:
                - seconds
            code:
              type:
                - string
                - 'null'
              description: 错误代码。
              examples:
                - invalid_duration
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: |
        使用 Bearer Token 认证，格式：`Authorization: Bearer sk-xxxxxx`。
        在 [控制台](https://api.getinfinityblue.com/console) 获取 API Key。

````