模型故障切换
Fallback 机制是 OpenClaw 最核心的省钱和保障可用性的策略。当主模型不可用时,系统自动切换到备选模型,确保工作流不中断。
工作原理
用户请求 → 主模型 (primary)
↓ 失败(超时/限流/报错)
备选模型 1 (fallback[0])
↓ 失败
备选模型 2 (fallback[1])
↓ 失败
...继续尝试 fallback 链触发条件
以下情况会触发自动切换:
- API 错误(5xx):服务端故障
- 请求超时:网络不稳定或模型响应慢
- 额度耗尽(429):速率限制或余额不足
- 服务不可用:模型下线或维护
配置示例
推荐配置(方案四:混合最优)
在 ~/.openclaw/openclaw.json 中设置:
json
{
"agents": {
"defaults": {
"model": {
"primary": "anthropic/claude-sonnet-4-6",
"fallbacks": [
"anthropic/claude-haiku-4-5",
"deepseek/deepseek-chat"
]
}
}
}
}这套配置的逻辑是:
- Sonnet 4.6($3.00/1M)处理主要任务
- Sonnet 不可用时降级到 Haiku 4.5($1.00/1M),保持 Claude 生态
- Claude 全线不可用时切换到 DeepSeek($0.14/1M),成本极低
极致省钱配置
json
{
"agents": {
"defaults": {
"model": {
"primary": "deepseek/deepseek-chat",
"fallbacks": [
"zai/glm-5-flash",
"ollama/qwen3.5-coder:32b"
]
}
}
}
}带本地兜底的配置
json
{
"agents": {
"defaults": {
"model": {
"primary": "anthropic/claude-sonnet-4-6",
"fallbacks": [
"deepseek/deepseek-chat",
"ollama/qwen3.5-coder:32b"
]
}
}
}
}本地模型兜底
将 Ollama 本地模型放在 Fallback 链末尾,即使所有云端 API 都不可用,你仍然能继续工作。
价格速查排行
按输入价格从低到高排列(单位:美元 / 1M tokens):
| 排名 | 模型 | 输入/1M | 输出/1M |
|---|---|---|---|
| 1 | Ollama 本地模型 | 免费 | 免费 |
| 2 | DeepSeek V3.2.2 | $0.14 | $0.28 |
| 3 | 豆包 Seed 2.0 Pro | $0.47 | $2.37 |
| 4 | MiniMax M2.5 | $0.50 | $2.00 |
| 5 | Kimi K2.5 | $0.60 | $3.00 |
| 6 | 智谱 GLM-5 | $0.80 | $2.56 |
| 7 | Claude Haiku 4.5 | $1.00 | $5.00 |
| 8 | 通义千问 Qwen 3.5 Max | $1.20 | $6.00 |
| 9 | Google Gemini 3 Pro | $2.00 | $12.00 |
| 10 | OpenAI GPT-5.4 | $2.50 | $15.00 |
| 11 | Claude Sonnet 4.6 | $3.00 | $15.00 |
| 12 | Claude Opus 4.6 | $5.00 | $25.00 |
五种场景化智能路由方案
根据不同的使用场景、团队规模和预算,以下是 5 种经过实战验证的路由方案。
方案一:个人极简(月预算 < $5)
目标:最低成本入门,个人开发者 / 学生党适用。
模型分工:
- DeepSeek V3 处理日常编码和问答(主力)
- GLM Flash 处理心跳任务(免费)
- Ollama 本地模型作为最终兜底
json
{
"agents": {
"defaults": {
"model": {
"primary": "deepseek/deepseek-chat",
"fallbacks": [
"zai/glm-5-flash",
"ollama/qwen3.5-coder:32b"
]
},
"heartbeat": {
"model": "zai/glm-4.7-flash",
"interval": 7200
}
}
},
"costControl": {
"enabled": true,
"limits": {
"daily": 0.5,
"monthly": 5.0
}
}
}SOUL.md 省钱配置
个人极简方案下,务必精简 SOUL.md,控制在 200 字以内。回复简洁、不废话、工具调用前先思考是否必要、能一次解决的不要多次调用、遇到不确定的直接询问用户。
方案二:小团队服务(月预算 $200)
目标:稳定可靠,适合 2-10 人团队。
模型分工:
- Sonnet 4.6(60% 流量):复杂任务、客户对话、内容创作
- Haiku(35% 流量):数据处理、简单查询、格式转换
- DeepSeek R1(5% 流量):每周深度分析报告
- GPT-5.4 作为 Fallback(当 Anthropic 不可用时)
json
{
"agents": {
"defaults": {
"model": {
"primary": "anthropic/claude-sonnet-4-6",
"fallbacks": [
"anthropic/claude-haiku-4-5",
"openai/gpt-5.4"
]
}
},
"lightweight": {
"model": {
"primary": "anthropic/claude-haiku-4-5",
"fallbacks": ["deepseek/deepseek-chat"]
}
},
"reasoning": {
"model": {
"primary": "deepseek/deepseek-reasoner"
}
}
},
"costControl": {
"enabled": true,
"limits": {
"daily": 10.0,
"monthly": 200.0
},
"actions": {
"onDailyLimit": "alert_and_pause",
"onMonthlyLimit": "stop"
}
}
}方案三:内容创作工作室(月预算 $100)
目标:中文内容质量最优。
模型分工:
- DeepSeek V4(70% 任务):中文写作,生成初稿
- GPT-5.4(20% 任务):图片分析、多模态内容
- Claude Haiku(10% 任务):最终校对、格式化输出
月产出能力:约 3000 篇短文(500字)或 300 篇长文(3000字)
json
{
"agents": {
"defaults": {
"model": {
"primary": "deepseek/deepseek-chat",
"fallbacks": ["anthropic/claude-haiku-4-5"]
}
},
"multimodal": {
"model": {
"primary": "openai/gpt-5.4"
}
},
"proofreading": {
"model": {
"primary": "anthropic/claude-haiku-4-5"
}
}
},
"costControl": {
"enabled": true,
"limits": {
"daily": 5.0,
"monthly": 100.0
}
}
}方案四:数据合规企业(国内预算 ¥1000/月)
目标:数据不出境,满足国内合规要求。
模型分工:
- Qwen 2.5-72B(阿里云百炼,日常任务)
- DeepSeek R1(复杂分析)
- Llama 3.3:70B(敏感数据处理,Ollama 本地部署)
数据分级:
- L1(公开):百炼 API 处理
- L2(内部):DeepSeek 处理
- L3(敏感):本地 Ollama 处理
json
{
"agents": {
"defaults": {
"model": {
"primary": "dashscope/qwen2.5-72b-instruct",
"fallbacks": [
"deepseek/deepseek-chat",
"ollama/llama3.3:70b"
]
}
}
},
"models": {
"mode": "merge",
"providers": {
"dashscope": {
"baseUrl": "https://dashscope.aliyuncs.com/compatible-mode/v1",
"apiKey": "${DASHSCOPE_API_KEY}"
},
"deepseek": {
"baseUrl": "https://api.deepseek.com/v1",
"apiKey": "${DEEPSEEK_API_KEY}"
}
}
},
"security": {
"auditLog": true,
"dataRetention": "90d",
"accessControl": true
},
"costControl": {
"enabled": true,
"limits": {
"monthly": 150.0
}
}
}方案五:高可用生产系统(月预算 $500+)
目标:99.9% 可用性,多模型冗余。
Fallback 链(按优先级):
- Claude Sonnet 4.6(主力,60% 流量)
- GPT-5.4(备用,30% 流量,A/B 测试)
- Gemini 3.1 Pro(第三备用)
- DeepSeek V4(成本兜底)
- Ollama Llama 3.3(最终兜底,本地)
SLA 目标:API 可用性 99.9%、平均响应 < 3 秒、成本波动 < 10%
json
{
"agents": {
"defaults": {
"model": {
"primary": "anthropic/claude-sonnet-4-6",
"fallbacks": [
"openai/gpt-5.4",
"google/gemini-3.1-pro",
"deepseek/deepseek-chat",
"ollama/llama3.3"
]
}
}
},
"costControl": {
"enabled": true,
"limits": {
"hourly": 5.0,
"daily": 30.0,
"monthly": 500.0
},
"actions": {
"onHourlyLimit": "slowdown",
"onDailyLimit": "alert_and_pause",
"onMonthlyLimit": "stop"
},
"alertWebhook": "${COST_ALERT_WEBHOOK}"
},
"monitoring": {
"healthCheck": {
"enabled": true,
"interval": 60
},
"costReport": {
"weekly": true,
"alertThreshold": 80
},
"autoFailover": true
}
}配置要点速查
| 操作 | 命令 |
|---|---|
| 交互式初始化 | openclaw onboard |
| 查看已配置模型 | openclaw models list |
| 探测模型可用性 | openclaw models status --probe |
| 设置主模型 | openclaw config set agents.defaults.model.primary <model-id> |
| 重启网关(配置生效) | openclaw gateway restart |
修改配置后
部分配置修改后需要执行 openclaw gateway restart 才能生效,特别是涉及 Provider 和 Fallback 链的变更。