模型故障转移
当主模型失败时,OpenClaw 可以自动切换到备用模型。
概述
故障转移场景:
- API 错误
- 速率限制
- 服务不可用
- 认证过期
配置
json
{
"agents": {
"defaults": {
"model": {
"primary": "anthropic/claude-sonnet-4-20250514",
"fallbacks": [
"openai/gpt-4o",
"google/gemini-pro"
]
}
}
}
}CLI 管理
bash
# 列出故障转移模型
openclaw models fallbacks list
# 添加故障转移
openclaw models fallbacks add openai/gpt-4o
# 移除故障转移
openclaw models fallbacks remove openai/gpt-4o
# 清除所有
openclaw models fallbacks clear故障转移流程
- 尝试主模型
- 如果失败,记录错误
- 尝试第一个故障转移模型
- 如果失败,继续下一个
- 所有模型失败则返回错误
错误类型
| 错误 | 是否故障转移 |
|---|---|
| 速率限制 (429) | ✅ |
| 服务器错误 (5xx) | ✅ |
| 认证错误 (401) | ✅ |
| 无效请求 (400) | ❌ |
| 超时 | ✅ |
"All models failed" 错误
当所有模型都失败时:
- 检查认证状态:
openclaw models status - 检查网络连接
- 验证 API 密钥/token 有效性
- 查看日志:
openclaw logs --follow