返回首页

绕过 OpenClaw 中的 Anthropic 封锁:指南

文章分解通过代理链绕过针对 OpenClaw 的 Anthropic 服务器封锁。检测通过工具名称 subagents 和 session_status 发生。设置 CLIProxyAPI 和 Node.js replace-proxy 可使用 Pro 订阅无 Extra Usage。

如何在第三方客户端绕过 Anthropic 检测
Advertisement 728x90

绕过 Anthropic 服务器端第三方客户端封锁:技术详解

Anthropic 已在 API 请求来源处部署了服务器端检查。来自官方 Claude Code 和 Cowork 客户端的请求可享受 Pro 订阅权益。第三方工具如 OpenClaw 则被引导至“额外使用”模式,按 token 计费,导致成本大幅飙升。简单的 HTTP 请求伪造头部已不管用——服务器会深入检查请求体。

目标:让请求与官方客户端无异,同时保留 OpenClaw 的 17 种工具功能。

请求结构分析

Anthropic API 请求采用 JSON 负载,包含系统提示、消息历史、元数据和工具列表。测试显示:

Google AdInline article slot
  • 系统提示和历史通过检查。
  • 添加工具即触发检测。

按组拆解工具后,锁定罪魁祸首:

  • read、edit、write —— 通过。
  • exec、process —— 通过。
  • sessions_list、sessions_history、sessions_send —— 通过。
  • web_search、web_fetch —— 通过。
  • image、memory_search、memory_get —— 通过。
  • subagents —— 被阻。
  • session_status —— 被阻。

Anthropic 服务器扫描 JSON 体中不在 Claude Code 中的工具名。仅 17 种工具中的两种就足以触发“额外使用”。

代理链架构

解决方案:在 OpenClaw 与 api.anthropic.com 之间搭建双层代理。

Google AdInline article slot
  • CLIProxyAPI(Go 语言,GitHub 2.3 万星):模拟 Claude Code 头部(user-agent、计费头部、client_id)。OAuth 认证——代理生成 URL,你通过浏览器登录,refresh_token 本地存储。
  • Replace-proxy(Node.js,133 行代码,无依赖):双向拦截 JSON。

- 出站:subagentssub_dispatchsession_statuscheck_statusOpenClawAssistant

- 入站:逐行反向替换,支持流式传输。

链路:OpenClaw(8318 端口)→ replace-proxy → CLIProxyAPI(8317)→ api.anthropic.com。

Google AdInline article slot

Replace-proxy 以 systemd 服务运行,支持自动重启。

设置 Replace-Proxy

代理代码精简:HTTP 服务器解析体、应用正则替换,并缓冲流式事件。

// 示例片段:处理出站请求
const replaceMap = {
  'subagents': 'sub_dispatch',
  'session_status': 'check_status',
  'OpenClaw': 'Assistant'
};
// JSON.parse(body).tools.forEach(tool => {
//   if (replaceMap[tool.name]) tool.name = replaceMap[tool.name];
// });
// 响应类似处理

服务器监听 localhost:8318,转发至 CLIProxyAPI:8317。

配置 OpenClaw

openclaw.json 中添加提供者:

{
  "models": {
    "providers": {
      "custom-proxy": {
        "baseUrl": "http://localhost:8318",
        "apiKey": "<CLIProxyAPI 的 API 密钥>",
        "api": "anthropic-messages",
        "models": [
          {"id": "claude-opus-4-6", "contextWindow": 1000000, "maxTokens": 16384},
          {"id": "claude-sonnet-4-6", "contextWindow": 200000, "maxTokens": 16384}
        ]
      }
    }
  }
}

设为默认:

openclaw config set "agents.defaults.model.primary" "custom-proxy/claude-opus-4-6"

重启 OpenClaw。聊天中可切换模型。

关键要点

  • 工具检测:Anthropic 检查 JSON 体中的工具名。OpenClaw 独有工具(subagents、session_status)触发额外使用。
  • 双层代理:CLIProxyAPI 隐藏头部,replace-proxy 清洗内容。
  • OAuth 认证:CLIProxyAPI 自动刷新 token;refresh_token 过期时重新认证。
  • 流式支持:Replace-proxy 缓冲事件,实现实时替换。
  • 风险:违反 Anthropic 服务条款。账户可能被封;检测可能演进(提示模式、结构)。

局限与监控

  • 非生产环境:个人使用自担风险。
  • 监控:检查代理日志,排查替换错误或新检测。
  • 扩展:Systemd 确保稳定,但 Anthropic 更新可能需调整替换映射。

测试确认 Opus 4.6 和 Sonnet 4.6 无额外使用费用。

— Editorial Team

Advertisement 728x90

继续阅读