> ## 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-Hant/api-reference/endpoint/chat-openai.md)
* [Messages（Anthropic）](https://mixroute.ai/docs/zh-Hant/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.