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

> 使用 `model` 与 `input` 调用 GLM，支持 `glm-5.3`、`glm-5.3-flash`、`glm-5.3-flashx` 与 `glm-5.2`。建议设置 `max_output_tokens` 为 1024 或更高，为推理和正文预留空间。

更多示例与模型差异见[完整参数文档](./responses-reference)。

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

使用 `POST /v1/responses`，通过 `model` 选择 `glm-5.3`、`glm-5.3-flash`、`glm-5.3-flashx` 或 `glm-5.2`。最少需要 `model` 和 `input`；示例额外设置输出预算与推理档位，便于直接开始。

<Warning>
  **参数名称与 Chat Completions 不同**：输入使用 `input`，输出上限使用 `max_output_tokens`，推理强度使用 `reasoning.effort`。`glm-5.3`、`glm-5.3-flash` 与 `glm-5.3-flashx` 的实际思考档位为 `low`、`high`、`max`；兼容 `xhigh` → `max`、`medium` → `high`、`minimal` / `none` → `low`。

  **`minimal` 与 `none` 不会关闭 5.3 系列的思考**，思考 token 仍按输出计费。
</Warning>

## 读取正文

响应的 `output` 可能同时包含推理、正文和工具调用。遍历 `type="message"` 中的 `output_text` 内容块，不要假设第一项就是正文。

假设已将响应 JSON 解析为 `response`，可以这样提取文本：

```python theme={null}
text = "".join(
    part["text"]
    for item in response.get("output", [])
    if item.get("type") == "message"
    for part in item.get("content", [])
    if part.get("type") == "output_text"
)
print(text)
```

<Note>
  **为推理预留输出预算**：`max_output_tokens` 包含思考与正文，建议从 `1024` 起按任务调整。若 `status="incomplete"` 且 `incomplete_details.reason="max_output_tokens"`，请调高上限；预算耗尽时可能只有推理项，没有正文。
</Note>

工具调用、图像输入、SSE 处理与多轮对话，请查看[完整参数文档](./responses-reference)。


## OpenAPI

````yaml cn/api-manual/language-series/glm/responses/responses-quickstart.json POST /v1/responses
openapi: 3.1.0
info:
  title: GLM 全模型接口 - Responses 快速开始
  description: >-
    通过 OpenAI 兼容的 Responses 格式调用智谱 GLM 系列。支持
    glm-5.3、glm-5.3-flash、glm-5.3-flashx、glm-5.2；不同型号支持的可选能力有所不同。
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://direct.evolink.ai
    description: 生产环境（推荐）
  - url: https://api.evolink.ai
    description: 备用地址
security:
  - bearerAuth: []
tags:
  - name: Responses
    description: GLM Responses 接口
paths:
  /v1/responses:
    post:
      tags:
        - Responses
      summary: GLM Responses 快速调用
      description: >-
        使用 `model` 与 `input` 调用 GLM，支持
        `glm-5.3`、`glm-5.3-flash`、`glm-5.3-flashx` 与 `glm-5.2`。建议设置
        `max_output_tokens` 为 1024 或更高，为推理和正文预留空间。


        更多示例与模型差异见[完整参数文档](./responses-reference)。
      operationId: glmResponsesQuick
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ResponsesQuickRequest'
            examples:
              basic:
                summary: 基础文本对话
                value:
                  model: glm-5.3-flash
                  input: 请用一句话介绍你自己。
                  max_output_tokens: 1024
                  reasoning:
                    effort: low
              stream:
                summary: SSE 流式输出
                value:
                  model: glm-5.3-flash
                  input: 请用一句话介绍你自己。
                  max_output_tokens: 1024
                  reasoning:
                    effort: low
                  stream: true
              flashx:
                summary: 调用 GLM-5.3-FlashX
                value:
                  model: glm-5.3-flashx
                  input: 请用一句话介绍你自己。
                  max_output_tokens: 1024
                  reasoning:
                    effort: low
      responses:
        '200':
          description: 生成成功或返回不完整结果；检查 status。流式时返回 text/event-stream。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ResponsesResponse'
              example:
                id: response_demo
                object: response
                created_at: 1789971757
                model: glm-5.3-flash
                status: completed
                output:
                  - type: message
                    id: message_demo
                    status: completed
                    role: assistant
                    content:
                      - type: output_text
                        text: 你好，我是 GLM，可以帮你完成对话、写作和代码任务。
                        annotations: []
                usage:
                  input_tokens: 17
                  output_tokens: 24
                  total_tokens: 41
                  input_tokens_details:
                    cached_tokens: 0
                  output_tokens_details:
                    reasoning_tokens: 0
                error: null
            text/event-stream:
              schema:
                type: string
              example: >+
                event: response.output_text.delta

                data:
                {"type":"response.output_text.delta","item_id":"message_demo","output_index":0,"content_index":0,"delta":"你好"}


                event: response.completed

                data:
                {"type":"response.completed","response":{"id":"response_demo","object":"response","created_at":1789971757,"model":"glm-5.3-flash","status":"completed","output":[{"type":"message","id":"message_demo","status":"completed","role":"assistant","content":[{"type":"output_text","text":"你好","annotations":[]}]}],"usage":{"input_tokens":17,"output_tokens":3,"total_tokens":20},"error":null}}

        '400':
          description: 请求参数无效，例如缺少 input、推理参数格式错误，或所选模型不支持 previous_response_id。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: API Key 无效或已过期。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '402':
          description: 可用额度不足。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: 请求频率超限，请退避后重试。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: 服务端错误。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '503':
          description: 服务暂时不可用，请稍后重试。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    ResponsesQuickRequest:
      type: object
      properties:
        model:
          type: string
          description: >-
            选择 GLM 模型。四个型号均支持本接口的文本调用。


            | 模型 ID | 输入能力 | 推理参数注意事项 |

            |---|---|---|

            | `glm-5.3` | 文本 | 实际思考档位为 `low` / `high` / `max`；支持兼容取值，见
            `reasoning`；不能关闭思考 |

            | `glm-5.3-flash` | 文本、图像 | 同上；图像使用 `input_image` 内容块 |

            | `glm-5.3-flashx` | 文本、图像 | 同 `glm-5.3`；图像使用 `input_image` 内容块 |

            | `glm-5.2` | 文本 | 传入 `none` 仍可能产生推理 token，不保证关闭思考 |


            不同模型支持的能力有所不同，请查看对应型号的说明。
          enum:
            - glm-5.3
            - glm-5.3-flash
            - glm-5.3-flashx
            - glm-5.2
          default: glm-5.3-flash
          example: glm-5.3-flash
        input:
          description: >-
            必填。纯文本字符串，或 Responses 输入项数组。数组支持消息、回传的模型输出项与
            function_call_output。多轮对话可在每次请求中携带完整历史；系统提示词推荐作为 role=system
            消息放在数组首项。图片使用 input_image，仅 glm-5.3-flash 与 glm-5.3-flashx 支持。不要使用
            Chat Completions 的 messages / image_url 内容块格式。
          oneOf:
            - type: string
            - type: array
              items:
                $ref: '#/components/schemas/InputItem'
          example: 请用一句话介绍你自己。
        max_output_tokens:
          type: integer
          minimum: 1
          description: >-
            本次生成的输出 token 上限，包含推理 token。建议从 1024 起按任务调整。过小可能在思考阶段耗尽预算，只返回
            reasoning 项而没有正文；检查 status 和 incomplete_details。不要改写为 max_tokens。
          example: 1024
        stream:
          type: boolean
          default: false
          description: >-
            开启 SSE 流式返回。正文读取 response.output_text.delta 的 delta；成功终态为
            response.completed。遇到 response.incomplete、response.failed 或 error
            也应结束本轮并处理。不要只等待 [DONE] 或连接断开。
        reasoning:
          type: object
          properties:
            effort:
              type: string
              description: >-
                推理强度，建议使用 low。


                **`glm-5.3` / `glm-5.3-flash` / `glm-5.3-flashx` 的兼容规则**：


                | 传入值 | 实际思考档位 |

                |---|---|

                | `low` / `high` / `max` | 保持对应档位 |

                | `xhigh` | `max` |

                | `medium` | `high` |

                | `minimal` / `none` | `low`，仍会思考 |


                **`minimal` 与 `none` 不会关闭 5.3 系列的思考**，思考 token
                仍按输出计费。未识别的值保持原值，不提供兼容映射；请使用表中列出的值。`glm-5.2` 不适用上述兼容规则。


                glm-5.2 在本接口传入 none 仍可能产生推理 token，不能通过该值确保关闭思考。
              enum:
                - max
                - xhigh
                - high
                - medium
                - low
                - minimal
                - none
              example: low
          description: >-
            Responses 使用嵌套 reasoning.effort，而非顶层 reasoning_effort 或
            thinking。推理用量包含在 output_tokens 中；简单任务可能返回
            reasoning_tokens=0，这不代表支持关闭思考。
      required:
        - model
        - input
    ResponsesResponse:
      type: object
      properties:
        id:
          type: string
          description: 本轮响应 ID。用于 previous_response_id 时原样传入。
          example: response_demo
        object:
          type: string
          const: response
        created_at:
          type: integer
          description: 创建时间，Unix 秒。
        model:
          type: string
          example: glm-5.3-flash
        status:
          type: string
          description: >-
            completed 表示本轮生成结束，也可能仅有工具调用；incomplete 表示输出不完整。请同时检查 output 和
            error。
          enum:
            - completed
            - incomplete
            - failed
            - in_progress
            - queued
        output:
          type: array
          items:
            $ref: '#/components/schemas/OutputItem'
          description: >-
            有序输出项。遍历 type=message 的 content 中 type=output_text 的 text
            得到正文。reasoning 可能在正文之前；function_call 轮次可能没有正文。不要固定读取 output[0]。
        output_text:
          type: string
          description: 可选的正文聚合字段，可能缺失。通用客户端应遍历 output。
        usage:
          $ref: '#/components/schemas/Usage'
        error:
          type:
            - object
            - 'null'
          description: 响应错误；成功时通常为 null。
          additionalProperties: true
        incomplete_details:
          type: object
          properties:
            reason:
              type: string
              description: 输出被截断时，例如 max_output_tokens。
        metadata:
          type:
            - object
            - 'null'
          additionalProperties:
            type: string
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            type:
              type: string
            param:
              type:
                - string
                - 'null'
            code:
              type:
                - string
                - integer
                - 'null'
      required:
        - error
    InputItem:
      description: 消息、函数结果，或上一轮 output 中原样回传的项。回传工具结果时使用模型返回的 call_id，保留上一轮输出项的原始字段。
      oneOf:
        - $ref: '#/components/schemas/InputMessage'
        - $ref: '#/components/schemas/FunctionCallOutput'
        - type: object
          properties:
            type:
              type: string
              description: 回传的输出项类型。
              enum:
                - function_call
                - reasoning
                - web_search_call
            id:
              type: string
            call_id:
              type: string
            name:
              type: string
            arguments:
              type: string
              description: JSON 编码的参数字符串。
            status:
              type: string
            action:
              type: object
              additionalProperties: true
              description: web_search_call 的搜索或网页访问动作。
          required:
            - type
    OutputItem:
      type: object
      properties:
        type:
          type: string
          description: 常见类型为 message、reasoning、function_call、web_search_call。
          enum:
            - message
            - reasoning
            - function_call
            - web_search_call
        id:
          type: string
        status:
          type: string
        role:
          type: string
        content:
          type: array
          items:
            type: object
            properties:
              type:
                type: string
              text:
                type: string
              annotations:
                type: array
                items:
                  type: object
          description: message 中为 output_text；reasoning 中可能为 reasoning_text。
        summary:
          type: array
          items:
            type: object
            properties:
              type:
                type: string
              text:
                type: string
          description: 推理内容也可能通过 summary_text 返回。不要假设每个 reasoning 项都有 content。
        call_id:
          type: string
          description: 函数调用标识，用于回传结果。
        name:
          type: string
          description: 函数名。
        arguments:
          type: string
          description: 函数参数的 JSON 字符串；执行前自行解析并校验。
        action:
          type: object
          additionalProperties: true
          description: web_search_call 的搜索或网页访问动作。
      required:
        - type
    Usage:
      type: object
      properties:
        input_tokens:
          type: integer
          description: 总输入 token，包含缓存命中部分。
        output_tokens:
          type: integer
          description: 总输出 token，包含推理 token。
        total_tokens:
          type: integer
          description: 输入与输出 token 总和。
        input_tokens_details:
          type: object
          properties:
            cached_tokens:
              type: integer
              description: >-
                输入中命中缓存的 token 子集，不要重复加到 input_tokens 上。前缀缓存自动命中，不要求显式
                cache_control；命中量以实际返回值为准。
        output_tokens_details:
          type: object
          properties:
            reasoning_tokens:
              type: integer
              description: 输出中用于推理的 token 子集，不要重复计入 output_tokens。此明细可能缺失或为 0。
    InputMessage:
      type: object
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
        content:
          description: 文本字符串，或输入内容块数组。回传已有 assistant 输出时，也可以原样保留其 output_text 内容块。
          oneOf:
            - type: string
            - type: array
              items:
                oneOf:
                  - $ref: '#/components/schemas/InputText'
                  - $ref: '#/components/schemas/InputImage'
                  - $ref: '#/components/schemas/OutputText'
      required:
        - role
        - content
    FunctionCallOutput:
      type: object
      properties:
        type:
          type: string
          const: function_call_output
        call_id:
          type: string
          description: 原 function_call 的 call_id。
        output:
          type: string
          description: 函数结果，通常为 JSON 编码字符串。
      required:
        - type
        - call_id
        - output
    InputText:
      type: object
      properties:
        type:
          type: string
          const: input_text
        text:
          type: string
      required:
        - type
        - text
    InputImage:
      type: object
      properties:
        type:
          type: string
          const: input_image
        image_url:
          type: string
          description: >-
            图片公网 URL 或 Base64 Data URL，例如 PNG 图片的 data:image/png;base64,...。仅
            glm-5.3-flash / glm-5.3-flashx 支持图像输入；glm-5.3 和 glm-5.2 请使用纯文本。
      required:
        - type
        - image_url
    OutputText:
      type: object
      properties:
        type:
          type: string
          const: output_text
        text:
          type: string
        annotations:
          type: array
          items:
            type: object
      required:
        - type
        - text
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: 在 Authorization 请求头中传入 Bearer YOUR_API_KEY。

````