Skip to content

网关配置参考

OpenClaw 网关的主配置文件位于 ~/.openclaw/config.json。这是一个 JSON 格式的文件,包含了网关的所有配置选项。

配置文件结构

完整的配置文件结构示例:

json
{
  "server": {
    "port": 18789,
    "bind": "0.0.0.0",
    "baseUrl": "https://your-domain.com"
  },
  "ai": {
    "model": "volcengine-plan/ark-code-latest",
    "apiKey": "your-api-key-here",
    "baseUrl": "https://ark.cn-beijing.volces.com/api/v3",
    "maxTokens": 4096,
    "temperature": 0.7
  },
  "channels": {
    "feishu": {
      "enabled": true,
      "appId": "cli_xxxxxx",
      "appSecret": "xxxxxx",
      "allowFrom": ["ou_xxxxxx"],
      "groups": {
        "*": {
          "requireMention": true
        }
      }
    },
    "telegram": {
      "enabled": false,
      "botToken": "xxxxxx:xxxxxx",
      "allowFrom": []
    }
  },
  "plugins": {
    "exec": {
      "enabled": true,
      "allowElevated": false,
      "allowedCommands": []
    }
  },
  "credentials": {
    "clawhub-api-key": "clh_xxxxxx"
  },
  "logging": {
    "level": "info",
    "file": "~/.openclaw/openclaw.log"
  }
}

配置项说明

server - 服务器配置

选项类型必填说明默认值
portnumber网关监听端口18789
bindstring绑定地址0.0.0.0
baseUrlstring公网访问地址,用于 webhook 回调-

TIP

baseUrl 不需要加端口,如果你使用反向代理(如 Nginx),直接填写域名即可。如果直接暴露端口,需要包含端口:https://your-domain:18789

ai - AI 模型配置

OpenClaw 支持多种 LLM 后端,当前主流使用火山引擎方舟平台:

选项类型必填说明默认值
modelstring模型标识符-
apiKeystringAPI 密钥-
baseUrlstringAPI 基础地址平台默认
maxTokensnumber最大输出 tokens4096
temperaturenumber采样温度 0-20.7

常见模型标识符:

  • volcengine-plan/ark-code-latest - 火山方舟代码大模型
  • volcengine/ep-20250xxx-xxxx/deepseek-v3 - 自定义部署模型
  • openai/gpt-4o - OpenAI GPT-4o
  • anthropic/claude-3-5-sonnet - Anthropic Claude 3.5 Sonnet

channels - 通道配置

每个通道是一个键值对,键为通道名称:

json
"channels": {
  "通道名称": {
    "enabled": true,
    "配置项": "值"
  }
}

通用配置项(所有通道都支持):

选项类型说明
enabledboolean是否启用该通道
allowFromstring[]允许访问的用户 ID 列表,留空允许所有
groups.requireMentionboolean群组中是否需要 @ 才触发

各通道的具体配置项请参考对应通道的文档:

plugins - 插件配置

OpenClaw 通过插件扩展功能,每个插件有自己的配置:

exec 插件 - 命令执行

json
"exec": {
  "enabled": true,
  "allowElevated": false,
  "allowedCommands": [],
  "workingDirectory": "~/.openclaw/workspace"
}
选项说明
enabled是否允许执行 shell 命令
allowElevated是否允许提权执行(sudo)
allowedCommands允许执行的命令白名单,空数组允许所有
workingDirectory默认工作目录

credentials - 凭证存储

存放各种 API 密钥和凭证,技能会从这里读取:

json
"credentials": {
  "clawhub-api-key": "clh_your-key-here",
  "feishu-app-id": "cli_xxxxxx",
  "other-api-key": "xxxxxx"
}

ClawHub API 密钥默认会被自动读取,用于从技能市场安装技能。

logging - 日志配置

json
"logging": {
  "level": "info",
  "file": "~/.openclaw/openclaw.log"
}
选项说明
level日志级别:debug / info / warn / error
file日志文件路径,不填输出到 stdout

环境变量

部分配置可以通过环境变量覆盖,方便容器部署:

环境变量对应配置项
OPENCLAW_PORTserver.port
OPENCLAW_AI_MODELai.model
OPENCLAW_AI_API_KEYai.apiKey
OPENCLAW_BASE_URLserver.baseUrl

编辑配置

你可以直接用文本编辑器编辑配置文件:

bash
nano ~/.openclaw/config.json

编辑完成后需要重启网关生效:

bash
# 如果使用 systemd 服务
sudo systemctl restart openclaw

# 如果前台运行
 Ctrl+C 停止,然后重新启动

验证配置

可以用以下命令验证配置文件格式是否正确:

bash
python3 -c "import json; json.load(open('$HOME/.openclaw/config.json')); print('✓ Config JSON syntax OK')"

如果没有报错,说明格式正确。

配置示例

最小化配置(飞书 + 火山方舟)

json
{
  "server": {
    "port": 18789,
    "baseUrl": "https://your-domain.com"
  },
  "ai": {
    "model": "volcengine-plan/ark-code-latest",
    "apiKey": "xxxxxxxxxxxxxxxx",
    "baseUrl": "https://ark.cn-beijing.volces.com/api/v3"
  },
  "channels": {
    "feishu": {
      "enabled": true,
      "appId": "cli_xxxxxxxx",
      "appSecret": "xxxxxxxxxxxxxxxx",
      "allowFrom": ["ou_xxxxxxxx"]
    }
  }
}

多通道配置(飞书 + Telegram)

json
{
  "server": {
    "port": 18789,
    "baseUrl": "https://your-domain.com"
  },
  "ai": {
    "model": "volcengine-plan/ark-code-latest",
    "apiKey": "xxxxxxxxxxxxxxxx"
  },
  "channels": {
    "feishu": {
      "enabled": true,
      "appId": "cli_xxxxxxxx",
      "appSecret": "xxxxxxxxxxxxxxxx",
      "allowFrom": ["ou_xxxxxxxx"]
    },
    "telegram": {
      "enabled": true,
      "botToken": "123456:ABCDEF",
      "allowFrom": [123456789]
    }
  }
}