为什么需要 Foxcode
OpenClaw 是一个 AI 模型管理工具,可以统一管理多个 AI provider。Foxcode 是一个支持 Anthropic Claude 模型的 provider,提供:
- 稳定的 Claude 模型访问
- 支持最新模型,如 claude-sonnet-4-5-thinking
- 独立的速率限制管理
- 完整的 reasoning 和 thinking 模式支持
如果你有 Foxcode 的 API key,可以在 OpenClaw 中配置使用。
准备工作
你需要:
- 已安装 OpenClaw(假设安装在
~/.openclaw) - Foxcode API key(注册地址)
jq命令行工具(用于编辑 JSON 配置)
安装 jq:
# macOS
brew install jq
# Ubuntu/Debian
sudo apt install jq
# CentOS/RHEL
sudo yum install jq
配置步骤
1. 备份现有配置
cp ~/.openclaw/openclaw.json ~/.openclaw/openclaw.json.bak
cp ~/.openclaw/agents/main/agent/auth-profiles.json ~/.openclaw/agents/main/agent/auth-profiles.json.bak
2. 注册 Foxcode Provider
创建一个临时的 jq 脚本:
cat > /tmp/add_foxcode.jq <<'EOF'
{
id: $model,
name: $model,
reasoning: true,
input: ["text", "image"],
cost: {
input: 3,
output: 15,
cacheRead: 0.3,
cacheWrite: 3.75
},
contextWindow: 200000,
maxTokens: 8192
} as $model_obj |
.models.providers.foxcode = {
baseUrl: $url,
apiKey: $key,
api: $api,
authHeader: true,
models: [$model_obj]
}
| .auth.profiles["foxcode:default"] = {
provider: "foxcode",
mode: "api_key"
}
| .agents.defaults.models["foxcode/" + $model] = {}
EOF
执行配置:
jq \
--arg url 'https://code.newcli.com/claude/aws' \
--arg key 'sk-free-your-api-key-here' \
--arg api 'anthropic-messages' \
--arg model 'claude-sonnet-4-5-thinking' \
-f /tmp/add_foxcode.jq \
~/.openclaw/openclaw.json > /tmp/openclaw_new.json
mv /tmp/openclaw_new.json ~/.openclaw/openclaw.json
重要:将 sk-free-your-api-key-here 替换为你的真实 API key。
3. 配置认证信息
jq \
--arg key 'sk-free-your-api-key-here' \
'.profiles["foxcode:default"] = {
type: "api_key",
provider: "foxcode",
key: $key
}' \
~/.openclaw/agents/main/agent/auth-profiles.json > /tmp/auth_new.json
mv /tmp/auth_new.json ~/.openclaw/agents/main/agent/auth-profiles.json
4. 设置为默认模型(可选)
如果你想让 Foxcode 成为默认模型:
jq \
--arg model 'foxcode/claude-sonnet-4-5-thinking' \
'.agents.defaults.model.primary = $model' \
~/.openclaw/openclaw.json > /tmp/openclaw_primary.json
mv /tmp/openclaw_primary.json ~/.openclaw/openclaw.json
5. 重启 OpenClaw Gateway
openclaw gateway restart
如果你的 OpenClaw 是通过 systemd 管理的:
systemctl restart openclaw-gateway
验证配置
查看 Provider 列表
jq '.models.providers | keys' ~/.openclaw/openclaw.json
应该能看到 foxcode 在列表中。
查看 Foxcode 配置
jq '.models.providers.foxcode' ~/.openclaw/openclaw.json
输出应该类似:
{
"baseUrl": "https://code.newcli.com/claude/aws",
"apiKey": "sk-free-...",
"api": "anthropic-messages",
"authHeader": true,
"models": [
{
"id": "claude-sonnet-4-5-thinking",
"name": "claude-sonnet-4-5-thinking",
"reasoning": true,
"input": ["text", "image"],
"cost": {
"input": 3,
"output": 15,
"cacheRead": 0.3,
"cacheWrite": 3.75
},
"contextWindow": 200000,
"maxTokens": 8192
}
]
}
测试模型
openclaw agent -m "test" --model foxcode/claude-sonnet-4-5-thinking
如果配置正确,应该能收到模型的回复。
使用 Foxcode
使用默认模型
如果你设置了 Foxcode 为默认模型:
openclaw agent -m "你的问题"
显式指定模型
openclaw agent -m "你的问题" --model foxcode/claude-sonnet-4-5-thinking
查看模型状态
openclaw models status --json
常见问题
API 类型错误
错误现象:配置后无法调用模型,提示 API 类型不支持。
原因:API 类型设置错误。
解决方案:确保使用 anthropic-messages,不是 anthropic:
jq '.models.providers.foxcode.api' ~/.openclaw/openclaw.json
如果输出不是 "anthropic-messages",需要修正:
jq '.models.providers.foxcode.api = "anthropic-messages"' \
~/.openclaw/openclaw.json > /tmp/fix.json
mv /tmp/fix.json ~/.openclaw/openclaw.json
openclaw gateway restart
Rate Limit 错误
错误现象:
Error: Provider foxcode is in cooldown (all profiles unavailable) (rate_limit)
原因:Anthropic API 有速率限制,短时间内多次调用触发冷却。
解决方案:等待几分钟后重试。查看冷却状态:
openclaw models status --json | jq '.auth.unusableProfiles'
配置不生效
原因:修改配置后没有重启 gateway。
解决方案:
openclaw gateway restart
API Key 无效
错误现象:提示认证失败。
解决方案:检查 API key 是否正确:
jq '.models.providers.foxcode.apiKey' ~/.openclaw/openclaw.json
确认 key 以 sk-ant- 开头。如果需要更新:
jq --arg key 'sk-free-new-key' \
'.models.providers.foxcode.apiKey = $key' \
~/.openclaw/openclaw.json > /tmp/update.json
mv /tmp/update.json ~/.openclaw/openclaw.json
jq --arg key 'sk-free-new-key' \
'.profiles["foxcode:default"].key = $key' \
~/.openclaw/agents/main/agent/auth-profiles.json > /tmp/auth_update.json
mv /tmp/auth_update.json ~/.openclaw/agents/main/agent/auth-profiles.json
openclaw gateway restart
配置文件说明
OpenClaw 的配置分为两个文件:
openclaw.json
位置:~/.openclaw/openclaw.json
包含:
- Provider 定义(baseUrl, apiKey, api 类型)
- 模型配置(cost, contextWindow, maxTokens)
- 默认模型设置
auth-profiles.json
位置:~/.openclaw/agents/main/agent/auth-profiles.json
包含:
- 认证 profile 定义
- API key 存储
- 认证类型配置
两个文件必须同步更新,否则会导致认证失败。
进阶配置
添加多个 Profile
如果你有多个 Anthropic API key,可以配置多个 profile:
jq --arg key 'sk-free-second-key' \
'.profiles["foxcode:backup"] = {
type: "api_key",
provider: "foxcode",
key: $key
}' \
~/.openclaw/agents/main/agent/auth-profiles.json > /tmp/multi.json
mv /tmp/multi.json ~/.openclaw/agents/main/agent/auth-profiles.json
配置 Fallback 模型
如果 Foxcode 不可用,自动切换到备用模型:
jq '.agents.defaults.model.fallbacks = ["openai/gpt-4", "cliproxy/gpt-4"]' \
~/.openclaw/openclaw.json > /tmp/fallback.json
mv /tmp/fallback.json ~/.openclaw/openclaw.json
自定义模型参数
修改 cost、contextWindow 等参数:
jq '.models.providers.foxcode.models[0].cost.input = 2.5' \
~/.openclaw/openclaw.json > /tmp/custom.json
mv /tmp/custom.json ~/.openclaw/openclaw.json
总结
配置 Foxcode 的核心步骤:
- 备份配置文件
- 用 jq 修改
openclaw.json和auth-profiles.json - 确保 API 类型是
anthropic-messages - 重启 gateway
- 验证配置
配置完成后,你就可以在 OpenClaw 中使用 Foxcode 服务了。如果遇到问题,先检查配置文件格式,再查看 gateway 日志。
如果你还没有 Foxcode API key,可以通过这个链接注册。
完整配置示例
这是 Foxcode 在 openclaw.json 中的完整配置结构:
{
"models": {
"mode": "merge",
"providers": {
"foxcode": {
"baseUrl": "https://code.newcli.com/claude/aws",
"apiKey": "sk-free",
"api": "anthropic-messages",
"authHeader": true,
"models": [
{
"id": "claude-sonnet-4-5-thinking",
"name": "Claude Sonnet 4.5 Thinking",
"reasoning": true,
"input": ["text", "image"],
"cost": {
"input": 3,
"output": 15,
"cacheRead": 0.3,
"cacheWrite": 3.75
},
"contextWindow": 200000,
"maxTokens": 8192
}
]
}
}
},
"agents": {
"defaults": {
"model": {
"primary": "foxcode/claude-sonnet-4-5-thinking"
},
"models": {
"foxcode/claude-sonnet-4-5-thinking": {}
}
}
}
}
配置说明:
baseUrl: Foxcode 服务地址apiKey: 你的 API key(替换sk-free)api: 必须是anthropic-messagesauthHeader: 启用认证头primary: 设置为默认模型
这个配置会将 Foxcode 设置为默认模型。