Appearance
OpenClaw 接入指南
OpenClaw 是 Anthropic 推出的命令行编码助手。通过 Mirrorstages,你可以以更低的成本使用 OpenClaw 接入多种模型。
前提条件
- 已安装 OpenClaw(
npm install -g openclaw) - 已获取 Mirrorstages API Key(参考 API Keys 说明)
配置文件位置
OpenClaw 的配置文件路径为 ~/.openclaw/openclaw.json:
- macOS:
/Users/你的用户名/.openclaw/openclaw.json - Linux:
/home/你的用户名/.openclaw/openclaw.json - Windows:
C:\Users\你的用户名\.openclaw\openclaw.json
如果文件不存在,请先创建:
bash
# macOS / Linux
mkdir -p ~/.openclaw
touch ~/.openclaw/openclaw.jsonpowershell
# Windows (PowerShell)
New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\.openclaw"
New-Item -ItemType File -Force -Path "$env:USERPROFILE\.openclaw\openclaw.json"TIP
如果你之前运行过 openclaw onboard,配置文件会自动生成,只需在已有内容上修改即可。
配置文件结构
openclaw.json 的整体结构分为两大部分:
json
{
"models": {
"mode": "merge",
"providers": {
// 配置 AI 模型提供商
}
},
"agents": {
"defaults": {
// 配置默认模型、工作目录等
}
}
}models.providers— 定义服务提供商,包括地址、Key、模型列表models.mode— 设为"merge"时,自定义配置会与内置默认配置合并,强烈建议始终加上agents.defaults.model.primary— 默认使用的模型,格式为provider名称/模型IDapi— API 协议类型,Anthropic 模型用"anthropic-messages",OpenAI 兼容模型用"openai-completions"
配置方式
配置 Anthropic(Claude)模型
将以下内容写入 openclaw.json:
json
{
"models": {
"mode": "merge",
"providers": {
"anthropic": {
"baseUrl": "https://api.mirrorstages.com/anthropic",
"apiKey": "your-api-key",
"api": "anthropic-messages",
"models": [
{
"id": "claude-opus-4-6",
"name": "Claude Opus 4.6",
"input": ["text", "image"],
"contextWindow": 200000,
"maxTokens": 8192,
"reasoning": false
}
]
}
}
},
"agents": {
"defaults": {
"model": {
"primary": "anthropic/claude-opus-4-6"
}
}
}
}将 your-api-key 替换为你在 API Keys 页面 获取的 Mirrorstages API Key。
关键字段说明
| 字段 | 含义 | 示例值 |
|---|---|---|
baseUrl | API 代理地址 | https://api.mirrorstages.com/anthropic |
apiKey | 你的 API Key | your-api-key |
api | API 协议类型 | anthropic-messages |
mode | 配置合并模式 | merge(推荐) |
models[].id | 模型 ID | claude-opus-4-6 |
model.primary | 默认模型 | anthropic/claude-opus-4-6 |
多模型配置
如果需要在多个 Claude 模型之间随时切换,在 models 数组中添加更多模型即可:
json
{
"models": {
"mode": "merge",
"providers": {
"anthropic": {
"baseUrl": "https://api.mirrorstages.com/anthropic",
"apiKey": "your-api-key",
"api": "anthropic-messages",
"models": [
{
"id": "claude-opus-4-6",
"name": "Claude Opus 4.6",
"input": ["text", "image"],
"contextWindow": 200000,
"maxTokens": 8192,
"reasoning": false
},
{
"id": "claude-sonnet-4-5-20250929",
"name": "Claude Sonnet 4.5",
"input": ["text", "image"],
"contextWindow": 200000,
"maxTokens": 8192,
"reasoning": false
},
{
"id": "claude-haiku-4-5-20251001",
"name": "Claude Haiku 4.5",
"input": ["text", "image"],
"contextWindow": 200000,
"maxTokens": 8192,
"reasoning": false
}
]
}
}
},
"agents": {
"defaults": {
"model": {
"primary": "anthropic/claude-opus-4-6"
}
}
}
}配置 OpenAI(GPT)模型
通过 Mirrorstages 调用 OpenAI 模型时,api 字段须设为 openai-completions:
json
{
"models": {
"mode": "merge",
"providers": {
"openai": {
"baseUrl": "https://api.mirrorstages.com/openai/v1",
"apiKey": "your-api-key",
"api": "openai-completions",
"models": [
{
"id": "gpt-5.4",
"name": "GPT-5.4",
"input": ["text", "image"],
"contextWindow": 200000,
"maxTokens": 16384,
"reasoning": true
}
]
}
}
},
"agents": {
"defaults": {
"model": {
"primary": "openai/gpt-5.4"
}
}
}
}同时配置 Anthropic + OpenAI(推荐)
在 models.providers 下并列添加两个 provider,即可同时使用两家模型:
json
{
"models": {
"mode": "merge",
"providers": {
"anthropic": {
"baseUrl": "https://api.mirrorstages.com/anthropic",
"apiKey": "your-api-key",
"api": "anthropic-messages",
"models": [
{
"id": "claude-opus-4-6",
"name": "Claude Opus 4.6",
"input": ["text", "image"],
"contextWindow": 200000,
"maxTokens": 8192,
"reasoning": false
},
{
"id": "claude-sonnet-4-5-20250929",
"name": "Claude Sonnet 4.5",
"input": ["text", "image"],
"contextWindow": 200000,
"maxTokens": 8192,
"reasoning": false
}
]
},
"openai": {
"baseUrl": "https://api.mirrorstages.com/openai/v1",
"apiKey": "your-api-key",
"api": "openai-completions",
"models": [
{
"id": "gpt-5.4",
"name": "GPT-5.4",
"input": ["text", "image"],
"contextWindow": 200000,
"maxTokens": 16384,
"reasoning": true
},
{
"id": "gpt-5.3-codex",
"name": "GPT-5.3 Codex",
"input": ["text", "image"],
"contextWindow": 200000,
"maxTokens": 16384,
"reasoning": true
}
]
}
}
},
"agents": {
"defaults": {
"model": {
"primary": "anthropic/claude-opus-4-6"
}
}
}
}切换默认模型时,只需修改 model.primary 的值:
"anthropic/claude-opus-4-6"→ Claude Opus 4.6"anthropic/claude-sonnet-4-5-20250929"→ Claude Sonnet 4.5"openai/gpt-5.4"→ GPT-5.4"openai/gpt-5.3-codex"→ GPT-5.3 Codex
也可以配置 fallback 机制,当主模型不可用时自动切换:
json
"model": {
"primary": "anthropic/claude-opus-4-6",
"fallbacks": [
"anthropic/claude-sonnet-4-5-20250929",
"openai/gpt-5.4"
]
}验证配置
运行以下命令确认配置生效:
bash
openclaw如果配置正确,OpenClaw 将正常启动并通过 Mirrorstages 代理发送请求。
也可以用以下命令检查模型列表:
bash
openclaw models list配置速查表
| 配置项 | Anthropic(Claude) | OpenAI(GPT) |
|---|---|---|
| Provider 名称 | anthropic | openai |
| Base URL | https://api.mirrorstages.com/anthropic | https://api.mirrorstages.com/openai/v1 |
| API 协议类型 | anthropic-messages | openai-completions |
| 模型引用格式 | anthropic/模型ID | openai/模型ID |
| 推荐旗舰模型 | claude-opus-4-6 | gpt-5.4 |
| 推荐日用模型 | claude-sonnet-4-5-20250929 | gpt-5.3-codex |
常见问题
配置后无法连接?
- 确认
openclaw.json中的apiKey是否正确 - 确认
baseUrl配置正确(参考上方速查表) - 确认套餐仍有剩余额度
提示 401 错误?
API Key 无效或已被删除,请到控制台检查或重新创建。
提示额度不足?
当前套餐额度已用尽,请升级套餐或等待下一计费周期刷新。
更多问题排查请参阅 OpenClaw 常见问题。