openclaw-model-switch
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOpenClaw Model Switch
OpenClaw 模型切换
Switch or repair an OpenClaw instance's model configuration by safely editing .
openclaw.jsonDiagnose before you edit. Model failures on OpenClaw are usually NOT the model id —
they are key routing (env hijack), provider-plugin restrictions, or endpoint/model mismatch.
Changing the model id without checking these first is how a 5-minute fix becomes a 2-hour
debugging session. The full trap catalog with discovery commands lives in
references/troubleshooting-model-config.md — read it
the moment anything errors.
通过安全编辑 来切换或修复 OpenClaw 实例的模型配置。
openclaw.json先诊断再编辑。 OpenClaw 的模型故障通常不是模型 ID 的问题——而是密钥路由(环境变量劫持)、提供商插件限制,或是端点与模型不匹配。如果不先排查这些问题就直接修改模型 ID,原本5分钟就能解决的问题会变成2小时的调试。完整的故障陷阱大全与排查命令见 references/troubleshooting-model-config.md——一旦出现任何报错,请立即阅读该文档。
Step 1 — Find the real config file(s)
步骤 1 — 找到真实的配置文件
Do NOT assume a hardcoded path. Candidate locations (check all, edit all that exist):
- — the gateway's live config on most installs
~/.openclaw/openclaw.json - — Kimi Claw mirror, kept in sync on some installs
~/.kimi/kimi-claw/openclaw.json - — legacy desktop path
~/.kimi_openclaw/openclaw.json
Confirm which one the gateway actually reads: prints
. If several exist, treat them as mirrors: edit all of them
identically, otherwise the next sync overwrites your fix.
openclaw gateway statusConfig (service): <path>不要假设路径是固定的。候选位置如下(检查所有位置,修改所有存在的文件):
- — 大多数安装中网关的生效配置
~/.openclaw/openclaw.json - — Kimi Claw 镜像,部分安装中会保持同步
~/.kimi/kimi-claw/openclaw.json - — 旧版桌面端路径
~/.kimi_openclaw/openclaw.json
确认网关实际读取的配置文件:执行 会输出 。如果存在多个配置文件,将它们视为镜像:必须完全一致地修改所有文件,否则下一次同步会覆盖你的修改。
openclaw gateway statusConfig (service): <路径>Step 2 — Probe the endpoint + model BEFORE touching config
步骤 2 — 修改配置前先探测端点和模型
Never trust a relay's model listing ( on new-api style relays is frequently
incomplete — a model can be absent from the list yet serve fine). The only authority is a
real completion probe from the host that will run the bot:
GET /v1/modelsbash
curl -sS -o /tmp/probe.json -w "HTTP %{http_code}\n" \
-X POST "<baseUrl>/v1/messages" \
-H "Authorization: Bearer <apiKey>" \
-H "Content-Type: application/json" \
-H "anthropic-version: 2023-06-01" \
-d '{"model":"<model-id>","max_tokens":16,"messages":[{"role":"user","content":"hi"}]}'Expected: and a array in the body. with a token you
just verified works elsewhere → the wire key is being hijacked (see trap #1 in the
troubleshooting reference). → the model is not served for this
token/group from this network (trap #3) — pick a served model or fix the relay, don't
blind-switch.
HTTP 200content401 Invalid token503 No available channel永远不要信任中继的模型列表(new-api 风格中继的 接口通常不完整——某个模型可能不在列表中,但实际可以正常服务)。唯一可靠的判断方式是从运行 bot 的主机发起真实的补全请求探测:
GET /v1/modelsbash
curl -sS -o /tmp/probe.json -w "HTTP %{http_code}\n" \
-X POST "<baseUrl>/v1/messages" \
-H "Authorization: Bearer <apiKey>" \
-H "Content-Type: application/json" \
-H "anthropic-version: 2023-06-01" \
-d '{"model":"<model-id>","max_tokens":16,"messages":[{"role":"user","content":"hi"}]}'预期结果:返回 且响应体中包含 数组。如果返回 ,但你刚验证过该 token 在其他地方可用——说明传输密钥被劫持了(见故障排查参考中的陷阱 #1)。如果返回 ——说明当前网络下该 token/分组无法使用这个模型(陷阱 #3)——请选择可用的模型或修复中继,不要盲目切换。
HTTP 200content401 Invalid token503 No available channelStep 3 — Switch the model
步骤 3 — 切换模型
bash
python3 scripts/switch-model.py <model-id> --restartbash
python3 scripts/switch-model.py <model-id> --restarttarget a specific provider instead of the guessed one:
指定特定提供商而非自动猜测:
python3 scripts/switch-model.py k3 --provider kimi-relay --restart
python3 scripts/switch-model.py k3 --provider kimi-relay --restart
explicit config path (skips discovery):
显式指定配置路径(跳过自动发现):
python3 scripts/switch-model.py k3 --config ~/.openclaw/openclaw.json --restart
The script: discovers and backs up every candidate config to `<config-dir>/config-backups/`,
adds the model definition if known, sets `agents.defaults.model.primary`, syncs mirror
files, and restarts the gateway with `--restart`.python3 scripts/switch-model.py k3 --config ~/.openclaw/openclaw.json --restart
该脚本会:自动发现所有候选配置并备份到 `<config-dir>/config-backups/`,如果是已知模型则添加模型定义,设置 `agents.defaults.model.primary`,同步镜像文件,加上 `--restart` 参数时会重启网关。Step 4 — Verify end-to-end (mandatory)
步骤 4 — 端到端验证(必须执行)
A restarted gateway proves nothing. Run one real agent turn and read the result metadata:
bash
openclaw agent --local --json --agent main --session-id verify-$(date +%s) -m "ping"Success looks like: , , and the gateway log shows
. with
means your target failed and a fallback saved the turn — the config is
still wrong.
"result": "success""fallbackUsed": falseagent model: <provider>/<model> (thinking=...)"result": "success"fallbackUsed: true网关重启不代表配置生效。运行一次真实的 Agent 调用,查看结果元数据:
bash
openclaw agent --local --json --agent main --session-id verify-$(date +%s) -m "ping"成功的标志是:返回 、,且网关日志显示 。如果返回 但 ,说明目标模型调用失败,是回退模型完成了请求——配置仍然有问题。
"result": "success""fallbackUsed": falseagent model: <provider>/<model> (thinking=...)"result": "success"fallbackUsed: trueCommon failures → read the troubleshooting reference
常见故障 → 请阅读故障排查参考
| Symptom | Most likely trap |
|---|---|
| Trap #1 — env |
| Trap #2 — kimi-provider plugin hardcodes binary thinking; bypass with a custom provider |
| Trap #2 variant — anthropic-messages base profile; unlock via |
| Trap #3 — model not served for this group/network; listing ≠ availability |
| Edit saved + gateway restarted, nothing changed | Trap #5 — edited the wrong file / mirror not synced |
| 症状 | 最可能的陷阱 |
|---|---|
| 陷阱 #1 — 环境变量 |
| 陷阱 #2 — kimi-provider 插件硬编码了二元思考模式;使用自定义提供商绕过 |
| 陷阱 #2 变体 — anthropic-messages 基础配置;通过 |
| 陷阱 #3 — 该分组/网络下不提供此模型;列表不等于可用性 |
| 已保存修改 + 重启网关,但毫无变化 | 陷阱 #5 — 编辑了错误的文件 / 镜像未同步 |
Safety rules
安全规则
- Always backup before editing (the script does this; manual edits: copy to first)
config-backups/ - Preserve existing ,
apiKey, plugin configs, andheadersblocks — retype only the fields you mean to changeenv - Validate JSON after manual edits:
python3 -m json.tool openclaw.json > /dev/null - Do not commit config files containing API keys to version control
- After changing anything, redo the Step-4 verification — and if it fails, restore the newest backup before trying something else
- 编辑前务必备份(脚本会自动备份;手动编辑请先复制到 目录)
config-backups/ - 保留现有的 、
apiKey、插件配置和headers块——只修改你需要改动的字段env - 手动编辑后验证 JSON:
python3 -m json.tool openclaw.json > /dev/null - 不要将包含 API 密钥的配置文件提交到版本控制
- 修改任何内容后,重新执行步骤4的验证——如果失败,先恢复最新的备份再尝试其他方案
Resources
相关资源
- scripts/switch-model.py — model switcher with config discovery, backup, mirror sync, and restart
- references/kimi-models.md — known model specs (k3, k2p6, kimi-k2.7-code) and config snippets
- references/troubleshooting-model-config.md — the trap catalog: env key hijack, plugin binary thinking, canonicalModelId, relay availability, config discovery. Read on any error.
- scripts/switch-model.py — 支持配置自动发现、备份、镜像同步和重启功能的模型切换工具
- references/kimi-models.md — 已知模型规格(k3、k2p6、kimi-k2.7-code)和配置片段
- references/troubleshooting-model-config.md — 故障陷阱大全:环境变量密钥劫持、插件二元思考、canonicalModelId、中继可用性、配置发现。任何报错时都请阅读。