> ## 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 全模型接口 - Messages 快速开始

> - 使用 Anthropic Messages 协议调用 GLM 系列模型，通过 `model` 参数选择具体型号
- 最少只需 `model`、`max_tokens` 与 `messages` 三个参数（`max_tokens` 在 Anthropic 协议中必填）
- 全系列 1M token 上下文窗口，最大输出 131,072 tokens
- 全系列**默认开启思考**，响应 `content` 里会带 `type="thinking"` 块，该部分计入 output token
- 需要流式输出、工具调用、图像输入等能力，请查看「完整参数」页

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

<Note>
  **GLM 系列默认开启思考**，响应 `content` 数组里会带 `type="thinking"` 块，这部分计入 output token。因此 `max_tokens` 不宜设得过小，建议不低于 1024，否则可能思考还没结束就被截断、拿不到正文。
</Note>


## OpenAPI

````yaml cn/api-manual/language-series/glm/messages/messages-quickstart.json POST /v1/messages
openapi: 3.1.0
info:
  title: GLM 全模型接口 - Messages 快速开始
  description: >-
    通过 Anthropic Messages 协议调用智谱 GLM 系列文本模型的快速开始示例。只需 `model`、`max_tokens` 与
    `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: Messages
    description: Anthropic Messages 协议接口
paths:
  /v1/messages:
    post:
      tags:
        - Messages
      summary: GLM 快速对话（全模型，Anthropic 兼容）
      description: >-
        - 使用 Anthropic Messages 协议调用 GLM 系列模型，通过 `model` 参数选择具体型号

        - 最少只需 `model`、`max_tokens` 与 `messages` 三个参数（`max_tokens` 在 Anthropic
        协议中必填）

        - 全系列 1M token 上下文窗口，最大输出 131,072 tokens

        - 全系列**默认开启思考**，响应 `content` 里会带 `type="thinking"` 块，该部分计入 output token

        - 需要流式输出、工具调用、图像输入等能力，请查看「完整参数」页
      operationId: glmMessagesQuick
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateMessageQuickRequest'
            examples:
              simple:
                summary: 最简调用
                value:
                  model: glm-5.3
                  max_tokens: 1024
                  messages:
                    - role: user
                      content: 你好，请用一句话介绍你自己
              flash:
                summary: 换用轻量模型
                description: '`glm-5.3-flash` 成本远低于 `glm-5.3`，适合高频调用。'
                value:
                  model: glm-5.3-flash
                  max_tokens: 1024
                  messages:
                    - role: user
                      content: 用一句话解释什么是 HTTP
              multi_turn:
                summary: 多轮对话
                value:
                  model: glm-5.3
                  max_tokens: 1024
                  messages:
                    - role: user
                      content: 推荐一门适合入门的编程语言
                    - role: assistant
                      content: 推荐 Python，语法简洁、生态丰富。
                    - role: user
                      content: 那学它大概要多久？
      responses:
        '200':
          description: 消息对象
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MessageResponse'
              examples:
                with_thinking:
                  summary: 默认含 thinking content block
                  value:
                    id: msg_0842a705-9d0b-4eaa-b12d-09a4106326c5
                    type: message
                    role: assistant
                    model: glm-5.3
                    content:
                      - type: thinking
                        thinking: 用户要求用一个词打招呼，回答 "Hi" 即可。
                        signature: ''
                      - type: text
                        text: Hi.
                    stop_reason: end_turn
                    usage:
                      input_tokens: 18
                      output_tokens: 101
                      cache_creation_input_tokens: 0
                      cache_read_input_tokens: 0
                      prompt_tokens_details:
                        cached_tokens: 0
                tool_use:
                  summary: 触发工具调用（stop_reason=tool_use）
                  value:
                    id: msg_067e85db-53df-43a1-bd38-09c53375f2f0
                    type: message
                    role: assistant
                    model: glm-5.3
                    content:
                      - type: tool_use
                        id: toolu_36b8a98e284c426799f08612
                        name: get_weather
                        input:
                          city: Tokyo
                    stop_reason: tool_use
                    usage:
                      input_tokens: 161
                      output_tokens: 11
                      cache_creation_input_tokens: 0
                      cache_read_input_tokens: 0
                      prompt_tokens_details:
                        cached_tokens: 0
        '400':
          description: 请求参数错误
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                type: error
                request_id: req_xxx
                error:
                  type: invalid_request_error
                  message: Invalid request
        '401':
          description: 身份验证错误
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                type: error
                error:
                  type: authentication_error
                  message: Authentication error
        '402':
          description: 配额不足
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                type: error
                error:
                  type: billing_error
                  message: Insufficient quota
        '403':
          description: 权限错误
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                type: error
                error:
                  type: permission_error
                  message: Permission denied
        '404':
          description: 模型或资源不存在
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                type: error
                error:
                  type: not_found_error
                  message: Model not found
        '429':
          description: 速率限制
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                type: error
                error:
                  type: rate_limit_error
                  message: Rate limited
        '500':
          description: 内部服务器错误
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '502':
          description: 上游服务错误
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '503':
          description: 服务暂时不可用
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    CreateMessageQuickRequest:
      title: Create Message Quick Request
      type: object
      required:
        - model
        - max_tokens
        - 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
        max_tokens:
          type: integer
          description: |-
            本次生成的最大 token 数，Anthropic 协议中为**必填**。

            注意：GLM 系列默认开启思考，思考内容也占用 output token，因此该值不宜过小，建议不低于 1024。
          minimum: 1
          maximum: 131072
          default: 1024
          example: 1024
        messages:
          type: array
          description: 对话消息列表，按时间顺序排列。至少包含 1 条消息。
          minItems: 1
          items:
            $ref: '#/components/schemas/MessageSimple'
    MessageResponse:
      type: object
      description: Anthropic 风格的消息响应
      properties:
        id:
          type: string
          description: 消息唯一 ID（格式形如 `msg_<uuid>`）
        type:
          type: string
          enum:
            - message
          description: 响应对象类型
        role:
          type: string
          enum:
            - assistant
        model:
          type: string
          description: 实际使用的模型
          example: glm-5.3
        content:
          type: array
          description: |-
            响应内容块列表

            **可能包含的 block type**：
            - `thinking`：推理过程（思考开启时，默认开启）
            - `text`：最终回答文本
            - `tool_use`：模型发起的工具调用
          items:
            $ref: '#/components/schemas/OutputContentBlock'
        stop_reason:
          type: string
          description: |-
            停止原因

            - `end_turn`：自然结束（命中 stop_sequences 时也返回此值）
            - `max_tokens`：达到 max_tokens 上限
            - `tool_use`：模型触发工具调用
          enum:
            - end_turn
            - max_tokens
            - tool_use
        usage:
          $ref: '#/components/schemas/AnthropicUsage'
    ErrorResponse:
      type: object
      properties:
        type:
          type: string
          enum:
            - error
        error:
          type: object
          properties:
            type:
              type: string
              description: >-
                错误类型（如 invalid_request_error / authentication_error /
                billing_error 等）
            message:
              type: string
              description: 错误描述
        request_id:
          type: string
          description: 请求追踪 ID
    MessageSimple:
      title: Message
      type: object
      required:
        - role
        - content
      properties:
        role:
          type: string
          enum:
            - user
            - assistant
          description: |-
            消息角色

            - `user`：用户输入
            - `assistant`：模型回复（多轮对话时携带）

            系统提示词请用顶层 `system` 字段传入，不放在 `messages` 里。
          example: user
        content:
          type: string
          description: 消息内容（纯文本）
          example: 你好，请用一句话介绍你自己
    OutputContentBlock:
      type: object
      description: 响应中的内容块
      properties:
        type:
          type: string
          enum:
            - text
            - thinking
            - tool_use
        text:
          type: string
          description: type=`text` 时的文本
        thinking:
          type: string
          description: type=`thinking` 时的推理过程文本
        signature:
          type: string
          description: type=`thinking` 时的签名（可能为空串）
        id:
          type: string
          description: type=`tool_use` 时的工具调用 ID
        name:
          type: string
          description: type=`tool_use` 时的工具名
        input:
          type: object
          description: type=`tool_use` 时模型生成的 JSON 入参
    AnthropicUsage:
      type: object
      description: Token 使用统计（Anthropic 规范）
      properties:
        input_tokens:
          type: integer
          description: 输入 token 数（未命中缓存部分）
          example: 18
        output_tokens:
          type: integer
          description: 输出 token 数（含 thinking）
          example: 101
        cache_creation_input_tokens:
          type: integer
          description: 缓存创建的输入 token 数（GLM 系列恒为 0）
          example: 0
        cache_read_input_tokens:
          type: integer
          description: 缓存命中的输入 token 数（隐式缓存命中时约为相同前缀的长度）
          example: 0
        prompt_tokens_details:
          type: object
          description: 输入 token 明细（缓存命中字段，GLM 系列一并返回）
          properties:
            cached_tokens:
              type: integer
              description: 命中缓存的输入 token 数
              example: 0
  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
        ```

        **备注**：EvoLink 对 `/v1/messages` 统一采用 Bearer Token 鉴权。

````