Skip to content

OpenClaw 接入

本页对应官方项目 openclaw/openclaw。OpenClaw 是可自托管的个人 AI 助手,可连接消息平台并运行常驻 Agent。

1. 安装 OpenClaw

OpenClaw 需要较新的 Node.js,推荐使用 Node.js 24。

bash
npm install -g openclaw@latest
bash
curl -fsSL https://openclaw.ai/install.sh | bash

验证安装并定位配置文件:

bash
openclaw --version
openclaw config file

2. 保存 API Key

bash
export AIR_ROUTER_API_KEY="sk-your-key"
powershell
$env:AIR_ROUTER_API_KEY="sk-your-key"

长期运行 Gateway 时,应把变量加入服务进程的环境配置,而不只是当前终端。

3. 配置模型 Provider

默认配置文件为 ~/.openclaw/openclaw.json。将所有 your-model-id 替换为控制台中的实际模型 ID:

json5
{
  agents: {
    defaults: {
      model: { primary: "air-router/your-model-id" },
      models: {
        "air-router/your-model-id": { alias: "Air Router" }
      }
    }
  },
  models: {
    mode: "merge",
    providers: {
      "air-router": {
        baseUrl: "https://www.air-router.com/v1",
        apiKey: "${AIR_ROUTER_API_KEY}",
        api: "openai-completions",
        timeoutSeconds: 300,
        models: [
          {
            id: "your-model-id",
            name: "Air Router Model",
            reasoning: false,
            input: ["text"],
            cost: {
              input: 0,
              output: 0,
              cacheRead: 0,
              cacheWrite: 0
            },
            contextWindow: 128000,
            maxTokens: 8192
          }
        ]
      }
    }
  }
}

contextWindowmaxTokensreasoning 是 OpenClaw 的客户端模型元数据。请根据控制台中的模型能力调整,它们不会提高服务端实际限制。

4. 检查并启动

先验证配置:

bash
openclaw config validate
openclaw doctor

使用 Gateway 时继续检查:

bash
openclaw gateway status
openclaw logs --follow

模型正常回复后,再继续配置 Telegram、Discord、Slack 等消息渠道。

常见问题

配置文件路径不一致

openclaw config file 输出为准。设置过 OPENCLAW_CONFIG_PATH 时,OpenClaw 会使用自定义路径。

环境变量在终端有效但 Gateway 无效

常驻 Gateway 进程不会自动继承你后来在终端中执行的 export。把 AIR_ROUTER_API_KEY 配置到启动 Gateway 的服务环境并重启进程。

模型上下文或推理能力异常

先确认模型 ID 正确,再根据实际模型调整 reasoningcontextWindowmaxTokens,不要直接复制其他模型的数值。