注册 登录
📝注册 🔑登录 🌙夜间模式
加载中...
内容已复制到剪贴板!
← 返回列表

openClaw的配置

作者: super Ai | 创建时间: 2026-02-23 05:25 | 更新时间: 2026-03-04 00:01 | 👁️ 282 次阅读

~/.openclaw/openclaw.json最终正确配置

{
  "env": {},
  "models": {
    "providers": {
      "aimath": {
        "api": "anthropic-messages",
        "baseUrl": "https://router.aimath.top",
        "apiKey": "sk-你的密钥",
        "models": [
          {
            "id": "claude-sonnet-4-5-20250929",
            "name": "Sonnet",
            "contextWindow": 128000,
            "maxTokens": 4096,
            "reasoning": false,
            "input": [
              "text"
            ],
            "cost": {
              "input": 0,
              "output": 0,
              "cacheRead": 0,
              "cacheWrite": 0
            }
          }
        ]
      }
    }
  },
  "agents": {
    "defaults": {
      "model": {
        "primary": "aimath/claude-sonnet-4-5-20250929"
      },
      "models": {
        "aimath/claude-sonnet-4-5-20250929": {
          "alias": "sonnet"
        }
      },
      "maxConcurrent": 4,
      "subagents": {
        "maxConcurrent": 8
      }
    }
  },
  "commands": {
    "native": "auto",
    "nativeSkills": "auto"
  },
  "hooks": {
    "enabled": false,
    "path": "/hooks",
    "mappings": []
  },
  "gateway": {
    "port": 18789,
    "mode": "local",
    "auth": {
      "mode": "token",
      "token": "my-password-2026"
    },
    "remote": {
      "token": "my-password-2026"
    }
  },
  "plugins": {
    "enabled": false,
    "allow": [],
    "entries": {}
  },
  "messages": {
    "ackReactionScope": "group-mentions"
  },
  "meta": {
    "lastTouchedVersion": "2026.1.30",
    "lastTouchedAt": "2026-02-08T19:33:44.813Z"
  }
}

关键配置说明

1. Models Provider 配置

"aimath": {
  "api": "anthropic-messages",           // 必须使用此API类型
  "baseUrl": "https://router.aimath.top", // 不要包含 /v1 路径
  "apiKey": "你的API密钥"
}

重要提示:

  • 使用 New API 中转服务时,必须使用 anthropic-messages 作为 API 类型
  • baseUrl 不要包含 /v1,因为 anthropic-messages 会自动添加 /v1/messages 路径
  • 如果 baseUrl 包含 /v1,会导致路径变成 /v1/v1/messages 返回 404 错误

2. Gateway 配置

"gateway": {
  "port": 18789,
  "mode": "local",
  "auth": {
    "mode": "token",
    "token": "my-password-2026"
  },
  "remote": {
    "token": "my-password-2026"  // 必须与 auth.token 一致
  }
}

重要提示:

  • gateway.mode 必须设置(local 或 remote)
  • gateway.remote.token 必须与 gateway.auth.token 一致,否则会出现 token mismatch 错误

3. Hooks 配置

"hooks": {
  "enabled": false,  // 如果没有配置 hooks.token,必须设为 false
  "path": "/hooks",
  "mappings": []
}

重要提示:

  • 如果 hooks.enabled 设为 true,必须提供 hooks.token
  • 否则 gateway 会启动失败,报错 "hooks.enabled requires hooks.token"

4. Plugins 配置

"plugins": {
  "enabled": false,  // 如果插件配置不完整,建议禁用
  "allow": [],
  "entries": {}
}

OpenClaw 支持的 API 类型

根据源码分析,OpenClaw 支持以下 API 类型:

  1. anthropic-messages - Anthropic Claude API
  2. openai-completions - OpenAI Completions API
  3. openai-responses - OpenAI Chat Completions API
  4. azure-openai-responses - Azure OpenAI API
  5. openai-codex-responses - OpenAI Codex API
  6. google-generative-ai - Google Gemini API
  7. google-gemini-cli - Google Gemini CLI
  8. google-vertex - Google Vertex AI
  9. bedrock-converse-stream - AWS Bedrock API

常用命令

启动和管理

# 检查配置和健康状态
openclaw doctor

# 启动 gateway
openclaw gateway install

# 强制启动 gateway(杀死占用端口的进程)
openclaw gateway --force

# 停止 gateway
openclaw gateway stop

# 检查 gateway 健康状态
openclaw health

# 查看 gateway 状态
openclaw status

使用 OpenClaw

# 打开控制面板(浏览器)
openclaw dashboard

# 启动终端界面
openclaw tui

# 直接发送消息测试
openclaw agent --agent main --message "你的消息" --local

# 查看配置的模型
openclaw models list

配置管理

# 交互式配置向导
openclaw configure

# 设置配置项
openclaw config set gateway.remote.token "your-token"

# 获取配置项
openclaw config get gateway.mode

# 查看完整配置
cat ~/.openclaw/openclaw.json

测试 API 连接

可以使用 curl 测试 New API 中转服务是否正常:

curl -X POST "https://router.aimath.top/v1/chat/completions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-你的密钥" \
  -d '{
    "model": "claude-sonnet-4-5-20250929",
    "messages": [{"role": "user", "content": "test"}],
    "max_tokens": 10
  }'

故障排查

1. Gateway 无法启动

检查日志:

tail -50 ~/.openclaw/logs/gateway.log

常见原因:

  • 端口被占用:使用 openclaw gateway --force 强制启动
  • 配置错误:运行 openclaw doctor 检查
  • Hooks 配置问题:确保 hooks.enabled: false 或提供 hooks.token

2. Token Mismatch 错误

错误信息:

unauthorized: gateway token mismatch

解决方法:

openclaw config set gateway.remote.token "与auth.token相同的值"

3. 模型无响应

检查步骤:

  1. 确认 API 类型正确(使用 anthropic-messages
  2. 确认 baseUrl 不包含 /v1
  3. 测试 API 密钥是否有效
  4. 查看 gateway 日志排查错误

4. 配置验证错误

运行修复命令:

openclaw doctor --fix

手动修复:

  • 移除所有 "//" 注释键
  • 确保所有必需字段都已设置
  • 检查字段值是否符合要求

New API 中转服务说明

  • 服务地址: https://router.aimath.top
  • API 密钥: sk-8a你的密钥
  • 兼容格式: OpenAI API 格式(但需要使用 anthropic-messages API 类型)
  • 支持模型: claude-sonnet-4-5-20250929

配置文件位置

  • 主配置文件: ~/.openclaw/openclaw.json
  • Gateway 日志: ~/.openclaw/logs/gateway.log
  • 会话存储: ~/.openclaw/agents/main/sessions/
  • LaunchAgent: ~/Library/LaunchAgents/ai.openclaw.gateway.plist

成功验证

配置完成后,运行以下命令验证:

# 1. 检查配置
openclaw doctor

# 2. 测试模型响应
openclaw agent --agent main --message "你好,请回复测试" --local

如果收到模型的正常回复,说明配置成功!

评论 (0)

请先登录后发表评论

暂无评论,快来抢沙发吧!