使用 nvm (Node Version Manager) 安装:
|
1 2 3 4 5 6 7 |
# 安装 nvm curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash # 重新加载配置 source ~/.bashrc # 安装 Node.js nvm install 22 nvm use 22 |
|
1 2 3 4 5 |
# 全局安装 OpenClaw npm install -g openclaw
# 验证安装 openclaw --version |
|
1 2 |
# 运行初始化向导 openclaw onboard |
初始化过程会:
配置文件位置
|
1 |
~/.openclaw/openclaw.json |
编辑 openclaw.json,在 models.providers 中添加新的提供商配置:
示例 1: OpenAI 兼容 API (如 CrazyRouter)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
{ "models": { "mode": "merge", "providers": { "crazyrouter": { "baseUrl": "https://crazyrouter.com/v1", "apiKey": "sk-your-api-key-here", "api": "openai-completions", "models": [ { "id": "claude-opus-4-6", "name": "Claude Opus 4.6", "reasoning": false, "input": ["text"], "cost": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0 }, "contextWindow": 200000, "maxTokens": 8192 } ] } } } } |
示例 2: Anthropic 兼容 API (如 MiniMax)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
{ "models": { "providers": { "minimax": { "baseUrl": "https://api.minimax.io/anthropic", "api": "anthropic-messages", "models": [ { "id": "MiniMax-M2.1", "name": "MiniMax M2.1", "reasoning": false, "input": ["text"], "cost": { "input": 15, "output": 60, "cacheRead": 2, "cacheWrite": 10 }, "contextWindow": 200000, "maxTokens": 8192 } ] } } } } |
OpenClaw 支持两种主要的 API 格式:
openai-completions: OpenAI Chat Completions API 格式
适用于: OpenAI, Azure OpenAI, 各种 OpenAI 兼容服务
anthropic-messages: Anthropic Messages API 格式
适用于: Anthropic Claude, 兼容 Anthropic API 的服务
在 agents.defaults.model 中设置主模型:
|
1 2 3 4 5 6 7 8 9 |
{ "agents": { "defaults": { "model": { "primary": "crazyrouter/claude-opus-4-6" } } } } |
格式: <provider>/<model-id>
方法 1: 直接在配置文件中
|
1 2 3 4 5 6 7 8 9 |
{ "models": { "providers": { "your-provider": { "apiKey": "your-api-key-here" } } } } |
方法 2: 使用环境变量
|
1 |
export OPENCLAW_PROVIDER_APIKEY="your-api-key-here" |
方法 3: 使用认证配置
|
1 2 3 4 5 6 7 8 9 10 |
{ "auth": { "profiles": { "provider:default": { "provider": "your-provider", "mode": "api_key" } } } } |
获取 Bot Token
配置 Telegram
|
1 2 3 4 5 6 7 8 9 10 11 |
{ "channels": { "telegram": { "enabled": true, "botToken": "your-bot-token-here", "dmPolicy": "pairing", "groupPolicy": "open", "streamMode": "partial" } } } |
配置说明:
获取 Bot Token
配置 Discord
|
1 2 3 4 5 6 7 8 9 |
{ "channels": { "discord": { "enabled": true, "token": "your-discord-bot-token", "groupPolicy": "open" } } } |
创建飞书应用
安装飞书插件
|
1 |
openclaw plugin install @m1heng-clawd/feishu |
配置飞书
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
{ "channels": { "feishu": { "enabled": true, "appId": "cli_your_app_id", "appSecret": "your_app_secret", "connectionMode": "websocket", "dmPolicy": "pairing" } }, "plugins": { "entries": { "feishu": { "enabled": true } } } } |
|
1 2 3 4 5 6 7 8 |
# 启动 WebSocket Gateway (默认端口 18789) openclaw gateway --port 18789
# 后台运行 openclaw gateway --port 18789 &
# 绑定到所有网络接口 openclaw gateway --port 18789 --bind 0.0.0.0 |
|
1 2 3 4 5 6 7 8 |
# 查看健康状态 openclaw health
# 查看服务状态 openclaw status
# 查看会话列表 openclaw sessions |
|
1 2 3 4 5 |
# 停止 Gateway openclaw gateway stop
# 或使用 systemctl (如果配置了服务) systemctl --user stop openclaw-gateway.service |
|
1 2 3 4 5 |
# 升级到最新版本 npm update -g openclaw
# 验证版本 openclaw --version |
启动 Gateway 后,可以通过浏览器访问 WebUI:
|
1 |
http://localhost:18789 |
认证令牌: 在 openclaw.json 的 gateway.auth.token 中查看
原因: API 请求格式不兼容
解决方案:
错误: Address already in use
解决方案:
|
1 2 3 4 5 6 7 8 |
# 查找占用端口的进程 lsof -i :18789
# 停止现有服务 openclaw gateway stop
# 或使用不同端口 openclaw gateway --port 18790 |
警告: Duplicate plugin ID: feishu
解决方案: 这是已知的配置警告,不影响使用,可以忽略。
错误: disconnected [WS] unauthorized gateway token missing
解决方案:
检查清单:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
{ "meta": { "lastTouchedVersion": "2026.2.15", "lastTouchedAt": "2026-02-18T00:00:00.000Z" }, "models": { "mode": "merge", "providers": { "openai": { "baseUrl": "https://api.openai.com/v1", "apiKey": "sk-your-openai-key", "api": "openai-completions", "models": [ { "id": "gpt-4", "name": "GPT-4", "reasoning": false, "input": ["text"], "cost": { "input": 30, "output": 60, "cacheRead": 0, "cacheWrite": 0 }, "contextWindow": 128000, "maxTokens": 4096 } ] }, "anthropic": { "baseUrl": "https://api.anthropic.com", "apiKey": "sk-ant-your-key", "api": "anthropic-messages", "models": [ { "id": "claude-3-5-sonnet-20241022", "name": "Claude 3.5 Sonnet", "reasoning": false, "input": ["text"], "cost": { "input": 3, "output": 15, "cacheRead": 0.3, "cacheWrite": 3.75 }, "contextWindow": 200000, "maxTokens": 8192 } ] } } }, "agents": { "defaults": { "model": { "primary": "anthropic/claude-3-5-sonnet-20241022" }, "workspace": "~/.openclaw/workspace", "maxConcurrent": 4 } }, "channels": { "telegram": { "enabled": true, "botToken": "your-telegram-bot-token", "dmPolicy": "pairing", "groupPolicy": "open" } }, "gateway": { "port": 18789, "mode": "local", "bind": "loopback", "auth": { "mode": "token", "token": "your-generated-token" } } } |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# 查看帮助 openclaw --help openclaw gateway --help
# 查看配置 cat ~/.openclaw/openclaw.json
# 查看日志 tail -f ~/.openclaw/agents/main/sessions/*.jsonl
# 测试 API 连接 curl -X POST https://your-api-endpoint/v1/chat/completions \ -H "Authorization: Bearer your-api-key" \ -H "Content-Type: application/json" \ -d '{"model":"your-model","messages":[{"role":"user","content":"test"}]}'
# 备份配置 cp ~/.openclaw/openclaw.json ~/.openclaw/openclaw.json.backup |