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

# Gemini 格式 - 调用工具内容生成

> - 适用于所有兼容 Gemini 原生格式模型的通用 generateContent API（含工具调用）
- 工具调用：支持函数声明，模型可调用定义的函数
- 多模态输入：支持文本 + 图像/音频/视频混合输入
- 生成配置：通过 generationConfig 控制温度、topP、topK、maxOutputTokens
- 安全设置：可配置内容安全阈值
- 支持流式和非流式响应




## OpenAPI

````yaml openapi/zh/gemini-format-tool-calling-generate-content.json POST /v1beta/models/{model}:generateContent
openapi: 3.1.0
info:
  title: Gemini Format - Tool Calling Generate Content
  version: '1.0'
servers:
  - url: https://api.aihubmax.com
security:
  - BearerAuth: []
paths:
  /v1beta/models/{model}:generateContent:
    post:
      tags:
        - Text Series > Gemini Format
      summary: Gemini Format - Tool Calling Generate Content
      description: |
        - 适用于所有兼容 Gemini 原生格式模型的通用 generateContent API（含工具调用）
        - 工具调用：支持函数声明，模型可调用定义的函数
        - 多模态输入：支持文本 + 图像/音频/视频混合输入
        - 生成配置：通过 generationConfig 控制温度、topP、topK、maxOutputTokens
        - 安全设置：可配置内容安全阈值
        - 支持流式和非流式响应
      operationId: gemini-format-tool-calling-generate-content
      parameters:
        - name: model
          in: path
          required: true
          schema:
            type: string
            example: gemini-2.5-flash
          description: 模型名称，如 gemini-2.5-flash
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GenerateContentRequest'
            examples:
              tool-calling-weather:
                summary: 天气查询
                description: 让模型调用天气查询函数
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 杭州今天的天气适合出去玩吗？
                  tools:
                    - functionDeclarations:
                        - name: get_weather
                          description: 获取指定城市的当前天气信息
                          parameters:
                            type: object
                            properties:
                              city:
                                type: string
                                description: 城市名称
                              unit:
                                type: string
                                enum:
                                  - celsius
                                  - fahrenheit
                                description: 温度单位
                            required:
                              - city
              tool-calling-search:
                summary: 网页搜索
                description: 让模型调用搜索函数查找信息
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 2026年最流行的前端框架是什么？
                  tools:
                    - functionDeclarations:
                        - name: web_search
                          description: 在互联网上搜索信息
                          parameters:
                            type: object
                            properties:
                              query:
                                type: string
                                description: 搜索关键词
                            required:
                              - query
              tool-calling-multi-functions:
                summary: 多函数声明
                description: 声明多个函数供模型选择调用
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 帮我查看明天成都的天气，如果天气好就在日历里添加一个户外烧烤活动
                  tools:
                    - functionDeclarations:
                        - name: get_weather
                          description: 获取天气预报
                          parameters:
                            type: object
                            properties:
                              city:
                                type: string
                                description: 城市名称
                              days:
                                type: integer
                                description: 预报天数
                            required:
                              - city
                        - name: create_calendar_event
                          description: 创建日历事件
                          parameters:
                            type: object
                            properties:
                              title:
                                type: string
                                description: 事件标题
                              date:
                                type: string
                                description: 日期（YYYY-MM-DD）
                              time:
                                type: string
                                description: 时间（HH:MM）
                            required:
                              - title
                              - date
      responses:
        '200':
          $ref: '#/components/responses/GenerateContentSuccess'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/PaymentRequired'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  schemas:
    GenerateContentRequest:
      type: object
      required:
        - contents
      properties:
        contents:
          type: array
          description: 对话内容列表
          items:
            type: object
            required:
              - role
              - parts
            properties:
              role:
                type: string
                description: 消息发送者的角色
                enum:
                  - user
                  - model
              parts:
                type: array
                description: 内容部分列表
                items:
                  type: object
                  properties:
                    text:
                      type: string
                      description: 文本内容
                    inlineData:
                      type: object
                      description: >-
                        内联二进制数据（base64 编码）。适用于：图片、音频、PDF、视频（base64）。视频形式下文件大小 ≤
                        100MB。
                      required:
                        - mimeType
                        - data
                      properties:
                        mimeType:
                          type: string
                          description: >-
                            IANA 标准 MIME 类型（Gemini 原生支持清单）：

                            -
                            **图片**：image/png、image/jpeg、image/webp、image/heic、image/heif

                            -
                            **音频**：audio/wav、audio/mp3、audio/aiff、audio/aac、audio/ogg、audio/flac

                            -
                            **视频**：video/mp4、video/mpeg、video/quicktime、video/avi、video/x-flv、video/mpg、video/webm、video/wmv、video/3gpp

                            -
                            **文档**：application/pdf（支持视觉理解：图表/布局/图像）、text/plain、text/markdown、text/html、text/xml（仅按纯文本提取）


                            > 实际可用的 MIME 类型以所选模型/渠道能力为准，部分渠道不支持视频 base64。
                          examples:
                            - image/png
                            - image/jpeg
                            - image/webp
                            - image/heic
                            - image/heif
                            - audio/wav
                            - audio/mp3
                            - audio/aiff
                            - audio/aac
                            - audio/ogg
                            - audio/flac
                            - video/mp4
                            - video/mpeg
                            - video/quicktime
                            - video/avi
                            - video/x-flv
                            - video/mpg
                            - video/webm
                            - video/wmv
                            - video/3gpp
                            - application/pdf
                            - text/plain
                            - text/markdown
                            - text/html
                            - text/xml
                        data:
                          type: string
                          description: Base64 编码的二进制数据
                    fileData:
                      type: object
                      description: >-
                        URL 引用。适用于：YouTube 视频、公开 HTTPS URL（图片 / PDF /
                        视频）。YouTube 场景 `mimeType` 可省略。
                      required:
                        - fileUri
                      properties:
                        fileUri:
                          type: string
                          description: 资源 URI：YouTube URL 或公开 HTTPS URL
                          examples:
                            - https://www.youtube.com/watch?v=9hE5-98ZeCg
                            - https://example.com/photo.jpg
                            - https://example.com/report.pdf
                        mimeType:
                          type: string
                          description: >-
                            IANA 标准 MIME 类型（同 inlineData 清单）：

                            -
                            **图片**：image/png、image/jpeg、image/webp、image/heic、image/heif

                            -
                            **音频**：audio/wav、audio/mp3、audio/aiff、audio/aac、audio/ogg、audio/flac

                            -
                            **视频**：video/mp4、video/mpeg、video/quicktime、video/avi、video/x-flv、video/mpg、video/webm、video/wmv、video/3gpp

                            -
                            **文档**：application/pdf（支持视觉理解：图表/布局/图像）、text/plain、text/markdown、text/html、text/xml（仅按纯文本提取）


                            > YouTube 链接场景可省略 `mimeType`；其他公开 HTTPS URL 建议显式声明。
                          examples:
                            - image/png
                            - image/jpeg
                            - image/webp
                            - image/heic
                            - image/heif
                            - audio/wav
                            - audio/mp3
                            - audio/aiff
                            - audio/aac
                            - audio/ogg
                            - audio/flac
                            - video/mp4
                            - video/mpeg
                            - video/quicktime
                            - video/avi
                            - video/x-flv
                            - video/mpg
                            - video/webm
                            - video/wmv
                            - video/3gpp
                            - application/pdf
                            - text/plain
                            - text/markdown
                            - text/html
                            - text/xml
                  description: >-
                    内容片段，三选一：text / inlineData / fileData。


                    **多模态输入支持**：

                    - 文本：`text`

                    - 图片 / 音频 / PDF（base64 内联）：`inlineData{mimeType, data}`

                    - 图片 / PDF（公开 HTTPS URL）：`fileData{fileUri, mimeType}`

                    - 视频：见下方「视频输入」


                    **视频输入（按模型/渠道能力）支持 3 种形式**：

                    1. **YouTube
                    链接**：`fileData{fileUri:"https://www.youtube.com/watch?v=..."}`，`mimeType`
                    可省略；视频必须为**公开视频**（private / unlisted 不支持）

                    2. **公开 HTTPS URL**：`fileData{fileUri:"https://...",
                    mimeType:"video/mp4"}`；视频文件大小 ≤ **100MB**（按下载后 base64
                    编码大小计算）

                    3. **内联 base64**：`inlineData{mimeType:"video/mp4",
                    data:"<base64>"}`；大小 ≤ **100MB**


                    > 不同模型 / 渠道支持的视频形式不同；部分渠道当前仅支持 YouTube 链接。视频大小超过
                    100MB，请联系管理员获取专用上传接口。
        systemInstruction:
          type: object
          description: 系统指令
          properties:
            parts:
              type: array
              description: 系统指令内容部分
              items:
                type: object
                properties:
                  text:
                    type: string
                    description: 系统指令文本
        generationConfig:
          type: object
          description: 生成配置
          properties:
            temperature:
              type: number
              description: 采样温度
              minimum: 0
              maximum: 2
            topP:
              type: number
              description: 核采样参数
              minimum: 0
              maximum: 1
            topK:
              type: integer
              description: Top-K 采样参数
            maxOutputTokens:
              type: integer
              description: 最大输出token数
            responseMimeType:
              type: string
              description: 响应 MIME 类型，如 text/plain 或 application/json
            responseSchema:
              type: object
              description: 响应 JSON Schema（当 responseMimeType 为 application/json 时使用）
        tools:
          type: array
          description: 可用工具列表
          items:
            type: object
            properties:
              functionDeclarations:
                type: array
                description: 函数声明列表
                items:
                  type: object
                  properties:
                    name:
                      type: string
                      description: 函数名称
                    description:
                      type: string
                      description: 函数描述
                    parameters:
                      type: object
                      description: 函数参数的 JSON Schema
        safetySettings:
          type: array
          description: 安全设置
          items:
            type: object
            properties:
              category:
                type: string
                description: 安全类别
                enum:
                  - HARM_CATEGORY_HARASSMENT
                  - HARM_CATEGORY_HATE_SPEECH
                  - HARM_CATEGORY_SEXUALLY_EXPLICIT
                  - HARM_CATEGORY_DANGEROUS_CONTENT
              threshold:
                type: string
                description: 安全阈值
                enum:
                  - BLOCK_NONE
                  - BLOCK_LOW_AND_ABOVE
                  - BLOCK_MEDIUM_AND_ABOVE
                  - BLOCK_ONLY_HIGH
    GenerateContentResponse:
      type: object
      properties:
        candidates:
          type: array
          description: 候选结果列表
          items:
            type: object
            properties:
              content:
                type: object
                description: 生成的内容
                properties:
                  parts:
                    type: array
                    items:
                      type: object
                      properties:
                        text:
                          type: string
                          description: 生成的文本内容
                          example: Hello! How can I help you today?
                  role:
                    type: string
                    description: 角色
                    enum:
                      - model
              finishReason:
                type: string
                description: 生成停止原因
                enum:
                  - STOP
                  - MAX_TOKENS
                  - SAFETY
                  - RECITATION
                  - OTHER
                example: STOP
              safetyRatings:
                type: array
                description: 安全评分列表
                items:
                  type: object
                  properties:
                    category:
                      type: string
                      description: 安全类别
                    probability:
                      type: string
                      description: 概率等级
        usageMetadata:
          type: object
          description: 用量统计
          properties:
            promptTokenCount:
              type: integer
              description: 提示token数
              example: 25
            candidatesTokenCount:
              type: integer
              description: 候选token数
              example: 150
            totalTokenCount:
              type: integer
              description: 总token数
              example: 175
    ErrorResponse400:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: 请求参数无效
            type:
              type: string
              example: invalid_request_error
    ErrorResponse401:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: API密钥无效
            type:
              type: string
              example: authentication_error
    ErrorResponse403:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: 访问被拒绝
            type:
              type: string
              example: permission_error
    ErrorResponse429:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: 请求频率超限
            type:
              type: string
              example: rate_limit_error
    ErrorResponse500:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: 服务器内部错误
            type:
              type: string
              example: server_error
  responses:
    GenerateContentSuccess:
      description: 内容生成响应
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/GenerateContentResponse'
    BadRequest:
      description: 请求错误
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse400'
    Unauthorized:
      description: 未授权
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse401'
    PaymentRequired:
      description: 余额不足
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse400'
    Forbidden:
      description: 禁止访问
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse403'
    TooManyRequests:
      description: 请求过多
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse429'
    InternalServerError:
      description: 服务器内部错误
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse500'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: |
        ## 所有接口均需要使用Bearer Token进行认证 ##

        使用时在请求头中添加：

        `Authorization: Bearer YOUR_API_KEY`

````