OpenClaw
OpenClaw 不支持通过环境变量 ANTHROPIC_BASE_URL 设置自定义 API 端点,必须通过配置文件的 models.providers 来配置。
前置条件
按照官方教程安装好并执行下面命令初始化:
bash
openclaw onboard --install-daemon配置文件位置:~/.openclaw/ 或 ~/.clawdbot/,取决于你用的版本。
步骤 1:编辑配置文件
bash
# 如果在 .openclaw 目录
nano ~/.openclaw/openclaw.json
# 或者在 openclaw 目录
nano ~/openclaw/openclaw.jsonpowershell
notepad $env:USERPROFILE\.openclaw\openclaw.json步骤 2:复制配置内容
把下面的 models / agents / auth 字段内容替换到配置文件。
agents.defaults.model.primary 字段是默认使用的模型,记得改成你想用的。
json
{
"models": {
"mode": "merge",
"providers": {
"api-proxy-gpt": {
"baseUrl": "https://www.dianlitoken.com/v1",
"api": "openai-completions",
"apiKey": "sk-你的API密钥",
"models": [
{
"id": "gpt-5.2",
"name": "GPT-5.2",
"reasoning": false,
"input": ["text"],
"cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0},
"contextWindow": 128000,
"maxTokens": 8192
}
]
},
"api-proxy-claude": {
"baseUrl": "https://www.dianlitoken.com",
"api": "anthropic-messages",
"apiKey": "sk-你的API密钥",
"models": [
{
"id": "claude-sonnet-4-6",
"name": "Claude Sonnet 4.6",
"reasoning": false,
"input": ["text"],
"cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0},
"contextWindow": 200000,
"maxTokens": 8192
}
]
},
"api-proxy-google": {
"baseUrl": "https://www.dianlitoken.com/v1beta",
"api": "google-generative-ai",
"apiKey": "sk-你的API密钥",
"models": [
{
"id": "gemini-3.1-pro-preview",
"name": "Gemini 3.1 Pro",
"reasoning": false,
"input": ["text"],
"cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0},
"contextWindow": 2000000,
"maxTokens": 8192
}
]
}
}
},
"agents": {
"defaults": {
"model": {
"primary": "api-proxy-gpt/gpt-5.2"
},
"models": {
"api-proxy-gpt/gpt-5.2": {"alias": "GPT-5.2"},
"api-proxy-claude/claude-sonnet-4-6": {"alias": "Claude Sonnet 4.6"},
"api-proxy-google/gemini-3.1-pro-preview": {"alias": "Gemini 3.1 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"}
}
}
}步骤 3:配置鉴权文件
bash
nano ~/.openclaw/agents/main/agent/auth.json
# 或
nano ~/openclaw/agents/main/agent/auth.jsonpowershell
notepad $env:USERPROFILE\.openclaw\agents\main\agent\auth.json替换为以下内容(把所有 sk-你的API密钥 改成你真实的 API Key):
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!
步骤 4:启动服务测试
bash
openclaw gateway --port 18789 --verbose然后浏览器打开:http://127.0.0.1:18789/#token=xxxxxx 测试聊天是否成功。
