Skip to content

Z.AI 是 GLM 系列模型的 API 平台,OpenClaw 通过 zai provider 对接。配置时只需提供 ZAI_API_KEY,OpenClaw 支持自动检测对应端点(推荐)或强制指定 Coding Plan / 通用 API 的全球或国内区域。配置完成后可用 openclaw models list --all --provider zai 验证模型列表。

在 OpenClaw 中配置 Z.AI(GLM 模型)

Z.AI 是 GLM 系列模型的 API 平台,提供 REST API,使用 API Key 认证。在 Z.AI 控制台创建 API Key 后,OpenClaw 通过 zai provider 对接。

  • Provider:zai
  • 认证方式:ZAI_API_KEY
  • API 地址:Z.AI Chat Completions (Bearer auth)

开始配置

自动检测端点(推荐)

适合大多数用户。OpenClaw 从 Key 的前缀自动匹配对应的 Z.AI 端点并设置正确的 base URL。

  1. 运行 onboarding 向导
    bash
    openclaw onboard --auth-choice zai-api-key
  2. 设置默认模型
    json5
    {
      env: { ZAI_API_KEY: "sk-..." },
      agents: { defaults: { model: { primary: "zai/glm-5.1" } } },
    }
  3. 验证模型列表
    bash
    openclaw models list --all --provider zai

显式指定区域端点

适合需要强制使用特定 Coding Plan 或通用 API 区域的用户。

  1. 选择合适的 onboarding 选项
    bash
    # Coding Plan 全球(推荐 Coding Plan 用户使用)
    openclaw onboard --auth-choice zai-coding-global
    
    # Coding Plan 中国区
    openclaw onboard --auth-choice zai-coding-cn
    
    # 通用 API 全球
    openclaw onboard --auth-choice zai-global
    
    # 通用 API 中国区
    openclaw onboard --auth-choice zai-cn
  2. 设置默认模型
    json5
    {
      env: { ZAI_API_KEY: "sk-..." },
      agents: { defaults: { model: { primary: "zai/glm-5.1" } } },
    }
  3. 验证模型列表
    bash
    openclaw models list --all --provider zai

内置模型目录

OpenClaw 在插件清单中预置了 zai provider 的模型目录,未加载 provider 运行时也能通过只读方式查看已知 GLM 模型:

bash
openclaw models list --all --provider zai

当前内置模型包括:

模型引用备注
zai/glm-5.1默认模型
zai/glm-5
zai/glm-5-turbo
zai/glm-5v-turbo
zai/glm-4.7
zai/glm-4.7-flash
zai/glm-4.7-flashx
zai/glm-4.6
zai/glm-4.6v
zai/glm-4.5
zai/glm-4.5-air
zai/glm-4.5-flash
zai/glm-4.5v

提示:GLM 模型以 zai/<model> 格式引用(例如 zai/glm-5)。默认内置模型为 zai/glm-5.1

高级配置

未知 GLM-5 模型的前向解析

对于未知的 glm-5* 模型 ID,当 ID 符合当前 GLM-5 家族格式时,会从 glm-4.7 模板合成 provider 自有的元数据,实现前向解析。

工具调用流式 (tool_stream)

Z.AI 默认启用 tool_stream。要关闭它:

json5
{
  agents: {
    defaults: {
      models: {
        "zai/<model>": {
          params: { tool_stream: false },
        },
      },
    },
  },
}

思考及保留思考 (thinking / preserveThinking)

Z.AI 的思考行为遵循 OpenClaw 的 /think 控制。关闭 thinking 时,OpenClaw 会发送 thinking: { type: "disabled" },避免响应在可见文本前消耗输出配额用于 reasoning_content

保留思考(保留历史 reasoning_content)需要手动启用,因为 Z.AI 要求重放完整的历史 reasoning_content,会增加 prompt token。启用方法:

json5
{
  agents: {
    defaults: {
      models: {
        "zai/glm-5.1": {
          params: { preserveThinking: true },
        },
      },
    },
  },
}

启用后,若 thinking 开启,OpenClaw 会发送 thinking: { type: "enabled", clear_thinking: false } 并重放之前的 reasoning_content。高级用户仍可通过 params.extra_body.thinking 直接覆盖 provider 负载。

图像理解

内置 Z.AI 插件已注册图像理解能力,使用模型 glm-4.6v。此能力会根据配置的 Z.AI 认证自动解析,无需额外配置。

认证详情

  • Z.AI 使用 Bearer 认证,凭你的 API Key。
  • zai-api-key onboarding 选项会根据 Key 前缀自动匹配 Z.AI 端点。
  • 需要强制指定 API 表面时,使用显式区域选项(zai-coding-globalzai-coding-cnzai-globalzai-cn)。

相关链接

常见问题

ZAI_API_KEY 在哪里获取?

Z.AI 控制台 创建 API Key,通常以 sk- 开头。

自动检测端点和显式指定区域有什么区别?

自动检测是推荐的默认方式,OpenClaw 从 Key 前缀判断端点并自动配置 base URL;显式区域适用于需要强制使用 Coding Plan 或特定区域(全球/中国区)的场景,适合有明确 API 表面需求的用户。

GLM 模型在 OpenClaw 中如何引用?

通过 zai/<模型名> 格式,例如 zai/glm-5.1zai/glm-5。使用 openclaw models list --all --provider zai 可查看所有内置模型。