添加模型提供商 是做什么的?
绝不打印或持久化密钥值;凭据仅作为 SecretRef(环境变量或文件源)进入配置。绝不在磁盘上手动编辑配置文件——每次变更都通过 openclaw config 执行,以确保经过验证和审计。每次运行结束时,要么显示可观察的验证结果,要么精确解释为何无法通过验证。
会话内的 config_set/config_set_ref 工具操作已被策略阻止用于 models.* 和 secrets.*;请使用信任的 shell(exec)执行以下命令。set_default_model 是允许在会话内更改默认路由的唯一操作——它在保存前进行实时测试。
收集
openclaw config get models --json # 首次设置前出现 "Config path not found" 属于正常
openclaw models list --agent <agentId> # 在包含多智能体的名单中,--agent 为必填项
openclaw models auth list --agent <agentId>
openclaw config schema --json | jq '.properties.models' # 在写入前确认确切的提供商路径
openclaw plugins list # OpenAI 路由需要 codex harness 插件;立即启用/安装,不要在验证过程中处理
如果目标提供商的 harness 插件缺失或已禁用,请在此处修复(openclaw plugins enable codex 或 openclaw plugins install @openclaw/codex),以免验证步骤因此卡住;插件启用会被网关热加载所识别。
确定认证契约:API 密钥提供商在 models.providers.<id>.apiKey 上使用 SecretRef;订阅/OAuth 提供商(ChatGPT/Codex、Claude 订阅)改用 openclaw models auth login --provider <id>,并且不得为其设置 API 密钥路径。
变更
API 密钥示例(OpenAI),操作员将密钥存放在 0600 权限的文件中——先用 --dry-run 进行验证,然后再写入:
openclaw config set secrets.providers.openai_key_file --provider-source file --provider-path /path/to/openai.key --provider-mode singleValue --dry-run
openclaw config set secrets.providers.openai_key_file --provider-source file --provider-path /path/to/openai.key --provider-mode singleValue
openclaw config set models.providers.openai.apiKey --ref-provider openai_key_file --ref-source file --ref-id value
环境变量替代方案(当网关进程环境中包含密钥时):
openclaw config set models.providers.openai.apiKey --ref-provider default --ref-source env --ref-id OPENAI_API_KEY
要更改默认模型,请使用会话内的 set_default_model 操作(对非默认智能体需指定 agentId);它会在保存前实时测试路由。不要通过原始配置写入来更改默认值。
修复
openclaw doctor --lint
doctor --lint 可能因发现问题而返回退出码 1:请阅读报告并继续其余检查。普通的 doctor 和 doctor --non-interactive 可能会写入配置/状态;获得批准前请勿将其用于诊断。如果需要修复,请先获得明确批准,运行 openclaw doctor --fix --non-interactive,然后重新运行收集阶段的读取命令。
验证
适用于任何名单的安全测试(在任何设置中均有效;请使用您自己的智能体 ID 或任何已配置的智能体):
openclaw agent --agent <agentId> --model openai/gpt-5.4 -m "Reply with exactly: PROVIDER-PROOF-OK"
单智能体安装可以使用更轻量的补全测试代替——该测试没有 --agent 标志,但在多智能体名单上会因 "no explicit owner" 而失败,所以不要在那里重试:
openclaw infer model run --gateway --model openai/gpt-5.4 --prompt "Reply with exactly: PROVIDER-PROOF-OK"
预期收到完全匹配的回复;记录模型 ID 和耗时。已知依赖:OpenAI 路由需要运行时的 codex harness 插件——如果测试报告运行时不可用,请运行 openclaw plugins install @openclaw/codex 并重启网关,然后重新测试。
报告
说明添加的提供商、写入的 SecretRef 路径(绝不写值)、测试结果(包含模型 ID 和延迟),以及默认模型是否发生变更。如果测试失败,报告确切的错误和接下来应尝试的命令。
更多参考:https://docs.openclaw.ai/providers/models 和 https://docs.openclaw.ai/providers/openai