> ## 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` 参数选择具体型号
- 请求 / 响应结构与 Anthropic API 对齐
- **系统提示词**：通过顶层 `system` 传入
- **思考模式**：全系列默认开启思考，思考内容通过 `content[type=thinking]` block 返回；只有 `glm-5.2` 可传 `thinking.type=disabled` 关闭
- **流式输出**：SSE 事件流
- **工具调用**：兼容 Anthropic `tool_use` / `tool_result` 流程
- **图像输入**：仅 `glm-5.3-flash` 真正支持，详见 `messages` 字段说明

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

<Note>
  **能否关闭思考因模型而异**：只有 `glm-5.2` 支持 `thinking.type: "disabled"`；`glm-5.3` 与 `glm-5.3-flash` 始终思考，传 `disabled` 会报错。从 `glm-5.2` 迁移时，请先移除写死的 `disabled` 再切换模型。
</Note>

<Warning>
  **图像输入只有 `glm-5.3-flash` 支持，且传给其他模型不会报错。** 向 `glm-5.3` 或 `glm-5.2` 传入图像内容块时，请求正常返回 200，但模型无法读取图片内容，只会依据文字部分作答，给出看似正常、实际与图片无关的回复，且多次请求结果并不一致。这类静默失败在生产环境中难以排查，需要图像理解时请选择 `glm-5.3-flash`。
</Warning>


## OpenAPI

````yaml cn/api-manual/language-series/glm/messages/messages-reference.json POST /v1/messages
openapi: 3.1.0
info:
  title: GLM 全模型接口 - Messages 完整参数
  description: >-
    通过 Anthropic Messages 协议调用智谱 GLM 系列文本模型的完整 API 参考。


    **收录模型**：`glm-5.3`、`glm-5.3-flash`、`glm-5.2`（用 `model` 参数选择）


    **兼容说明**：

    - 路径：`/v1/messages`（Anthropic 标准路径）

    - 请求 / 响应结构与 Anthropic Messages API 一致

    - 支持字段：`model` `messages`（必填）`system` `max_tokens` `temperature` `top_p`
    `top_k` `stop_sequences` `stream` `thinking` `tools` `tool_choice`
    `metadata`


    **通用能力**：

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

    - 思考模式：全系列**默认即开启思考**；思考内容通过 `content[type=thinking]` block 返回，并计入 output
    tokens

    - 提示词缓存：隐式前缀缓存，相同前缀的重复请求自动命中（体现在 `cache_read_input_tokens`），无需手动设置
    `cache_control`；`cache_creation_input_tokens` 恒为 0


    **模型间差异**（能否关闭思考、能否读图）见下方 `model`、`thinking` 与 `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` 参数选择具体型号

        - 请求 / 响应结构与 Anthropic API 对齐

        - **系统提示词**：通过顶层 `system` 传入

        - **思考模式**：全系列默认开启思考，思考内容通过 `content[type=thinking]` block 返回；只有
        `glm-5.2` 可传 `thinking.type=disabled` 关闭

        - **流式输出**：SSE 事件流

        - **工具调用**：兼容 Anthropic `tool_use` / `tool_result` 流程

        - **图像输入**：仅 `glm-5.3-flash` 真正支持，详见 `messages` 字段说明
      operationId: createMessageGLM
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateMessageRequest'
            examples:
              simple:
                summary: 最小可运行请求
                value:
                  model: glm-5.3
                  max_tokens: 1024
                  messages:
                    - role: user
                      content: 你好，世界
              system_prompt:
                summary: 含 system 提示词
                value:
                  model: glm-5.3
                  max_tokens: 2048
                  system: 你是一名资深中文技术编辑。
                  messages:
                    - role: user
                      content: 用三句话介绍 GLM-5.3。
              stop_sequences:
                summary: 自定义停止序列
                value:
                  model: glm-5.3
                  max_tokens: 50
                  thinking:
                    type: disabled
                  stop_sequences:
                    - '3'
                  messages:
                    - role: user
                      content: 'Output exactly: 1 2 3 4 5 6'
              tool_use:
                summary: 工具调用（Anthropic tool_use 风格）
                value:
                  model: glm-5.3
                  max_tokens: 2048
                  messages:
                    - role: user
                      content: 查询东京的天气并告诉我
                  tools:
                    - name: get_weather
                      description: 查询指定城市的当前天气
                      input_schema:
                        type: object
                        properties:
                          city:
                            type: string
                            description: 城市名，例如：Tokyo
                        required:
                          - city
                  tool_choice:
                    type: auto
              streaming:
                summary: 流式输出（SSE）
                value:
                  model: glm-5.3
                  max_tokens: 1024
                  stream: true
                  messages:
                    - role: user
                      content: 写一首关于春天的短诗
              disable_thinking_glm52_only:
                summary: 关闭思考模式（仅 glm-5.2 支持）
                value:
                  model: glm-5.2
                  max_tokens: 512
                  thinking:
                    type: disabled
                  messages:
                    - role: user
                      content: 一句话：日本首都是？
                description: >-
                  只有 `glm-5.2` 可关闭思考。`glm-5.3` 与 `glm-5.3-flash` 传
                  `thinking.type=disabled` 会报错。
              vision_flash:
                summary: 图像输入（仅 glm-5.3-flash）
                description: >-
                  `glm-5.3-flash` 原生支持视觉。图像用 `image` 内容块传入，`source` 支持 `base64`
                  与 `url` 两种方式。
                value:
                  model: glm-5.3-flash
                  max_tokens: 1024
                  messages:
                    - role: user
                      content:
                        - type: text
                          text: 这张图里是什么？
                        - type: image
                          source:
                            type: base64
                            media_type: image/png
                            data: <BASE64_ENCODED_IMAGE>
      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:
    CreateMessageRequest:
      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 上下文 |
            可关闭（`thinking.type=disabled`） | 不支持 |
          enum:
            - glm-5.3
            - glm-5.3-flash
            - glm-5.2
          example: glm-5.3
          default: glm-5.3
        max_tokens:
          type: integer
          description: |-
            指定生成内容长度的上限（Token 数）

            **说明**：
            - GLM 系列最大支持 **131,072 tokens**（128K）输出长度，建议设置不小于 `1024`
            - thinking 产生的 token 也计入该上限
            - 达到上限时内容会被截断，响应 `stop_reason=max_tokens`
          minimum: 1
          maximum: 131072
          example: 1024
        messages:
          type: array
          description: >-
            对话消息列表，按轮次 user / assistant 交替


            **说明**：

            - 至少包含 1 条消息

            - 最后一条消息通常为 `role=user`

            - 支持多轮上下文，模型会引用历史消息


            **图像输入**：只有 `glm-5.3-flash` 支持，通过 `content` 数组里的
            `{"type":"image","source":{...}}` 块传入。


            向 `glm-5.3` 或 `glm-5.2` 传入图像内容块**不会报错，但模型无法读取图片内容**。请求正常返回
            200，模型仅依据文字部分作答，给出看似正常、实际与图片无关的回复，且多次请求结果并不一致。


            这类静默失败在生产环境中难以排查，需要图像理解时请选择 `glm-5.3-flash`。
          items:
            $ref: '#/components/schemas/InputMessage'
          minItems: 1
        system:
          description: |-
            系统提示词，用于设定 AI 角色与行为

            **说明**：
            - 支持字符串或内容块数组
            - 通过顶层 `system` 字段传入（不要放进 messages）
            - 模型会遵循 system 约束
            - **过长的 system 可能被截断**：需要长上下文请放入 `messages`，不要全部堆在 `system`
          oneOf:
            - type: string
              example: You are a helpful assistant.
            - type: array
              description: 内容块数组格式的系统提示词。text 块可携带 cache_control
              items:
                type: object
                required:
                  - type
                  - text
                properties:
                  type:
                    type: string
                    enum:
                      - text
                  text:
                    type: string
                  cache_control:
                    $ref: '#/components/schemas/CacheControl'
        temperature:
          type: number
          description: |-
            采样温度

            **说明**：
            - 值越高输出越发散，越低越确定
            - 建议范围 `[0, 1]`
          minimum: 0
          maximum: 1
          example: 1
        top_p:
          type: number
          description: |-
            核采样阈值

            **说明**：
            - 范围 `[0, 1]`
            - 建议不要同时调整 temperature 与 top_p
          minimum: 0
          maximum: 1
          example: 0.9
        top_k:
          type: integer
          description: |-
            仅从概率最高的 K 个 token 中采样（Anthropic 特有参数）

            **说明**：
            - 值越小输出越确定，越大候选越多样
          minimum: 0
          example: 10
        stop_sequences:
          type: array
          description: >-
            自定义停止序列：生成命中其中任一字符串时停止


            **说明**：

            - 命中即截断，命中处之前的内容正常返回

            - **注意**：命中停止序列时，GLM 系列的 `stop_reason` 返回 `end_turn`（而非 Anthropic
            标准的 `stop_sequence`），响应也不含 `stop_sequence` 字段。若客户端依赖
            `stop_reason=="stop_sequence"` 判断命中，需特殊处理
          items:
            type: string
          example:
            - |+


        stream:
          type: boolean
          description: >-
            是否以 SSE 流式返回


            - `true`：Server-Sent Events 流式返回（标准 Anthropic 事件序列：message_start /
            content_block_start / content_block_delta / message_delta /
            message_stop）

            - `false`：完整响应后一次性返回（默认）
          default: false
          example: false
        thinking:
          type: object
          description: >-
            控制深度思考


            **说明**：

            - GLM 系列均为推理模型，**不传该字段时默认开启思考**

            - 开启时响应 `content` 数组中会出现 `type="thinking"` 的推理过程 block（按 output
            token 计费，`signature` 可能为空串）

            - **仅 `type` 二元开关有效**：`budget_tokens`、`effort` 等思考预算/等级参数不生效（会被忽略）


            **能否关闭因模型而异**：

            - `glm-5.2`：传 `{"type":"disabled"}` 可关闭思考，显著减少 output token

            - `glm-5.3` / `glm-5.3-flash`：**始终思考，不可关闭**。传 `disabled` 会报错


            **由此带来的结果：`glm-5.3` 系列在本端点无法降低思考开销。** 关不掉（`disabled` 报错），

            也调不小（`budget_tokens` 与 `effort` 均不生效，顶层 `reasoning_effort` 是 OpenAI
            协议字段、本端点忽略）。

            思考内容按 output token 计费，这部分开销在本端点是刚性的。


            **需要控制思考成本，请改用 [Chat Completions
            接口](../chat-completions/chat-completions-reference)** ——

            那边的 `reasoning_effort` 有 `low` / `high` / `max` 三档真实生效。`glm-5.2`
            不受此限，它在本端点可以直接关闭思考。


            **从 `glm-5.2` 迁移**：现有代码若写死 `thinking.type=disabled`，切换到 `glm-5.3`
            前必须移除该字段，否则请求直接失败。

            迁移后若原本依赖关闭思考来控制成本，本端点没有等效替代，需要一并考虑换用 Chat Completions 接口。
          required:
            - type
          properties:
            type:
              type: string
              enum:
                - enabled
                - disabled
              description: |-
                - 不传 thinking 字段：默认开启思考
                - `disabled`：关闭思考，直接回答
                - `enabled`：Anthropic 标准的显式开启值
        tools:
          type: array
          description: |-
            工具定义列表

            **说明**：
            - 遵循 Anthropic tool 定义规范
            - `input_schema` 使用 JSON Schema 对象
            - 模型会返回标准 `tool_use` block，`stop_reason=tool_use`
          items:
            $ref: '#/components/schemas/Tool'
        tool_choice:
          type: object
          description: 工具选择策略
          required:
            - type
          properties:
            type:
              type: string
              enum:
                - auto
                - none
              description: |-
                - `auto`：模型自动决定是否调用工具
                - `none`：禁止调用工具
        metadata:
          type: object
          description: 请求元数据
          properties:
            user_id:
              type: string
              description: 代表终端用户的唯一标识符，可用于按用户维度做监控与滥用检测（建议使用散列后的 ID）
    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
    InputMessage:
      type: object
      required:
        - role
        - content
      properties:
        role:
          type: string
          enum:
            - user
            - assistant
          description: |-
            消息发送方角色，user / assistant 交替

            - `user`：用户消息（也用于回传 `tool_result` block）
            - `assistant`：助手历史回复（可含 `text` / `thinking` / `tool_use` blocks）

            **不接受 `system`**：系统提示请走顶层 `system` 字段。
        content:
          description: >-
            消息内容


            **说明**：

            - 纯文本时直接传字符串

            - 结构化时传 content block 数组（`text` / `image` / `tool_use` /
            `tool_result` / `thinking`）

            - `image` 内容块**仅 `glm-5.3-flash` 支持**；传给其余模型不会报错，但模型无法读取图片内容
          oneOf:
            - type: string
            - type: array
              items:
                $ref: '#/components/schemas/ContentBlock'
    CacheControl:
      type: object
      description: >-
        提示词缓存标记


        **说明**：GLM 系列使用隐式缓存（按相同前缀自动建立，命中见
        `cache_read_input_tokens`，需预热），不依赖该显式标记；`cache_control`
        可正常传入但可能被忽略，不影响隐式缓存。
      required:
        - type
      properties:
        type:
          type: string
          enum:
            - ephemeral
          description: 缓存标记类型
    Tool:
      type: object
      required:
        - name
        - input_schema
      properties:
        name:
          type: string
          description: |-
            工具名称

            **说明**：
            - 只允许 `a-zA-Z0-9_-`
            - 最大 64 字符
        description:
          type: string
          description: 工具功能描述，供模型判断何时调用
        input_schema:
          type: object
          description: |-
            工具入参的 JSON Schema 对象

            **说明**：
            - `type` 必须为 `object`
            - 应声明 `properties` 与 `required`
        cache_control:
          $ref: '#/components/schemas/CacheControl'
    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 数量。相同前缀的重复请求自动命中，无需设置
            `cache_control`；命中部分按缓存价计费，显著低于未命中的输入价。首次请求为 0。
          example: 0
        prompt_tokens_details:
          type: object
          description: 输入 token 明细（缓存命中字段，GLM 系列一并返回）
          properties:
            cached_tokens:
              type: integer
              description: 命中缓存的输入 token 数
              example: 0
    ContentBlock:
      type: object
      description: |-
        消息内容块

        **支持 type**：
        - `text`：文本内容
        - `image`：图片（**仅 `glm-5.3-flash`**；传给其余模型不会报错，但模型无法读取图片内容）
        - `tool_use`：回带上一轮 assistant 工具调用
        - `tool_result`：工具执行结果
        - `thinking`：回带上一轮 assistant 思考内容
      required:
        - type
      properties:
        type:
          type: string
          enum:
            - text
            - image
            - tool_use
            - tool_result
            - thinking
        text:
          type: string
          description: 当 type=`text` 时的文本内容
        source:
          type: object
          description: |-
            图片来源（type=`image` 时必填，**仅 `glm-5.3-flash` 支持**）

            支持 `base64` 内联与 `url` 两种传入方式。
          required:
            - type
          properties:
            type:
              type: string
              enum:
                - base64
                - url
              description: |-
                图片传入方式

                - `base64`：内联图片数据
                - `url`：公网图片地址，由上游服务端自行下载
            media_type:
              type: string
              description: 图片 MIME 类型（`type=base64` 时必填）
              example: image/png
            data:
              type: string
              description: Base64 编码的图片数据（`type=base64` 时必填，不含 `data:` 前缀）
              example: iVBORw0KGgoAAAANSUhEUgAA...
            url:
              type: string
              description: 公网图片地址（`type=url` 时必填）
              example: https://example.com/photo.jpg
        id:
          type: string
          description: 工具调用 ID（tool_use 时必填）
        name:
          type: string
          description: 工具名（tool_use 时必填）
        input:
          type: object
          description: 工具入参（tool_use 时，JSON 对象）
        tool_use_id:
          type: string
          description: 对应的工具调用 ID（tool_result 时必填，回填到 tool_use.id）
        content:
          description: 工具执行结果（tool_result），字符串或 content block 数组
          oneOf:
            - type: string
            - type: array
              items:
                type: object
        thinking:
          type: string
          description: 回带的 assistant 思考过程内容（type=`thinking` 时使用）
        signature:
          type: string
          description: 回带的 thinking 内容签名，多轮续写时需原样回带（可能返回空串）
        cache_control:
          $ref: '#/components/schemas/CacheControl'
  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 鉴权。

````