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

# Gemini generateContent

> Omniall AI 转发的 Google Gemini 原生 generateContent 接口。支持视觉、文件、接地搜索与函数调用。



## OpenAPI

````yaml zh-CN/openapi/xgapi-public.yaml POST /v1beta/models/{model}:generateContent
openapi: 3.0.3
info:
  title: Omniall AI 公开 API
  description: >-
    Omniall AI 公开 API。网站：https://omniall.ai — API 主机：https://api.omniall.ai —
    模型广场：https://omniall.ai/pricing
  version: 1.1.0
servers:
  - url: https://api.omniall.ai
    description: 生产环境
security:
  - bearerAuth: []
tags:
  - name: Models
    description: 列出当前 API Key 可用的模型。
  - name: ChatGPT Chat Completions
    x-group: ChatGPT
    description: OpenAI Chat Completions 对话接口（`POST /v1/chat/completions`）。
  - name: Responses
    description: OpenAI Responses 接口（`POST /v1/responses`）。
  - name: Claude
    description: Anthropic Messages 消息接口（`POST /v1/messages`）。
  - name: Gemini
    description: Google Gemini 原生 generateContent / streamGenerateContent。
  - name: Images
    description: 图像生成（OpenAI Images）、各厂商说明与 Midjourney 代理接口。
  - name: Video
    description: 异步视频任务。
  - name: Audio
    description: 语音合成及相关音频接口。
  - name: Rerank
    description: 文档重排序。
paths:
  /v1beta/models/{model}:generateContent:
    post:
      tags:
        - Gemini
      summary: Gemini 原生 generateContent
      description: >
        Google Gemini 原生 `generateContent`（Omniall AI 转发）。


        **路径：** `POST
        https://api.omniall.ai/v1beta/models/{model}:generateContent`


        非流式原生调用。生图请在 `generationConfig.responseModalities` 中包含 `IMAGE`，并用
        `imageConfig.aspectRatio` / `imageConfig.imageSize` 控制画幅与分辨率。


        鉴权：`Authorization: Bearer sk-...`，或 `x-goog-api-key` / `?key=`。


        ### 常见场景


        - **文生图**：仅 `parts[].text` + `responseModalities` 含 `IMAGE`

        - **图生图**：`parts` 同时包含 `inlineData` 参考图与文本指令

        - **视觉理解**：`inlineData` + 文本提问（不强制 IMAGE 模态）


        官方参考：https://ai.google.dev/api/generate-content
      operationId: geminiGenerateContent
      parameters:
        - name: model
          in: path
          required: true
          schema:
            type: string
            example: gemini-3.1-flash-image-preview
          description: Gemini 模型 ID（模型广场 / `GET /v1/models`）。生图请选图像模型。
        - name: key
          in: query
          required: false
          schema:
            type: string
          description: 可选的 Gemini 风格 API Key 查询参数。
        - name: x-goog-api-key
          in: header
          required: false
          schema:
            type: string
          description: 可选的 Gemini 风格 API Key 请求头。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GeminiGenerateContentRequest'
            examples:
              基础 generateContent:
                summary: 基础 generateContent
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 你好，Gemini
              图像理解:
                summary: 图像理解
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 为这张图片写一段说明
                        - inlineData:
                            mimeType: image/jpeg
                            data: /9j/4AAQ...
              文件 URI 分析:
                summary: 文件 URI 分析
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 请总结这份 PDF
                        - fileData:
                            mimeType: application/pdf
                            fileUri: https://example.com/doc.pdf
              Google Search 接地:
                summary: Google Search 接地
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 最近一场 F1 比赛谁赢了？
                  tools:
                    - googleSearch: {}
              函数调用（Agent）:
                summary: 函数调用（Agent）
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 巴黎天气怎么样？
                  tools:
                    - functionDeclarations:
                        - name: get_weather
                          description: 查询天气
                          parameters:
                            type: object
                            properties:
                              city:
                                type: string
                            required:
                              - city
      responses:
        '200':
          description: Gemini 响应 JSON（streamGenerateContent 时为 SSE）。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeminiGenerateContentResponse'
        '400':
          description: 请求体无效，或该模型不支持的参数。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OpenAIErrorResponse'
        '401':
          description: 缺少或无效的 API Key。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OpenAIErrorResponse'
              example:
                error:
                  message: '无效的令牌 (request id: ...)'
                  type: new_api_error
                  code: ''
        '403':
          description: 无权限（用户封禁、IP 白名单或分组访问限制）。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OpenAIErrorResponse'
        '429':
          description: 触发速率限制。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OpenAIErrorResponse'
        '500':
          description: 上游或网关内部错误。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OpenAIErrorResponse'
components:
  schemas:
    GeminiGenerateContentRequest:
      type: object
      required:
        - contents
      description: >-
        Gemini 原生 `generateContent` 请求体（由 Omniall AI 转发）。最少包含一个 `contents`
        轮次；生图时请设置 `generationConfig.responseModalities` 包含 `IMAGE`。
      properties:
        contents:
          type: array
          items:
            type: object
            properties:
              role:
                type: string
                enum:
                  - user
                  - model
                description: 本轮发送方。user=应用/终端用户输入；model=先前的 Gemini
              parts:
                type: array
                items:
                  type: object
                  properties:
                    text:
                      type: string
                      description: 文本提示词或说明。文生图写清画面；图生图写清如何基于参考图修改。
                      example: Describe this image
                    inlineData:
                      type: object
                      properties:
                        mimeType:
                          type: string
                          example: image/jpeg
                          description: 媒体 MIME 类型，如 `image/jpeg`、`image/png`、`image/webp`。
                        data:
                          type: string
                          description: Base64 原始字节，不要带 `data:` 前缀。
                          example: /9j/4AAQSkZJRgABAQ...
                      description: 内联二进制媒体（图片等），Base64 编码。图生图时在此放入参考图。
                    fileData:
                      type: object
                      properties:
                        mimeType:
                          type: string
                          description: 远程文件的 MIME 类型（规则同 `inlineData.mimeType`）。
                          example: application/pdf
                        fileUri:
                          type: string
                          description: 可公开访问的文件 URI/URL。须可无登录 cookie 下载。推荐 HTTPS。
                          example: https://example.com/report.pdf
                      description: 引用远程文件而非内联 Base64。适用于文件已可访问时
                description: 本轮的一个或多个内容部件。可混合文本与媒体（如文本+图片）。至少需要一个 part。
            description: 单轮对话。
          description: 发给 Gemini 的有序对话轮次。每项为 user 或 model 的一条消息。
        systemInstruction:
          type: object
          properties:
            parts:
              type: array
              items:
                type: object
                additionalProperties: true
              description: 系统指令部件（通常为一个文本部件）。
          description: 可选系统级指令，用于引导整次请求的模型行为（人设、输出
        tools:
          type: array
          description: >-
            模型可调用的可选工具。例如启用时用 `{ "googleSearch": {} }` 做接地/联网，或用 `{
            "functionDeclarations": [ ... ] }` 声明自有 Agent 函数。是否可用取决于模型/渠道。
          items:
            type: object
            additionalProperties: true
        toolConfig:
          type: object
          additionalProperties: true
          description: 控制工具选择方式（如函数调用模式）。透传为 Gemini toolConfig
        generationConfig:
          type: object
          properties:
            temperature:
              type: number
              description: 回答随机性。越高越有创意/多样；越低越稳定。常见范围
            topP:
              type: number
              description: 核采样：仅考虑累计概率质量达到 p 的 token。值越小输出越集中。
            topK:
              type: integer
              description: 仅从 top-K token 中采样。K 越小措辞越保守。
            maxOutputTokens:
              type: integer
              description: 模型响应可生成 token 的硬上限。长回答可增大；控成本/延迟可减小。
            responseMimeType:
              type: string
              description: 模型文本响应的期望 MIME 类型，如 text/plain，或面向 JSON 的 application/json
            responseModalities:
              type: array
              items:
                type: string
              description: 响应模态。生图请包含 `IMAGE`，常见为 `["TEXT","IMAGE"]` 或 `["IMAGE"]`。
              example:
                - TEXT
                - IMAGE
            thinkingConfig:
              type: object
              additionalProperties: true
              description: 支持思考/推理的模型的可选控制（视渠道/模型而定）。
            imageConfig:
              type: object
              description: >-
                生图输出配置（当 `responseModalities` 含 `IMAGE` 时生效）。网关也兼容
                `image_config` / snake_case。
              properties:
                aspectRatio:
                  type: string
                  description: 输出画幅，如 `1:1`、`16:9`、`9:16`、`3:4`、`4:3`。
                  enum:
                    - '1:1'
                    - '2:3'
                    - '3:2'
                    - '3:4'
                    - '4:3'
                    - '4:5'
                    - '5:4'
                    - '9:16'
                    - '16:9'
                    - '21:9'
                  example: '16:9'
                imageSize:
                  type: string
                  description: 输出分辨率档位：`1K` / `2K` / `4K`。
                  enum:
                    - 1K
                    - 2K
                    - 4K
                  example: 2K
          description: 本次生成的采样与输出控制。
        safetySettings:
          type: array
          items:
            type: object
            additionalProperties: true
          description: 按类别的安全阈值（骚扰、仇恨、色情、危险内容等）。需要时使用
    GeminiGenerateContentResponse:
      type: object
      properties:
        candidates:
          type: array
          items:
            type: object
            properties:
              content:
                type: object
                properties:
                  role:
                    type: string
                    description: 通常为 model。
                  parts:
                    type: array
                    items:
                      type: object
                      additionalProperties: true
                    description: 回答部件（`text`、内联图像、函数调用等）。
                description: 该候选的模型消息内容。
              finishReason:
                type: string
                description: 生成停止原因（如 STOP、MAX_TOKENS、SAFETY）。回答被截断时请检查
            description: 单个候选。
          description: 一个或多个候选回复。通常使用 `candidates[0]`。
        usageMetadata:
          type: object
          properties:
            promptTokenCount:
              type: integer
              description: 请求消耗的 token（contents + system + tools 等）。
            candidatesTokenCount:
              type: integer
              description: 响应生成的 token。
            totalTokenCount:
              type: integer
              description: prompt 与 candidates token 之和。
          description: 用于计费/排查的 token 用量。
      description: Gemini generateContent 响应。从第一个 candidate 的 `content.parts` 读取回答文本/图像。
    OpenAIErrorResponse:
      type: object
      description: 鉴权或请求失败时返回的 OpenAI 风格错误包络。
      required:
        - error
      properties:
        error:
          type: object
          required:
            - message
            - type
          properties:
            message:
              type: string
              description: 人类可读错误信息。网关可能附加 request id 便于排查。
            type:
              type: string
              description: 错误类型，常见为 `new_api_error`。
              example: new_api_error
            code:
              type: string
              description: 可选机器可读错误码（如 `access_denied`），可能为空字符串。
          description: 错误对象。
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: '使用来自 https://omniall.ai/dashboard 的 Authorization: Bearer sk-...'

````

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