OpenClaw 接入
更新时间: 2026/08/27 10:13:38
OpenClaw 可以通过自定义 provider 接入 AIHub。推荐优先使用 OpenAI Chat Completions 兼容入口;如果工具配置需要 Anthropic Messages,也可以改用 AIHub /v1/messages。
OpenClaw 可以通过自定义 provider 接入云信大模型 API 平台(简称 AIHub)。推荐优先使用 OpenAI Chat Completions 兼容入口;如果工具配置需要 Anthropic Messages,也可切换至 AIHub /v1/messages 接口。
安装 OpenClaw
-
OpenClaw 需要 Node.js 22 或更高版本,请先确认本机环境:
bash
node --version -
执行以下命令安装 OpenClaw:
-
macOS/Linux 推荐使用安装脚本:
bash
curl -fsSL https://openclaw.ai/install.sh | bash -
Windows 可在 PowerShell 中使用安装脚本:
powershelliwr -useb https://openclaw.ai/install.ps1 | iex -
也可以使用 npm 安装:
bash
npm install -g openclaw@latest
-
-
安装完成后,确认命令和配置文件位置:
bash
openclaw --version openclaw config file默认配置文件通常位于
~/.openclaw/openclaw.json。- 修改前请备份现有配置,并将示例字段合并进去,请勿直接覆盖整个文件。
- 首次安装后如果进入初始化向导,可先完成基础设置;也可以执行
openclaw onboard重新进入向导。
配置接入凭证
OpenAI Chat Completions 入口(推荐):
-
将以下配置合并至
~/.openclaw/openclaw.json。json{ "models": { "mode": "merge", "providers": { "aihub-openai": { "baseUrl": "https://ai.yunxinapi.com/hub/v1", "api": "openai-completions", "apiKey": { "source": "env", "provider": "default", "id": "AIHUB_TOKEN" }, "models": [ { "id": "your-logical-model", "name": "Aihub logical model", "input": ["text"], "contextWindow": 16000, "maxTokens": 4096, "reasoning": false, "cost": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0 } } ] } } }, "agents": { "defaults": { "model": { "primary": "aihub-openai/your-logical-model" } } } } -
运行 OpenClaw 前,在终端中导出环境变量。
bashexport AIHUB_TOKEN="sk-..."
配置项说明:
| 配置项 | 说明 |
|---|---|
baseUrl |
AIHub 根地址 + /v1,例如 https://ai.yunxinapi.com/hub/v1 |
api |
固定为 openai-completions |
apiKey |
从环境变量 AIHUB_TOKEN 读取 |
models[].id |
AIHub 逻辑模型名 |
agents.defaults.model.primary |
provider/model 格式的默认模型 |
验证配置
bashopenclaw config validate
openclaw models status --plain
AIHUB_TOKEN="sk-..." openclaw infer model run \
--local \
--model aihub-openai/your-logical-model \
--prompt "只回复 OK"
如果控制台请求日志中出现 /v1/chat/completions 请求,说明 OpenClaw 已成功通过 AIHub 调用模型。
Anthropic Messages 入口
如需使用 Anthropic Messages 接口,将 provider 配置替换为:
json{
"models": {
"providers": {
"aihub-anthropic": {
"baseUrl": "https://ai.yunxinapi.com/hub/v1",
"api": "anthropic-messages",
"apiKey": {
"source": "env",
"provider": "default",
"id": "AIHUB_TOKEN"
},
"models": [
{
"id": "your-logical-model",
"name": "Aihub logical model"
}
]
}
}
}
}
切换后,实际请求将进入 $AIHUB_BASE_URL/v1/messages。
常见问题
| 现象 | 排查方向 |
|---|---|
| 配置校验失败 | JSON 语法错误,或覆盖丢失了 OpenClaw 原有字段。 |
/chat/completions 返回 404 |
baseUrl 缺少 /hub/v1,或误写成完整 endpoint。 |
401/unauthorized |
运行 OpenClaw 的进程未读取到 AIHUB_TOKEN。 |
| 找不到模型 | models[].id 或 agents.defaults.model.primary 与 AIHub 逻辑模型名不一致。 |
model not allowed/no candidate |
当前访问令牌未授权该模型,或模型无可用路由。 |
此文档是否对你有帮助?




