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

# GLM-5.4

> 在 MixRoute 调用 GLM-5.4，处理长上下文编程、推理与图片理解任务。

GLM-5.4 是智谱 Z.ai 面向复杂编程与长程智能体工作流的旗舰推理模型。它采用 Loop Transformer，在多轮推理计算中复用模型层。智谱公布的上下文窗口为 1M Token，最大输出为 128K Token，输出模态为文本。

MixRoute Console 列出的主入口是 `POST /v1/chat/completions`。运行示例前请设置 `MIXROUTE_API_KEY`。

## 快速示例

> [tab] cURL
>
> ```bash theme={null}
> curl https://api.mixroute.ai/v1/chat/completions \
>   -H "Authorization: Bearer $MIXROUTE_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "model": "glm-5.4",
>     "messages": [{"role": "user", "content": "只回复 OK。"}],
>     "max_tokens": 768
>   }'
> ```

> [tab] Python
>
> ```python theme={null}
> import os
>
> from openai import OpenAI
>
> client = OpenAI(
>     api_key=os.environ["MIXROUTE_API_KEY"],
>     base_url="https://api.mixroute.ai/v1",
> )
> response = client.chat.completions.create(
>     model="glm-5.4",
>     messages=[{"role": "user", "content": "只回复 OK。"}],
>     max_tokens=768,
> )
> print(response.choices[0].message.content)
> ```

## Chat Completions 参数

| 参数 | 类型 | 说明 |
| - | - | - |
| `model` | string | 必填，使用 `glm-5.4`。 |
| `messages` | array | 必填，可传文本字符串，或包含文本和图片的内容块数组。 |
| `max_tokens` | integer | 最大输出 Token 数；为思考和最终答案留出足够空间。 |
| `stream` | boolean | 设为 `true` 启用 SSE。正文从 `choices[].delta.content` 读取，`data: [DONE]` 表示流结束。 |
| `thinking.type` | string | 此模型只支持 `enabled`。 |
| `reasoning_effort` | string | 推理强度，可用 `low`、`high`、`max`。 |
| `tools` | array | 函数定义。模型请求调用工具时，读取 `choices[].message.tool_calls`。 |
| `response_format` | object | 设为 `{ "type": "json_object" }` 获取 JSON 输出。 |

非流式 Chat Completions 的最终答案位于 `choices[0].message.content`。如响应包含 `reasoning_content`，它与最终答案是两个字段。

## 图片输入

在同一个用户消息中传入 `text` 和 `image_url` 内容块。请将示例链接换成可访问的 HTTPS 图片地址，或使用 Base64 Data URL。该请求输出文本，不生成图片。

```json theme={null}
{
  "model": "glm-5.4",
  "messages": [
    {
      "role": "user",
      "content": [
        {"type": "text", "text": "描述这张图片里的主要元素。"},
        {"type": "image_url", "image_url": {"url": "https://example.com/image.png"}}
      ]
    }
  ],
  "max_tokens": 768
}
```

## Anthropic 兼容文本请求

使用 Anthropic 兼容客户端时，`POST /v1/messages` 也已在 MixRoute 上实测返回文本，但它不是 Console 列出的主入口。下方示例仅验证文本，不代表 Chat Completions 的参数或能力可以直接套用。

```bash theme={null}
curl https://api.mixroute.ai/v1/messages \
  -H "x-api-key: $MIXROUTE_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "glm-5.4",
    "max_tokens": 768,
    "messages": [{"role": "user", "content": "只回复 OK。"}]
  }'
```

从 `content` 中读取 `text` 类型块作为最终答案。请预留足够的输出 Token，让模型完成思考并返回正文。

## API 参考

* [创建对话请求（OpenAI）](https://mixroute.ai/docs/zh-Hans/api-reference/endpoint/chat-openai.md)
* [Messages（Anthropic）](https://mixroute.ai/docs/zh-Hans/api-reference/endpoint/messages.md)
* [智谱 GLM-5.4 官方模型说明](https://docs.z.ai/guides/llm/glm-5.4)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.