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

# 文本对话

<Note>
  注：你可以在模型广场筛选查看[系统支持的所有对话模型列表](https://geekai.co/models)，对话模型请求/响应参数结构兼容 [OpenAI](https://platform.openai.com/docs/api-reference/chat/create)，切换模型时只需修改对应的模型名称即可，若模型请求/响应参数和 OpenAI 不一致，极客智坊底层会自动转换对齐。 除百度文心一言和讯飞星火模型外，其他所有平台支持函数调用（具体支持模型以平台限制为准）。 调用 GPTs 模型 API 时，需要将 gpt-4-gizmo-\* 中的 \* 替换成对应 GPTs 的 gizmo\_id，获取方式：从 GPTs URL 中提取，以 [https://chatgpt.com/g/g-bo0FiWLY7-researchgpt](https://chatgpt.com/g/g-bo0FiWLY7-researchgpt) 为例， 对应的 gizmo\_id 为 g-bo0FiWLY7。
</Note>

响应数据基础结构和 OpenAI 完全兼容，并在其基础上为适配其他模型新增功能，提供了对搜索引用链接(`citations`)、搜索计费次数(`billed_units`)、消息内容支持视频、图片/视频输入tokens、推理模式设置(`thinking`)的支持，响应结构会根据是否是流式输出而变化，可以参考下面的请求示例进行判断。

关于对话模型 API 调用示例，可以参考这里：[文本对话](https://docs.geekai.co/cn/docs/chat/base)。

### 请求/响应参数明细


## OpenAPI

````yaml openapi.yaml POST /chat/completions
openapi: 3.1.0
info:
  title: 极客智坊 API文档
  description: 极客智坊 API 消息接口规范文档
  version: 1.0.0
servers:
  - url: https://geekai.co/api/v1
    description: 国内代理入口
  - url: https://geekai.dev/api/v1
    description: 海外代理入口
security:
  - bearerAuth: []
  - apiKeyAuth: []
paths:
  /chat/completions:
    post:
      tags:
        - Chat
      summary: 对话完成接口
      description: 用于创建对话完成的接口，支持多种对话模型，可配置各种参数来控制响应的生成。
      operationId: createChatCompletion
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - model
                - messages
              properties:
                model:
                  type: string
                  description: 对话模型
                  default: gpt-5-mini
                messages:
                  type: array
                  description: 消息列表
                  items:
                    type: object
                    required:
                      - content
                      - role
                    properties:
                      content:
                        oneOf:
                          - type: string
                            description: 文本格式消息内容
                          - type: array
                            description: 多模态消息内容
                            items:
                              oneOf:
                                - $ref: '#/components/schemas/TextContentPart'
                                - $ref: '#/components/schemas/ImageContentPart'
                                - $ref: '#/components/schemas/AudioContentPart'
                                - $ref: '#/components/schemas/VideoContentPart'
                      role:
                        type: string
                        description: 消息角色
                        enum:
                          - system
                          - user
                          - assistant
                  example:
                    - content: 你是一个助手
                      role: system
                    - content: 你好
                      role: user
                enable_thinking:
                  type: boolean
                  description: 开启推理模式，仅支持切换思考模式的模型支持
                  default: false
                thinking:
                  type: object
                  description: 推理模式细节配置
                  properties:
                    include_thoughts:
                      type: boolean
                      description: 是否显示思考链内容，默认false
                      default: false
                    budget_tokens:
                      type: integer
                      description: 推理模式token预算
                      default: 16000
                    reasoning_effort:
                      type: string
                      description: 推理模式推理努力程度，适用于 OpenAI，GPT 5.1 起默认 none
                      enum:
                        - none
                        - minimal
                        - low
                        - medium
                        - high
                      default: medium
                    thinking_level:
                      type: string
                      description: 推理模式思考层级，适用于 Gemini 3 Pro，默认 high
                      enum:
                        - low
                        - high
                      default: high
                stream:
                  type: boolean
                  description: 是否返回流式响应，默认false
                  default: false
                background:
                  type: boolean
                  description: 是否开启后台任务模式，默认false，注意 stream 和 background 不能同时为 true
                  default: false
                enable_search:
                  type: boolean
                  description: 是否启用联网搜索，默认false
                  default: false
                search_config:
                  type: object
                  description: 联网搜索配置明细，仅智谱清言和不支持内置搜索工具的模型适用
                  properties:
                    engine:
                      type: string
                      description: 搜索引擎
                      enum:
                        - glm/search-std
                        - glm/search-pro
                        - glm/search-pro-sogou
                        - glm/search-pro-quark
                      default: glm/search-std
                    prompt:
                      type: string
                      description: 定制搜索结果处理的提示语
                    intent:
                      type: boolean
                      description: 启用搜索意图
                      default: false
                    count:
                      type: integer
                      description: 搜索结果数量, 取值范围1-50
                      default: 10
                    domain_filter:
                      type: string
                      description: 搜索结果域名过滤白名单
                    recency_filter:
                      type: string
                      description: 搜索结果时间过滤
                      enum:
                        - noLimit
                        - oneDay
                        - oneWeek
                        - oneMonth
                        - oneYear
                      default: noLimit
                    content_size:
                      type: string
                      description: 搜索结果摘要长度
                      enum:
                        - medium
                        - high
                      default: medium
                    return_result:
                      type: boolean
                      description: 是否返回搜索结果
                      default: false
                    result_sequence:
                      type: string
                      description: 搜索结果在对话响应中的位置，主要用于流式响应，位于真正回答内容之前还是之后
                      enum:
                        - before
                        - after
                      default: after
                    require_search:
                      type: boolean
                      description: 是否强制要求必须有搜索结果才进行回答
                      default: false
                    deepable:
                      type: boolean
                      description: 是否开启深度搜索（目前未生效）
                      default: false
                enable_url_context:
                  type: boolean
                  description: 是否启用 URL Context，默认false，仅部分 Gemini 模型生效
                  default: false
                temperature:
                  type: number
                  description: 温度参数，默认为代理模型默认值
                max_completion_tokens:
                  type: integer
                  description: 最大输出token数,默认设置为当前模型最大支持输出
                  example: 4096
                json_mode:
                  type: boolean
                  description: 是否设置响应格式为JSON对象，默认false
                  default: false
                response_format:
                  description: 指定响应输出格式，默认不指定为文本输出，如果设置该配置项会覆盖json_mode设置
                  oneOf:
                    - $ref: '#/components/schemas/ResponseFormatText'
                    - $ref: '#/components/schemas/ResponseFormatJsonObject'
                    - $ref: '#/components/schemas/ResponseFormatJsonSchema'
                modalities:
                  type: array
                  description: 输出的多模态类型列表
                  items:
                    type: string
                    enum:
                      - text
                      - image
                      - audio
                      - video
                audio:
                  type: object
                  description: 音频输出配置
                  properties:
                    voice:
                      type: string
                      description: 音色
                      default: alloy
                    format:
                      type: string
                      description: 音频格式
                      default: wav
                image:
                  type: object
                  description: 图像生成配置，仅 Gemini 3 Pro Image 适用
                  properties:
                    aspect_ratio:
                      type: string
                      description: 图片宽高比
                      enum:
                        - '1:1'
                        - '4:3'
                        - '3:4'
                        - '16:9'
                        - '9:16'
                    image_size:
                      type: string
                      description: 图像分辨率
                      enum:
                        - 1K
                        - 2K
                        - 4K
                      default: 1K
                tools:
                  type: array
                  description: 可调用的工具函数列表
                tool_choice:
                  description: 模型在生成响应时应如何选择使用哪个工具（或多个工具）
                  oneOf:
                    - $ref: '#/components/schemas/ToolChoiceOptions'
                    - $ref: '#/components/schemas/ToolChoiceTypes'
                    - $ref: '#/components/schemas/ToolChoiceFunction'
                tool_config:
                  type: object
                  description: 工具函数调用配置(兼容gemini)
                  properties:
                    functionCallingConfig:
                      type: object
                      description: 函数调用配置
                      properties:
                        mode:
                          type: string
                          description: 函数调用模式
                          enum:
                            - AUTO
                            - ANY
                            - NONE
                            - VALIDATED
                          default: AUTO
                        allowedFunctionNames:
                          type: array
                          description: 允许调用的函数名称列表
                          items:
                            type: string
                parallel_tool_calls:
                  type: boolean
                  description: 是否并发调用工具函数
                  default: true
                image_generation:
                  type: boolean
                  description: 是否强制出图，仅支持对话画图的模型支持
                  default: false
                stop:
                  type: array
                  description: 停止生成的触发词列表
                  items:
                    type: string
                logprobs:
                  type: boolean
                  description: 是否返回token概率
                  default: false
                top_logprobs:
                  type: integer
                  description: 每个位置返回的最可能token数
                  example: 2
                frequency_penalty:
                  type: number
                  description: 频率惩罚系数
                  default: 0
                presence_penalty:
                  type: number
                  description: 存在惩罚系数
                  default: 0
                top_p:
                  type: number
                  description: 核采样阈值
                  default: 1
                top_k:
                  type: integer
                  description: 最高概率采样数
                  default: 1
                seed:
                  type: integer
                  description: 随机数种子
                'n':
                  type: integer
                  description: 生成结果数量
                  default: 1
                metadata:
                  type: object
                  description: 自定义元数据
                sess_id:
                  type: string
                  description: 第三方应用自行实现的会话ID
                  format: uuid
                retries:
                  type: integer
                  description: 自动重试次数，默认0
                  default: 0
      responses:
        '200':
          description: 成功响应
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    description: 请求ID
                  status:
                    type: string
                    description: 请求状态，只有后台模式才会返回
                    enum:
                      - pending
                      - running
                      - succeed
                  created:
                    type: integer
                    description: 请求创建Unix时间戳
                  model:
                    type: string
                    description: 对话使用的模型
                  object:
                    type: string
                    description: 响应对象类型
                  choices:
                    type: array
                    description: 生成的对话列表
                    items:
                      type: object
                      properties:
                        index:
                          type: integer
                          description: 对话索引
                        message:
                          type: object
                          description: 生成的消息
                          properties:
                            role:
                              type: string
                              enum:
                                - assistant
                              description: 角色
                            content:
                              type: string
                              description: 响应内容
                            reasoning_content:
                              type: string
                              description: 推理内容
                            image:
                              type: string
                              description: 图片URL/Base64数据
                            audio:
                              type: object
                              description: 音频数据
                              properties:
                                id:
                                  type: string
                                  description: 音频唯一识别码
                                data:
                                  type: string
                                  description: Base64编码的音频数据
                                expires_at:
                                  type: integer
                                  description: 过期Unix时间戳
                                transcript:
                                  type: string
                                  description: 音频转录文本
                            tool_calls:
                              type: array
                              description: 工具函数调用列表
                              items:
                                type: object
                                properties:
                                  id:
                                    type: string
                                    description: 工具ID
                                  type:
                                    type: string
                                    enum:
                                      - function
                                    description: 工具类型
                                  function:
                                    type: object
                                    description: 工具函数
                                    properties:
                                      name:
                                        type: string
                                        description: 函数名称
                                      arguments:
                                        type: string
                                        description: 函数参数
                        finish_reason:
                          type: string
                          enum:
                            - stop
                            - length
                            - tool_calls
                            - content_filter
                            - stop_sequence
                            - error
                          description: 结束原因
                        logprobs:
                          type: object
                          description: 日志概率
                          properties:
                            content:
                              type: array
                              description: 消息内容标记列表
                              items:
                                type: object
                                properties:
                                  token:
                                    type: string
                                    description: 令牌
                                  logprob:
                                    type: number
                                    description: 对数概率
                                  bytes:
                                    type: array
                                    description: 表示 UTF-8 字节编码的整数列表，代表该标记
                                    items:
                                      type: integer
                                  top_logprobs:
                                    type: array
                                    description: 最有可能的标记及其在此位置的对数概率列表
                                    items:
                                      type: object
                                      properties:
                                        token:
                                          type: string
                                          description: 令牌
                                        logprob:
                                          type: number
                                          description: 对数概率
                                        bytes:
                                          type: array
                                          description: 表示 UTF-8 字节编码的整数列表，代表该标记
                                          items:
                                            type: integer
                  usage:
                    type: object
                    description: tokens消耗统计
                    properties:
                      prompt_tokens:
                        type: integer
                        description: 输入文本token数
                      completion_tokens:
                        type: integer
                        description: 生成文本token数
                      total_tokens:
                        type: integer
                        description: 总token数
                      billed_units:
                        type: integer
                        description: 计费次数（搜索）
                      prompt_tokens_details:
                        type: object
                        description: 输入文本消耗明细
                        properties:
                          text_tokens:
                            type: integer
                            description: 文本token数
                          audio_tokens:
                            type: integer
                            description: 音频token数
                          cached_tokens:
                            type: integer
                            description: 缓存token数
                          image_tokens:
                            type: integer
                            description: 图片token数
                          video_tokens:
                            type: integer
                            description: 视频token数
                          citation_tokens:
                            type: integer
                            description: 引用token数
                      completion_tokens_details:
                        type: object
                        description: 生成文本消耗明细
                        properties:
                          text_tokens:
                            type: integer
                            description: 文本token数
                          audio_tokens:
                            type: integer
                            description: 音频token数
                          reasoning_tokens:
                            type: integer
                            description: 推理token数
                          accepted_prediction_tokens:
                            type: integer
                            description: 接受的预测token数
                          rejected_prediction_tokens:
                            type: integer
                            description: 拒绝的预测token数
                  citations:
                    type: array
                    description: 引用的文献/链接列表
                    items:
                      type: string
                  system_fingerprint:
                    description: 系统指纹
                    type: string
        '400':
          $ref: '#/components/responses/ValidationError'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '500':
          $ref: '#/components/responses/StandardError'
components:
  schemas:
    TextContentPart:
      type: object
      required:
        - type
        - text
      properties:
        type:
          type: string
          enum:
            - text
          description: 内容类型
        text:
          type: string
          description: 文本内容
    ImageContentPart:
      type: object
      required:
        - type
        - image_url
      properties:
        type:
          type: string
          enum:
            - image_url
          description: 内容类型
        image_url:
          type: object
          required:
            - url
          properties:
            url:
              type: string
              description: 图片URL或Base64编码的图片数据
          description: 图片URL对象
    AudioContentPart:
      type: object
      required:
        - type
        - input_audio
      properties:
        type:
          type: string
          enum:
            - input_audio
          description: 内容类型
        input_audio:
          type: object
          required:
            - data
            - format
          properties:
            data:
              type: string
              description: Base64编码的音频数据
            format:
              type: string
              description: 内容类型，目前仅支持 wav/mp3 格式
          description: 音频数据对象
    VideoContentPart:
      type: object
      required:
        - type
        - video_url
      properties:
        type:
          type: string
          enum:
            - video_url
          description: 内容类型
        video_url:
          type: object
          required:
            - url
          properties:
            url:
              type: string
              description: 视频URL
          description: 视频URL对象
    ResponseFormatText:
      type: object
      title: Text
      description: |
        默认响应格式。用于生成文本响应。
      properties:
        type:
          type: string
          description: 正在定义的响应格式的类型。始终为 `text`。
          enum:
            - text
          x-stainless-const: true
      required:
        - type
    ResponseFormatJsonObject:
      type: object
      title: JSON object
      description: |
        JSON 对象响应格式。生成 JSON 响应的旧方法。
        建议对支持 `json_schema` 的模型使用它。请注意，模型不会在没有系统消息或用户消息指示的情况下生成 JSON。
      properties:
        type:
          type: string
          description: 正在定义的响应格式的类型。始终为 `json_object`。
          enum:
            - json_object
          x-stainless-const: true
      required:
        - type
    ResponseFormatJsonSchema:
      type: object
      title: JSON schema
      description: |
        JSON Schema 响应格式。用于生成结构化 JSON 响应。
        了解有关[结构化输出](/docs/guides/structured-outputs)的更多信息。
      properties:
        type:
          type: string
          description: 正在定义的响应格式的类型。始终为 `json_schema`。
          enum:
            - json_schema
          x-stainless-const: true
        json_schema:
          type: object
          title: JSON schema
          description: |
            结构化输出配置选项，包括 JSON Schema。
          properties:
            description:
              type: string
              description: |
                响应格式的描述，用于模型确定如何以该格式进行响应。
            name:
              type: string
              description: |
                响应格式的名称。必须是 a-z、A-Z、0-9，或包含下划线和破折号，且最大长度为 64。
            schema:
              $ref: '#/components/schemas/ResponseFormatJsonSchemaSchema'
            strict:
              type: boolean
              nullable: true
              default: false
              description: |
                是否在生成输出时启用严格的模式遵循。
                如果设置为 true，模型将始终遵循 `schema` 字段中定义的确切模式。
                当 `strict` 为 `true` 时，仅支持 JSON Schema 的子集。
                要了解更多信息，请阅读 [结构化输出指南](/docs/guides/structured-outputs)。
          required:
            - name
      required:
        - type
        - json_schema
    ToolChoiceOptions:
      type: string
      title: 工具选择模式
      description: |
        控制模型调用哪个（如果有）工具。

        `none` 表示模型将不调用任何工具，而是生成一条消息。

        `auto` 表示模型可以选择生成消息或调用一个或多个工具。

        `required` 表示模型必须调用一个或多个工具。
      enum:
        - none
        - auto
        - required
    ToolChoiceTypes:
      type: object
      title: 托管工具
      description: |
        表示模型应使用内置工具生成响应。
        [了解有关内置工具的更多信息](/docs/guides/tools)。
      properties:
        type:
          type: string
          description: |
            模型应使用的托管工具的类型。详细了解
            [内置工具](/docs/guides/tools)。

            允许的值为：
            - `file_search`
            - `web_search_preview`
            - `computer_use_preview`
            - `code_interpreter`
            - `mcp`
            - `image_generation`
          enum:
            - file_search
            - web_search_preview
            - computer_use_preview
            - web_search_preview_2025_03_11
            - image_generation
            - code_interpreter
            - mcp
      required:
        - type
    ToolChoiceFunction:
      type: object
      title: 函数工具
      description: |
        使用此选项强制模型调用特定函数。
      properties:
        type:
          type: string
          enum:
            - function
          description: 对于函数调用，类型始终为 `function`。
          x-stainless-const: true
        name:
          type: string
          description: 要调用的函数的名称。
      required:
        - type
        - name
    ResponseFormatJsonSchemaSchema:
      type: object
      title: JSON schema
      description: |
        响应格式的模式，描述为 JSON Schema 对象。
        了解有关如何构建 JSON Schema 的更多信息 [here](https://json-schema.org/)。
      additionalProperties: true
    Error:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
          description: 错误代码
          example: invalid_request
        message:
          type: string
          description: 错误信息描述
          example: 请求参数不合法
  responses:
    ValidationError:
      description: 参数验证错误
      content:
        application/json:
          schema:
            type: object
            properties:
              code:
                type: string
                example: validation_error
              message:
                type: string
                example: 参数验证失败
              details:
                type: object
                additionalProperties:
                  type: string
                example:
                  field: 错误描述
    Unauthorized:
      description: 未授权
      content:
        application/json:
          schema:
            type: object
            properties:
              code:
                type: string
                example: unauthorized
              message:
                type: string
                example: Invalid API key or token
    StandardError:
      description: 标准错误响应
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: API认证token
    apiKeyAuth:
      type: apiKey
      in: header
      name: GeekAI-API-Key
      description: API密钥认证

````