平时做技术实践时,很多问题不是概念不会,而是细节没串起来。拿“OpenClaw 中转站配置”来说,它看着像小点,放到项目里常会牵出环境、配置、兼容性和维护成本。下面按实际采用顺序,把思路、关键写法和容易踩坑的地方讲清楚,便于大家直接对照操作。
本教程教你如何设置 OpenClaw 采用自定义 API 中转站。
适用系统: Windows / macOS / Linux
预计时间: 10 分钟
npm install -g openclaw
注意:Windows 用户如果提示 openclaw 不是命令,能够采用 clawdbot 代替。
openclaw onboard
按提示完成基础设置。
从实现思路看,OpenClaw 不兼容借助环境变量 ANTHROPIC_BASE_URL 来设置自定义 API 端点。必须借助设置文件的 models.providers 来设置。
| 系统 | 设置文件路径 |
|---|---|
| Windows | C:Users你的用户名.clawdbotclawdbot.json |
| macOS | ~/.clawdbot/clawdbot.json 或 ~/openclaw/clawdbot.json |
| Linux | ~/.clawdbot/clawdbot.json 或 ~/openclaw/clawdbot.json |
注意: 设置文件可能在 .clawdbot 或 openclaw 目录,取决于你的安装方式。
macOS/Linux:
# 如果在 .clawdbot 目录
cp ~/.clawdbot/clawdbot.json ~/.clawdbot/clawdbot.json.bak
# 或者在 openclaw 目录
cp ~/openclaw/clawdbot.json ~/openclaw/clawdbot.json.bak
Windows:
copy %USERPROFILE%.clawdbotclawdbot.json %USERPROFILE%.clawdbotclawdbot.json.bak
macOS/Linux:
# 如果在 .clawdbot 目录
nano ~/.clawdbot/clawdbot.json
# 或者在 openclaw 目录
nano ~/openclaw/clawdbot.json
Windows:
notepad %USERPROFILE%.clawdbotclawdbot.json
{
"models": {
"mode": "merge",
"providers": {
"api-proxy-gpt": {
"baseUrl": "https://apipro.maynor1024.live/v1",
"api": "openai-completions",
"apiKey": "sk-你的API密钥",
"models": [
{
"id": "gpt-4o",
"name": "GPT-4o",
"reasoning": false,
"input": ["text"],
"cost": {
"input": 0,
"output": 0,
"cacheRead": 0,
"cacheWrite": 0
},
"contextWindow": 128000,
"maxTokens": 8192
}
]
},
"api-proxy-claude": {
"baseUrl": "https://apipro.maynor1024.live",
"api": "anthropic-messages",
"apiKey": "sk-你的API密钥",
"models": [
{
"id": "claude-sonnet-4-5-20250929",
"name": "Claude Sonnet 4.5",
"reasoning": false,
"input": ["text"],
"cost": {
"input": 0,
"output": 0,
"cacheRead": 0,
"cacheWrite": 0
},
"contextWindow": 200000,
"maxTokens": 8192
}
]
},
"api-proxy-google": {
"baseUrl": "https://apipro.maynor1024.live/v1beta",
"api": "google-generative-ai",
"apiKey": "sk-你的API密钥",
"models": [
{
"id": "gemini-3-pro-preview",
"name": "Gemini 3 Pro",
"reasoning": false,
"input": ["text"],
"cost": {
"input": 0,
"output": 0,
"cacheRead": 0,
"cacheWrite": 0
},
"contextWindow": 2000000,
"maxTokens": 8192
}
]
}
}
},
"agents": {
"defaults": {
"model": {
"primary": "api-proxy-claude/claude-sonnet-4-5-20250929"
},
"models": {
"api-proxy-gpt/gpt-4o": {
"alias": "GPT-4o"
},
"api-proxy-claude/claude-sonnet-4-5-20250929": {
"alias": "Claude Sonnet 4.5"
},
"api-proxy-google/gemini-3-pro-preview": {
"alias": "Gemini 3 Pro"
}
}
}
},
"auth": {
"profiles": {
"api-proxy-gpt:default": {
"provider": "api-proxy-gpt",
"mode": "api_key"
},
"api-proxy-claude:default": {
"provider": "api-proxy-claude",
"mode": "api_key"
},
"api-proxy-google:default": {
"provider": "api-proxy-google",
"mode": "api_key"
}
}
}
}| 字段 | 说明 | 必需 |
|---|---|---|
baseUrl | 自定义 API 端点地址 | |
apiKey | 你的 API 密钥(直接写在这里) | |
api | API 类型 | |
models | 模型列表设置 |
重要:将所有 sk-你的API密钥 替换为你的真实 API Key!
| 系统 | 鉴权文件路径 |
|---|---|
| Windows | C:Users你的用户名.clawdbotagentsmainagentauth-profiles.json |
| macOS | ~/.clawdbot/agents/main/agent/auth-profiles.json 或~/openclaw/agents/main/agent/auth-profiles.json |
| Linux | ~/.clawdbot/agents/main/agent/auth-profiles.json 或~/openclaw/agents/main/agent/auth-profiles.json |
macOS/Linux:
# 如果在 .clawdbot 目录
nano ~/.clawdbot/agents/main/agent/auth-profiles.json
# 或者在 openclaw 目录
nano ~/openclaw/agents/main/agent/auth-profiles.json
Windows:
notepad %USERPROFILE%.clawdbotagentsmainagentauth-profiles.json
{
"version": 1,
"profiles": {
"api-proxy-gpt:default": {
"type": "api_key",
"provider": "api-proxy-gpt",
"key": "sk-你的API密钥"
},
"api-proxy-claude:default": {
"type": "api_key",
"provider": "api-proxy-claude",
"key": "sk-你的API密钥"
},
"api-proxy-google:default": {
"type": "api_key",
"provider": "api-proxy-google",
"key": "sk-你的API密钥"
}
},
"lastGood": {
"api-proxy-gpt": "api-proxy-gpt:default",
"api-proxy-claude": "api-proxy-claude:default",
"api-proxy-google": "api-proxy-google:default"
}
} 重要:将所有 sk-你的API密钥 替换为你的真实 API Key!
openclaw doctor
openclaw gateway
预期输出:
? OpenClaw Gateway starting...
? WebSocket server listening on ws://127.0.0.1:18789
? Web interface available at http://127.0.0.1:18789
✨ Gateway ready!
保持这个窗口打开!
打开新的终端窗口,运行:
openclaw tui
在 TUI 中输入:
你好
如果 AI 正常回复,设置成功!
打开浏览器访问:(链接已移除)
采用 openclaw onboard 结尾输出的 Token 登录。
| 命令 | 说明 |
|---|---|
/models | 查看所有可用模型 |
/model api-proxy-gpt/gpt-4o | 切换到 GPT-4o |
/model api-proxy-claude/claude-sonnet-4-5-20250929 | 切换到 Claude Sonnet 4.5 |
/model api-proxy-google/gemini-3-pro-preview | 切换到 Gemini 3 Pro |
/model status | 查看当前模型状态 |
/clear | 清空对话历史 |
/save | 保存当前会话 |
/quit | 退出 TUI |
原因: API Key 未设置或设置错误
解决步骤:
clawdbot.json 中的 apiKey 字段auth-profiles.json 中的 key 字段原因: 网络连接问题或 API 地址错误
解决步骤:
检查 baseUrl 是否正确:
(链接已移除)(链接已移除)(链接已移除)测试网络连接:
curl -I https://apipro.maynor1024.live
错误信息: Port 18789 already in use
Windows 解决:
netstat -ano | findstr :18789
taskkill /PID <PID> /F
macOS/Linux 解决:
lsof -i :18789
kill -9 <PID>
解决: 确保已经运行过 openclaw onboard 初始化
如果设置目录不存在,手动新建:
Windows:
mkdir %USERPROFILE%.clawdbotagentsmainagent
macOS/Linux:
mkdir -p ~/.clawdbot/agents/main/agent
# 或者
mkdir -p ~/openclaw/agents/main/agent
主配置文件:
C:Users你的用户名.clawdbotclawdbot.json
鉴权文件:
C:Users你的用户名.clawdbotagentsmainagentauth-profiles.json
主配置文件:
~/.clawdbot/clawdbot.json
或
~/openclaw/clawdbot.json
鉴权文件:
~/.clawdbot/agents/main/agent/auth-profiles.json
或
~/openclaw/agents/main/agent/auth-profiles.json
提示: 采用以下命令查找设置文件位置:
macOS/Linux:
find ~ -name "clawdbot.json" 2>/dev/null
Windows (PowerShell):
Get-ChildItem -Path $env:USERPROFILE -Filter "clawdbot.json" -Recurse -ErrorAction SilentlyContinue
config.json 的 models.providers[].apiKeyauth-profiles.json 的 profiles[].key/v1 后缀/v1beta 后缀设置步骤:
config.json(包含 apiKey)auth-profiles.json(包含 key)理解这一步时,到此这篇关于OpenClaw 中转站设置完全指南的文章就介绍到这了,更多相关OpenClaw 中转站设置内容请搜索脚本之家以前的文章或继续浏览下面的相关文章,希望大家以后多多兼容脚本之家!