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

# GLM 全模型接口 - Chat Completions 快速开始

> - 使用 OpenAI Chat Completions 协议调用 GLM 系列模型，通过 `model` 参数选择具体型号
- 最少只需 `model` 与 `messages` 两个参数
- 全系列 1M token 上下文窗口，最大输出 131,072 tokens
- 全系列默认开启深度思考，推理过程通过 `reasoning_content` 返回
- 需要流式输出、工具调用、思考强度调节、图像输入等能力，请查看「完整参数」页

<Note>
  **BaseURL 说明**：默认 BaseURL 为 `https://direct.evolink.ai`，对文本模型支持更好，支持长连接；`https://api.evolink.ai` 是多模态主力地址，对文本模型作为备用地址使用。
</Note>


## OpenAPI

````yaml cn/api-manual/language-series/glm/chat-completions/chat-completions-quickstart.json POST /v1/chat/completions
openapi: 3.1.0
info:
  title: GLM 全模型接口 - Chat Completions 快速开始
  description: >-
    通过 OpenAI 兼容的 Chat Completions 接口调用智谱 GLM 系列文本模型的快速开始示例。只需 `model` 与
    `messages` 两个参数即可发起对话；完整参数请查看「完整参数」页。
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://direct.evolink.ai
    description: 生产环境（推荐）
  - url: https://api.evolink.ai
    description: 备用地址
security:
  - bearerAuth: []
tags:
  - name: 对话生成
    description: AI 对话生成相关接口
paths:
  /v1/chat/completions:
    post:
      tags:
        - 对话生成
      summary: GLM 快速对话（全模型）
      description: |-
        - 使用 OpenAI Chat Completions 协议调用 GLM 系列模型，通过 `model` 参数选择具体型号
        - 最少只需 `model` 与 `messages` 两个参数
        - 全系列 1M token 上下文窗口，最大输出 131,072 tokens
        - 全系列默认开启深度思考，推理过程通过 `reasoning_content` 返回
        - 需要流式输出、工具调用、思考强度调节、图像输入等能力，请查看「完整参数」页
      operationId: glmChatCompletionsQuick
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionQuickRequest'
            examples:
              simple:
                summary: 最简调用
                value:
                  model: glm-5.3
                  messages:
                    - role: user
                      content: 你好，请用一句话介绍你自己
              flash:
                summary: 换用轻量模型
                description: '`glm-5.3-flash` 成本远低于 `glm-5.3`，适合高频调用。'
                value:
                  model: glm-5.3-flash
                  messages:
                    - role: user
                      content: 用一句话解释什么是 HTTP
              multi_turn:
                summary: 多轮对话
                value:
                  model: glm-5.3
                  messages:
                    - role: user
                      content: 推荐一门适合入门的编程语言
                    - role: assistant
                      content: 推荐 Python，语法简洁、生态丰富。
                    - role: user
                      content: 那学它大概要多久？
      responses:
        '200':
          description: 对话生成成功
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
        '400':
          description: 请求参数错误
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: 400
                  message: Invalid request parameters
                  type: invalid_request_error
        '401':
          description: 未认证、Token无效或过期
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: 401
                  message: Invalid or expired token
                  type: authentication_error
        '402':
          description: 配额不足、需要充值
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: 402
                  message: Insufficient quota
                  type: insufficient_quota_error
                  fallback_suggestion: https://evolink.ai/dashboard/billing
        '403':
          description: 无权限访问
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: 403
                  message: Access denied for this model
                  type: permission_error
                  param: model
        '404':
          description: 资源不存在
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: 404
                  message: Specified model not found
                  type: not_found_error
                  param: model
                  fallback_suggestion: glm-5.3
        '429':
          description: 请求频率超限
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: 429
                  message: Rate limit exceeded
                  type: rate_limit_error
                  fallback_suggestion: retry after 60 seconds
        '500':
          description: 服务器内部错误
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: 500
                  message: Internal server error
                  type: internal_server_error
                  fallback_suggestion: try again later
        '502':
          description: 上游服务错误
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: 502
                  message: Upstream AI service unavailable
                  type: upstream_error
                  fallback_suggestion: try different model
        '503':
          description: 服务暂时不可用
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: 503
                  message: Service temporarily unavailable
                  type: service_unavailable_error
                  fallback_suggestion: retry after 30 seconds
components:
  schemas:
    ChatCompletionQuickRequest:
      title: Chat Completion Quick Request
      type: object
      required:
        - model
        - messages
      properties:
        model:
          type: string
          description: |
            要调用的模型：

            | 模型 ID | 定位 |
            |---|---|
            | `glm-5.3` | 旗舰模型，复杂软件工程与 Agent 任务能力全面进阶；1M 上下文 |
            | `glm-5.3-flash` | 轻量多模态模型，成本极低，原生支持图像输入；1M 上下文 |
            | `glm-5.2` | 上一代旗舰，复杂推理与超长上下文；1M 上下文 |
          enum:
            - glm-5.3
            - glm-5.3-flash
            - glm-5.2
          default: glm-5.3
          example: glm-5.3
        messages:
          type: array
          description: 对话消息列表，按时间顺序排列。至少包含 1 条消息。
          minItems: 1
          items:
            $ref: '#/components/schemas/MessageSimple'
    ChatCompletionResponse:
      type: object
      properties:
        id:
          type: string
          description: 任务 `ID`
          example: chatcmpl-a6613b56-c61c-94ba-9a9f-43d4cdc7d77a
        object:
          type: string
          description: 响应类型
          enum:
            - chat.completion
          example: chat.completion
        request_id:
          type: string
          description: 请求 `ID`（在请求中提供 `request_id` 时回传）
          example: req-7f3a2c1e8b9d4f0a
        created:
          type: integer
          description: 请求创建时间，`Unix` 时间戳（秒）
          example: 1777021417
        model:
          type: string
          description: 模型名称
          example: glm-5.3
        choices:
          type: array
          description: 模型响应列表
          items:
            $ref: '#/components/schemas/Choice'
        usage:
          $ref: '#/components/schemas/Usage'
        content_filter:
          type: array
          description: 内容安全相关信息
          items:
            $ref: '#/components/schemas/ContentFilter'
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: integer
              description: HTTP 状态错误代码
            message:
              type: string
              description: 错误描述信息
            type:
              type: string
              description: 错误类型
            param:
              type: string
              description: 相关参数名称
            fallback_suggestion:
              type: string
              description: 错误时的建议
    MessageSimple:
      title: Message
      type: object
      required:
        - role
        - content
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
          description: |-
            消息角色

            - `system`：系统提示词
            - `user`：用户输入
            - `assistant`：模型回复（多轮对话时携带）
          example: user
        content:
          type: string
          description: 消息内容（纯文本）
          example: 你好，请用一句话介绍你自己
    Choice:
      type: object
      properties:
        index:
          type: integer
          description: 结果索引
          example: 0
        message:
          $ref: '#/components/schemas/AssistantMessage'
        finish_reason:
          type: string
          description: |-
            推理终止原因

            - `stop`：自然结束或触发停止词
            - `tool_calls`：模型命中函数（工具调用）
            - `length`：达到 token 长度限制
            - `sensitive`：内容被安全审核拦截（请判断并决定是否撤回公开内容）
            - `network_error`：模型推理异常
            - `model_context_window_exceeded`：超出模型上下文窗口
          enum:
            - stop
            - tool_calls
            - length
            - sensitive
            - network_error
            - model_context_window_exceeded
          example: stop
    Usage:
      type: object
      description: 调用结束时返回的 Token 使用统计
      properties:
        prompt_tokens:
          type: integer
          description: 用户输入的 token 数量
          example: 24
        completion_tokens:
          type: integer
          description: 输出的 token 数量（含思维链 `reasoning_tokens` 部分）
          example: 346
        total_tokens:
          type: integer
          description: token 总数 = prompt_tokens + completion_tokens
          example: 370
        prompt_tokens_details:
          type: object
          description: 输入 token 详细分项
          properties:
            cached_tokens:
              type: integer
              description: 命中缓存的 token 数量
              example: 0
        completion_tokens_details:
          type: object
          description: 输出 token 详细分项
          properties:
            reasoning_tokens:
              type: integer
              description: 思维链（深度思考）产生的 token 数量，计入 `completion_tokens`
              example: 321
    ContentFilter:
      type: object
      description: 内容安全信息
      properties:
        role:
          type: string
          description: |-
            安全生效环节

            - `assistant`：模型推理
            - `user`：用户输入
            - `history`：历史上下文
          enum:
            - assistant
            - user
            - history
        level:
          type: integer
          description: 严重程度 `0-3`，`0` 表示最严重，`3` 表示轻微
          minimum: 0
          maximum: 3
    AssistantMessage:
      type: object
      properties:
        role:
          type: string
          description: 当前对话角色，默认 `assistant`
          enum:
            - assistant
          example: assistant
        content:
          type:
            - string
            - 'null'
          description: |-
            对话文本内容

            **说明**：调用工具（`tool_calls`）时可能为 `null`，否则返回模型回复内容
          example: 你好！我是 GLM-5.3，可以帮你完成对话、推理、写作、代码等多种任务。
        reasoning_content:
          type: string
          description: |-
            思维链内容

            **说明**：在 `thinking` 开启时返回，记录模型的推理过程
          example: 让我先分析这个问题……
        tool_calls:
          type: array
          description: 生成的工具调用信息（当模型决定调用工具时返回）
          items:
            type: object
            properties:
              id:
                type: string
                description: 工具调用的唯一标识符
              type:
                type: string
                description: 工具调用类型
                enum:
                  - function
              function:
                type: object
                description: 函数调用信息（包含生成的函数名称和 JSON 格式参数）
                properties:
                  name:
                    type: string
                    description: 生成的函数名称
                  arguments:
                    type: string
                    description: 函数调用参数的 JSON 格式字符串，调用函数前请验证参数
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: |-
        ##所有接口均需要使用 Bearer Token 进行认证##

        **获取 API Key**：

        访问 [API Key 管理页面](https://evolink.ai/dashboard/keys) 获取您的 API Key

        **使用时在请求头中添加**：
        ```
        Authorization: Bearer YOUR_API_KEY
        ```

````