跳转到主要内容

配置文件位置

OpenClaw 使用 JSON 配置文件,位于 ~/.openclaw/openclaw.json

基础配置

创建或编辑配置文件 ~/.openclaw/openclaw.json
{
  "agents": {
    "defaults": {
      "model": { "primary": "apiyi/gpt-5.4" }
    }
  },
  "models": {
    "providers": {
      "apiyi": {
        "baseUrl": "https://api.apiyi.com/v1",
        "apiKey": "sk-你的API易密钥",
        "api": "openai-completions",
        "models": [
          { "id": "gpt-5.4", "name": "GPT-5.4" },
          { "id": "claude-sonnet-4-6", "name": "Claude Sonnet 4" },
          { "id": "deepseek-v3.2", "name": "DeepSeek V3.2" },
          { "id": "gemini-3.1-pro-preview", "name": "Gemini 3.1 Pro" }
        ]
      }
    }
  }
}

配置字段说明

字段说明
agents.defaults.model.primary默认模型,格式为 provider名/模型名
models.providers自定义模型提供商配置
baseUrlAPI 地址,使用 https://api.apiyi.com/v1
apiKey你的 API易 密钥
apiAPI 类型:OpenAI 兼容用 openai-completions,Anthropic 兼容用 anthropic-messages

多模型配置

可以配置多个模型,在聊天中用 /model <id> 切换:
{
  "models": {
    "providers": {
      "apiyi": {
        "baseUrl": "https://api.apiyi.com/v1",
        "apiKey": "sk-你的密钥",
        "api": "openai-completions",
        "models": [
          { "id": "gpt-5.4", "name": "GPT-5.4" },
          { "id": "claude-sonnet-4-6", "name": "Claude Sonnet 4" },
          { "id": "deepseek-v3.2", "name": "DeepSeek V3.2" }
        ]
      }
    }
  }
}

完整配置示例

包含模型配置和 Telegram 渠道的完整示例:
{
  "agents": {
    "defaults": {
      "model": { "primary": "apiyi/gpt-5.4" }
    }
  },
  "models": {
    "providers": {
      "apiyi": {
        "baseUrl": "https://api.apiyi.com/v1",
        "apiKey": "sk-你的API易密钥",
        "api": "openai-completions",
        "models": [
          { "id": "gpt-5.4", "name": "GPT-5.4" },
          { "id": "claude-sonnet-4-6", "name": "Claude Sonnet 4" },
          { "id": "deepseek-v3.2", "name": "DeepSeek V3.2" }
        ]
      }
    }
  },
  "channels": {
    "telegram": {
      "enabled": true,
      "accounts": {
        "default": {
          "token": "你的Telegram Bot Token"
        }
      }
    }
  }
}
配置文件修改后,需要重启 Gateway 服务才能生效:
openclaw gateway restart