主题
密钥管理
概述
OpenClaw 的密钥管理通过 openclaw.json 中的 env 字段统一管理所有 API Key、Token 等敏感信息。所有密钥存储在本地配置文件中,不会上传到任何外部服务。
配置方式
在配置文件中管理
在 openclaw.json 的 env 字段中集中管理所有密钥:
json
{
"env": {
"OPENROUTER_API_KEY": "sk-or-v1-你的密钥",
"SILICONFLOW_API_KEY": "sk-你的密钥",
"DEEPSEEK_API_KEY": "sk-你的密钥"
}
}在模型配置中引用
使用 ${变量名} 语法引用环境变量:
json
{
"models": {
"providers": {
"openrouter": {
"baseUrl": "https://openrouter.ai/api/v1",
"apiKey": "${OPENROUTER_API_KEY}"
},
"siliconflow": {
"baseUrl": "https://api.siliconflow.cn/v1",
"apiKey": "${SILICONFLOW_API_KEY}"
}
}
}
}通过 CLI 管理
bash
# 设置配置值
openclaw config set env.OPENAI_KEY "sk-xxxxx"
# 查看配置
openclaw config get env
# 查看完整配置
openclaw config get安全最佳实践
不要硬编码密钥
DANGER
不要在 SKILL.md 的 prompt 中直接写入 API Key。使用 env 字段和环境变量引用。
配置文件位置
| 系统 | 路径 |
|---|---|
| macOS / Linux | ~/.openclaw/openclaw.json |
| Windows | C:\Users\用户名\.openclaw\openclaw.json |
定期轮换密钥
- 定期在各提供商控制台重新生成 API Key
- 更新
openclaw.json后重启 Gateway:openclaw gateway restart
备份注意
备份 ~/.openclaw/ 目录时,注意 openclaw.json 包含明文密钥。建议:
- 不要将配置文件提交到 Git
- 备份时加密处理
- 使用各提供商的密钥权限限制功能(如限制 IP、用量上限)
AppSecret 安全
部分频道(如 QQ、飞书)的 AppSecret 不支持二次查看,丢失需要重置。创建后请立即保存。