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

# GLM-5.1

> 智谱当前旗舰 —— 在 GLM-5 基础上加入视觉支持、更紧的 tool-call 生成。

**厂商：** Zhipu（智谱）
**Model ID：** `glm-5-1`
**能力：** 128K 上下文 · 视觉 · 工具调用 · 流式 · 结构化输出 · CJK 原生
**计价：** 按 token，中端档（[实时费率](https://bytespike.ai/pricing#text)）

GLM-5.1 是 GLM-5 的打磨版 —— 同样的上下文窗口，加上视觉支持、更紧的 tool-call
参数生成，以及在中文市场代码生成上可量化的质量提升。网关上中文市场新项目的
默认起点。

## Request

```bash theme={null}
curl https://llm.bytespike.ai/v1/chat/completions \
  -H "Authorization: Bearer $BYTESPIKE_API_KEY" \
  -H "content-type: application/json" \
  -d '{
    "model": "glm-5-1",
    "messages": [{"role": "user", "content": "用中文写一份产品发布公告。"}]
  }'
```

### Body 参数

| 字段                | 类型      | 必填 | 默认    | 说明                                  |
| ----------------- | ------- | -- | ----- | ----------------------------------- |
| `model`           | string  | 是  | —     | `glm-5-1`                           |
| `messages`        | array   | 是  | —     | 原生支持 CJK。视觉通过 `image_url` block 传入。 |
| `max_tokens`      | integer | 否  | 模型上限  | 最大值：16384。                          |
| `tools`           | array   | 否  | —     | 支持 function calling（并行）。            |
| `response_format` | object  | 否  | —     | JSON / 结构化输出。                       |
| `stream`          | boolean | 否  | false | SSE 流式。                             |

## Response

```json theme={null}
{
  "id": "chatcmpl-…",
  "object": "chat.completion",
  "model": "glm-5-1",
  "choices": [{"index": 0, "message": {"role": "assistant", "content": "..."}, "finish_reason": "stop"}],
  "usage": {"prompt_tokens": 28, "completion_tokens": 412, "total_tokens": 440}
}
```

## 代码示例

<CodeGroup>
  ```bash cURL theme={null}
  curl https://llm.bytespike.ai/v1/chat/completions \
    -H "Authorization: Bearer $BYTESPIKE_API_KEY" \
    -H "content-type: application/json" \
    -d '{"model": "glm-5-1", "messages": [{"role": "user", "content": "写产品发布公告"}]}'
  ```

  ```python Python theme={null}
  from openai import OpenAI

  client = OpenAI(base_url="https://llm.bytespike.ai/v1", api_key="$BYTESPIKE_API_KEY")
  resp = client.chat.completions.create(
      model="glm-5-1",
      messages=[{"role": "user", "content": "用中文写一份产品发布公告。"}],
  )
  print(resp.choices[0].message.content)
  ```

  ```javascript Node theme={null}
  import OpenAI from "openai"

  const client = new OpenAI({
    baseURL: "https://llm.bytespike.ai/v1",
    apiKey: process.env.BYTESPIKE_API_KEY,
  })
  const resp = await client.chat.completions.create({
    model: "glm-5-1",
    messages: [{ role: "user", content: "用中文写一份产品发布公告。" }],
  })
  console.log(resp.choices[0].message.content)
  ```
</CodeGroup>

## 流式与缓存

`"stream": true` 走 SSE。自动 prompt caching。

## Errors

| Code                        | 触发条件 | 是否计费    |
| --------------------------- | ---- | ------- |
| 400 / 401 / 402 / 422 / 429 | 标准   | 否       |
| 5xx                         | 上游   | 否（自动重试） |

## 何时选用

* 文本 + 视觉混合输入的中文市场新项目。
* CJK 语言下的工具使用类 agent。
* 想要更长上下文，见 [Kimi K2.6](/zh/api-reference/text/kimi-k2-6)。
* 中文重代码工作，见 [DeepSeek V4 Pro](/zh/api-reference/text/deepseek-v4-pro)。

## 限制

| 项                 | 值            |
| ----------------- | ------------ |
| 上下文窗口             | 128K tokens  |
| 最大输出              | 16384 tokens |
| 支持工具调用            | 是（并行）        |
| 支持视觉              | 是            |
| 支持流式              | 是            |
| 支持 prompt caching | 自动           |
