Skip to content
广告 · 本站推荐广告

配置参考

本文档列出 Gateway 所有可用配置项及其默认值、类型说明和使用示例。

General(通用配置)

配置项类型默认值说明
gateway.portnumber18789监听端口
gateway.hoststring"127.0.0.1"绑定地址
gateway.reloadModestring"hybrid"热加载模式:off / hot / restart / hybrid
gateway.logLevelstring"info"日志级别:trace / debug / info / warn / error
gateway.dataDirstring"~/.openclaw"数据存储目录
gateway.maxSessionsnumber50最大并发会话数
gateway.sessionTimeoutnumber86400会话超时时间(秒)
json5
{
  "gateway": {
    "port": 18789,
    "host": "127.0.0.1",
    "reloadMode": "hybrid",
    "logLevel": "info",
    "dataDir": "~/.openclaw",
    "maxSessions": 50,
    "sessionTimeout": 86400
  }
}

Channels(通道配置)

配置 LLM(大语言模型)提供商连接。

配置项类型默认值说明
channels[].namestring通道名称(唯一标识)
channels[].providerstring提供商:openai / anthropic / google / ollama
channels[].apiKeystringAPI 密钥(推荐使用 Secrets 管理)
channels[].baseUrlstring提供商默认自定义 API 端点
channels[].modelsstring[]["*"]允许使用的模型列表
channels[].maxConcurrencynumber10最大并发请求数
channels[].timeoutnumber120000请求超时(毫秒)
channels[].retriesnumber2失败重试次数
json5
{
  "channels": [
    {
      "name": "openai-main",
      "provider": "openai",
      "apiKey": "${OPENAI_API_KEY}",   // 引用环境变量
      "models": ["gpt-4o", "gpt-4o-mini"],
      "maxConcurrency": 10,
      "timeout": 120000,
      "retries": 2
    }
  ]
}

密钥引用

使用 ${VAR_NAME} 语法引用环境变量或 Secrets 中的值,避免在配置文件中明文存储密钥。

Models(模型路由)

配置项类型默认值说明
models.defaultstring默认模型标识
models.routingobject{}模型到 Channel 的路由映射
models.fallbackstring[][]模型不可用时的回退链
json5
{
  "models": {
    "default": "gpt-4o",
    "routing": {
      "gpt-4o": "openai-main",
      "claude-sonnet-4-20250514": "anthropic-main"
    },
    "fallback": ["gpt-4o-mini"]
  }
}

Automation(自动化配置)

配置项类型默认值说明
automation.heartbeat.enabledbooleantrue是否启用心跳
automation.heartbeat.intervalnumber60000心跳间隔(毫秒)
automation.autoApprovestring[][]自动批准的工具列表
automation.maxTurnsnumber25单次对话最大轮次
json5
{
  "automation": {
    "heartbeat": {
      "enabled": true,
      "interval": 60000
    },
    "autoApprove": ["read_file", "list_files"],
    "maxTurns": 25
  }
}

Security(安全配置)

配置项类型默认值说明
security.sandbox.enabledbooleantrue启用沙箱隔离
security.sandbox.modestring"standard"沙箱模式:off / standard / strict
security.toolPolicy.deniedstring[][]禁用的工具列表
security.toolPolicy.requireApprovalstring[]["execute_command"]需要人工批准的工具
security.trustedProxy.enabledbooleanfalse启用可信代理认证
security.trustedProxy.headersstring[]["X-Forwarded-For"]可信头列表
json5
{
  "security": {
    "sandbox": {
      "enabled": true,
      "mode": "standard"
    },
    "toolPolicy": {
      "denied": ["dangerous_tool"],
      "requireApproval": ["execute_command", "write_file"]
    },
    "trustedProxy": {
      "enabled": false,
      "headers": ["X-Forwarded-For"]
    }
  }
}

安全配置

修改安全配置前,请仔细阅读 安全概览沙箱机制,了解各选项的安全影响。

Authentication(认证配置)

配置项类型默认值说明
gateway.auth.methodstring"token"认证方式:token / password / both
gateway.auth.rateLimitAttemptsnumber5最大失败尝试次数
gateway.auth.rateLimitWindownumber60速率限制窗口(秒)
gateway.auth.sessionTimeoutnumber86400会话超时(秒)

环境变量映射

所有配置项可通过环境变量覆盖:

text
gateway.port                         → OPENCLAW_GATEWAY_PORT
gateway.host                         → OPENCLAW_GATEWAY_HOST
gateway.auth.method                  → OPENCLAW_GATEWAY_AUTH_METHOD
security.sandbox.mode                → OPENCLAW_SECURITY_SANDBOX_MODE
automation.heartbeat.interval        → OPENCLAW_AUTOMATION_HEARTBEAT_INTERVAL

相关文档

基于MIT协议开源 | 内容翻译自 官方文档,同步更新