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

# glm-5.1

> 面向智谱 GLM 系列聊天模型的统一入口。

支持模型包括 `glm-5.1` 同一路径支持纯文本对话，以及包含 `image_url` 分片的图像理解请求。

本文档公开字段：`model`、`messages`、`stream`、`thinking`、`temperature`、`top_p`、`max_tokens`、`stop`、`tools`、`tool_choice`。



## OpenAPI

````yaml api-reference/zh-Hans/zmodelChat/zhipu/glm-5.1.json POST /v1/chat/completions
openapi: 3.0.1
info:
  title: 智谱对话补全
  version: 1.0.0
  description: >-
    智谱对话补全文档。公开统一入口为 `/v1/chat/completions`，适用于文本对话、流式输出、思考模式与函数工具调用。


    支持模型：`glm-5.1` 


    本文档覆盖的请求字段包括：`model`、`messages`、`stream`、`thinking`、`temperature`、`top_p`、`max_tokens`、`stop`、`tools`、`tool_choice`。
  license:
    name: Project License
    url: https://github.com/QuantumNous/new-api/blob/main/LICENSE
servers:
  - url: https://api.powertokens.ai
    description: Baze API 服务地址
security: []
tags:
  - name: Zhipu Chat
    description: 智谱 GLM 对话与视觉理解能力
paths:
  /v1/chat/completions:
    post:
      tags:
        - Zhipu Chat
      summary: 智谱对话补全
      description: >-
        面向智谱 GLM 系列聊天模型的统一入口。


        支持模型包括 `glm-5.1` 同一路径支持纯文本对话，以及包含 `image_url` 分片的图像理解请求。


        本文档公开字段：`model`、`messages`、`stream`、`thinking`、`temperature`、`top_p`、`max_tokens`、`stop`、`tools`、`tool_choice`。
      operationId: zhipuChatCompletionsGlm51
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
            examples:
              text_chat:
                summary: 纯文本对话
                value:
                  model: glm-5.1
                  messages:
                    - role: system
                      content: 你是一个简洁专业的助手。
                    - role: user
                      content: 请用三句话介绍一下向量数据库。
                  temperature: 0.7
                  max_tokens: 1024
              thinking_tool_call:
                summary: 思考模式与函数调用
                value:
                  model: glm-5.1
                  messages:
                    - role: user
                      content: 帮我查询上海今天的天气，并告诉我是否适合外出。
                  thinking:
                    type: enabled
                    clear_thinking: true
                  tools:
                    - type: function
                      function:
                        name: get_weather
                        description: 根据城市名称查询实时天气
                        parameters:
                          type: object
                          properties:
                            city:
                              type: string
                              description: 城市名称
                          required:
                            - city
                  tool_choice: auto
                  stream: true
      responses:
        '200':
          description: 调用成功。非流式模式返回 JSON；流式模式返回 SSE 事件流。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
              examples:
                success:
                  summary: 非流式成功响应
                  value:
                    id: chatcmpl_zhipu_123
                    object: chat.completion
                    created: 1775174400
                    model: glm-5.1
                    choices:
                      - index: 0
                        message:
                          role: assistant
                          content: 向量数据库是一种专门存储和检索向量表示的数据系统，常用于语义搜索、推荐和 RAG。
                          reasoning_content: 先给出定义，再补充典型场景。
                        finish_reason: stop
                    usage:
                      prompt_tokens: 42
                      completion_tokens: 31
                      total_tokens: 73
                      prompt_tokens_details:
                        cached_tokens: 0
            text/event-stream:
              schema:
                type: string
                description: >-
                  SSE 数据流。每个 `data:` 事件都可按 OpenAI Chat Completions Chunk
                  解析；结束时通常返回 `data: [DONE]`。
              examples:
                stream:
                  summary: 流式响应片段
                  value: >
                    data:
                    {"id":"chatcmpl_zhipu_123","object":"chat.completion.chunk","created":1775174400,"model":"glm-5.1","choices":[{"index":0,"delta":{"role":"assistant","content":"今天天气"},"finish_reason":null}]}


                    data:
                    {"id":"chatcmpl_zhipu_123","object":"chat.completion.chunk","created":1775174400,"model":"glm-5.1","choices":[{"index":0,"delta":{"content":"晴，适合外出。"},"finish_reason":"stop"}]}


                    data: [DONE]
        '400':
          description: 请求参数不合法。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                invalid_request:
                  summary: 参数错误
                  value:
                    error:
                      message: messages is required
                      type: invalid_request_error
                      param: messages
                      code: bad_request_body
        '401':
          description: 鉴权失败，例如未提供令牌或令牌无效。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                unauthorized:
                  summary: 未授权
                  value:
                    error:
                      message: 无效的令牌
                      type: api_error
                      param: ''
                      code: access_denied
        '429':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                quota_exceeded:
                  summary: 额度不足或速率受限
                  value:
                    error:
                      message: 当前账户额度不足，请稍后重试
                      type: api_error
                      code: insufficient_user_quota
                      param: ''
          description: 触发速率限制或账户额度不足。
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                internal_error:
                  summary: 内部处理失败
                  value:
                    error:
                      message: 服务内部处理失败，请稍后重试
                      type: api_error
                      code: gen_relay_info_failed
                      param: ''
          description: 服务端处理请求时发生内部错误。
        '502':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                bad_gateway:
                  summary: 服务响应异常
                  value:
                    error:
                      message: 模型服务返回了无效响应
                      type: api_error
                      code: bad_response_status_code
                      param: ''
          description: 模型服务返回异常响应。
        '503':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                service_unavailable:
                  summary: 服务暂不可用
                  value:
                    error:
                      message: 当前模型暂时无可用渠道，请稍后重试
                      type: api_error
                      code: get_channel_failed
                      param: ''
          description: 模型服务暂不可用，或当前模型暂时无可用渠道。
      security:
        - BearerAuth: []
components:
  schemas:
    ChatCompletionRequest:
      type: object
      required:
        - model
        - messages
      description: 智谱 chat completions 请求体。
      properties:
        model:
          type: string
          description: 模型名称。支持的模型包括 `glm-5.1`
          example: glm-5.1
          enum:
            - glm-5.1
        messages:
          type: array
          description: >-
            消息列表。请求中至少需要包含一条非 `system`、非 `assistant` 的消息；不能只传 `system` 消息或只传
            `assistant` 消息。
          items:
            $ref: '#/components/schemas/Message'
          minItems: 1
        stream:
          type: boolean
          description: 是否启用流式输出。为 `true` 时返回 `text/event-stream`。
          default: true
        thinking:
          $ref: '#/components/schemas/ThinkingConfig'
        temperature:
          type: number
          description: 采样温度，取值范围为 `[0, 1]`。
          minimum: 0
          maximum: 1
          default: 1
        top_p:
          type: number
          description: 核采样概率阈值，取值范围为 `[0.01, 1]`。
          minimum: 0.01
          maximum: 1
          default: 0.95
        max_tokens:
          type: integer
          description: 最大输出 token 数。
          minimum: 1
          maximum: 131072
        stop:
          type: array
          description: 停止词列表。当前仅支持单个停止词。
          items:
            type: string
          maxItems: 1
        tools:
          type: array
          description: 工具定义列表。当前仅支持 `function` 工具形态。
          items:
            $ref: '#/components/schemas/Tool'
          maxItems: 128
        tool_choice:
          $ref: '#/components/schemas/ToolChoice'
    ChatCompletionResponse:
      type: object
      description: 非流式对话补全响应。
      properties:
        id:
          type: string
          description: 响应 ID。
        object:
          type: string
          example: chat.completion
          description: 对象类型。
        created:
          type: integer
          format: int64
          description: Unix 时间戳（秒）。
        model:
          type: string
          description: 实际使用的模型名称。
        choices:
          type: array
          description: 模型返回的候选结果。
          items:
            $ref: '#/components/schemas/Choice'
        usage:
          $ref: '#/components/schemas/Usage'
    ErrorResponse:
      type: object
      required:
        - error
      description: 统一错误响应。
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              description: 错误信息。
            type:
              type: string
              description: 错误类型，例如 `invalid_request_error` 或 `api_error`。
            param:
              type: string
              description: 出错字段。
            code:
              type: string
              description: 错误码。
    Message:
      type: object
      required:
        - role
      description: 聊天消息对象。单独使用 `system` 或 `assistant` 消息作为整个请求输入会被上游拒绝。
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
            - tool
          description: 消息角色。
        content:
          description: 消息内容。
          type: string
        tool_calls:
          type: array
          description: 助手消息中的函数调用列表。
          items:
            $ref: '#/components/schemas/ToolCall'
        tool_call_id:
          type: string
          description: 工具消息对应的工具调用 ID。
    ThinkingConfig:
      type: object
      description: 思考模式配置。适用于支持 `thinking` 参数的模型。
      properties:
        type:
          type: string
          enum:
            - enabled
            - disabled
          default: enabled
          description: 是否启用思考模式。
        clear_thinking:
          type: boolean
          default: true
          description: 是否清理历史轮次中的 `reasoning_content`。
    Tool:
      type: object
      required:
        - type
        - function
      description: 函数工具定义。
      properties:
        type:
          type: string
          enum:
            - function
          description: 工具类型。当前仅支持 `function`。
        function:
          $ref: '#/components/schemas/FunctionDefinition'
    ToolChoice:
      type: string
      enum:
        - auto
      default: auto
      description: 工具选择策略。智谱该接口当前仅公开 `auto`。
    Choice:
      type: object
      description: 单个候选结果。
      properties:
        index:
          type: integer
          description: 候选下标。
        message:
          $ref: '#/components/schemas/ResponseMessage'
        finish_reason:
          type: string
          description: >-
            结束原因，例如
            `stop`、`tool_calls`、`length`、`sensitive`、`model_context_window_exceeded`
            或 `network_error`。
    Usage:
      type: object
      description: Token 使用统计。
      properties:
        prompt_tokens:
          type: integer
          description: 输入 token 数。
        completion_tokens:
          type: integer
          description: 输出 token 数。
        total_tokens:
          type: integer
          description: 总 token 数。
        prompt_tokens_details:
          $ref: '#/components/schemas/InputTokenDetails'
    ToolCall:
      type: object
      required:
        - id
        - type
        - function
      description: 模型返回的工具调用信息。
      properties:
        id:
          type: string
          description: 工具调用唯一 ID。
        type:
          type: string
          description: 工具类型，当前通常为 `function`。
        function:
          $ref: '#/components/schemas/FunctionCall'
    FunctionDefinition:
      type: object
      required:
        - name
        - description
      description: 函数定义。
      properties:
        name:
          type: string
          description: 函数名称。建议仅使用字母、数字、下划线和中划线。
          maxLength: 64
        description:
          type: string
          description: 函数用途说明，用于帮助模型选择何时调用。
        parameters:
          type: object
          description: JSON Schema 形式的入参定义。
    ResponseMessage:
      type: object
      description: 模型返回的消息对象。
      properties:
        role:
          type: string
          description: 消息角色，通常为 `assistant`。
        content:
          type: string
          nullable: true
          description: 模型可见输出内容。命中函数调用时该字段可能为空。
        tool_calls:
          type: array
          description: 模型生成的函数调用信息。
          items:
            $ref: '#/components/schemas/ToolCall'
    InputTokenDetails:
      type: object
      description: 输入 token 明细。
      properties:
        cached_tokens:
          type: integer
          description: 命中缓存的输入 token 数。
    FunctionCall:
      type: object
      required:
        - name
        - arguments
      description: 模型生成的函数调用。
      properties:
        name:
          type: string
          description: 函数名称。
        arguments:
          description: 函数参数。兼容字符串形式的 JSON，或直接返回的对象结构。
          oneOf:
            - type: string
            - type: object
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Token
      description: '在请求头中传入 `Authorization: Bearer <token>`。'

````