any路由器因为跟claude code有一些参数适配的问题,所以我们可以在本地架设一个简单的网关,将参数在本地拦截,然后修改一下,再传给any大善人,就可以绕过这些参数适配的小问题了。 claudecode最新版本适用,不需要回退版本 这个本地网关做了什么 在本地监听 127.0.0.1:1998。 把 Claude Code 的请求转发到上游any的端口。 自动补认证头(Authorization / x-api-key)。 对 haiku 请求额外修正:补 context-1m-2025-08-07,并加 thinking.budget_tokens=1024。 把请求和响应写到 gateway_requests.jsonl 方便排错。 极简启动步骤 先开网关 export ANTHROPIC_BASE_URL=“any大善人地址” export ANTHROPIC_AUTH_TOKEN=“你的真实token” python3 /Users/Apple/Desktop/code/claude_gateway.py 新开一个终端再开 Claude Code ANTHROPIC_BASE_URL=“ http://127.0.0.1:1998 ” claude --enable-auto-mode 截图为证: 网关代码如下(vibe写的,很多冗余,大佬可以自行修改): #!/usr/bin/env python3 import base64 import json import os import threading from datetime import datetime, timezone from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer from urllib.error import HTTPError, URLError from urllib.parse import urlsplit, urlunsplit from urllib.request import Request, urlopen LISTEN_HOST = os.getenv("CLAUDE_GATEWAY_HOST", "127.0.0.1") LISTEN_PORT = int(os.getenv("CLAUDE_GATEWAY_PORT", "1998")) UPSTREAM_BASE_URL = os.getenv( "ANTHROPIC_BASE_URL", "https://a-ocnfniawgw.cn-shanghai.fcapp.run" ) UPSTREAM_AUTH_TOKEN = os.getenv("ANTHROPIC_AUTH_TOKEN", "") UPSTREAM_TIMEOUT = float(os.getenv("CLAUDE_GATEWAY_TIMEOUT", "120")) LOG_PATH = os.getenv( "CLAUDE_GATEWAY_LOG", os.path.join(os.path.dirname(__file__), "gateway_requests.jsonl") ) LOG_LOCK = threading.Lock() def utc_now_iso() -> str: return datetime.now(timezone.utc).isoformat() def ensure_log_parent_exists() -> None: parent = os.path.dirname(LOG_PATH) if parent: os.makedirs(parent, exist_ok=True) def decode_body_for_log(body: bytes) -> dict: if not body: return {"encoding": "utf-8", "text": ""} try: return {"encoding": "utf-8", "text": body.decode("utf-8")} except UnicodeDecodeError: return {"encoding": "base64", "text": base64.b64encode(body).decode("ascii")} def append_log(record: dict) -> None: ensure_log_parent_exists() line = json.dumps(record, ensure_ascii=False) with LOG_LOCK: with open(LOG_PATH, "a", encoding="utf-8") as f: f.write(line + "\n") def build_upstream_url(base_url: str, incoming_path: str) -> str: base = urlsplit(base_url) incoming = urlsplit(incoming_path) incoming_path_only = incoming.path or "/" base_path = base.path.rstrip("/") if base_path: merged_path = f"{base_path}{incoming_path_only}" else: merged_path = incoming_path_only return urlunsplit((base.scheme, base.netloc, merged_path, incoming.query, "")) def rewrite_request_headers(headers: dict, path: str) -> dict: rewritten = dict(headers) if UPSTREAM_AUTH_TOKEN: has_x_api_key = any(k.lower() == "x-api-key" for k in rewritten) has_authorization = any(k.lower() == "authorization" for k in rewritten) if not has_x_api_key: rewritten["x-api-key"] = UPSTREAM_AUTH_TOKEN if not has_authorization: rewritten["Authorization"] = f"Bearer {UPSTREAM_AUTH_TOKEN}" # 先做骨架,后续按 any 规则逐步覆写。 return rewritten def rewrite_request_body(body: bytes, headers: dict, path: str) -> bytes: if not body: return body content_type = "" for k, v in headers.items(): if k.lower() == "content-type": content_type = v break if "application/json" not in content_type.lower(): return body try: payload = json.loads(body.decode("utf-8")) except (UnicodeDecodeError, json.JSONDecodeError): return body model = str(payload.get("model", "")).lower() if not model.startswith("claude-haiku"): return body beta_key = None for k in headers.keys(): if k.lower() == "anthropic-beta": beta_key = k break raw_beta = headers.get(beta_key, "") if beta_key else "" beta_features = [item.strip() for item in raw_beta.split(",") if item.strip()] if "context-1m-2025-08-07" not in beta_features: beta_features.append("context-1m-2025-08-07") merged_beta = ",".join(beta_features) if beta_key: headers[beta_key] = merged_beta else: headers["anthropic-beta"] = merged_beta payload["thinking"] = {"type": "enabled", "budget_tokens": 1024} return json.dumps(payload, ensure_ascii=False, separators=(",", ":")).encode("utf-8") class ClaudeGatewayHandler(BaseHTTPRequestHandler): protocol_version = "HTTP/1.1" def do_GET(self): self._handle_proxy() def do_POST(self): self._handle_proxy() def do_PUT(self): self._handle_proxy() def do_PATCH(self): self._handle_proxy() def do_DELETE(self): self._handle_proxy() def do_OPTIONS(self): self._handle_proxy() def do_HEAD(self): self._handle_proxy() def log_message(self, fmt, *args): return def _read_request_body(self) -> bytes: content_length = int(self.headers.get("Content-Length", "0") or "0") if content_length <= 0: return b"" return self.rfile.read(content_length) def _copy_request_headers(self) -> dict: headers = {} for key, value in self.headers.items(): key_l = key.lower() if key_l in {"host", "content-length", "connection", "accept-encoding"}: continue headers[key] = value return headers def _send_response(self, status: int, headers: dict, body: bytes) -> None: self.send_response(status) ignored = {"transfer-encoding", "content-length", "connection"} for k, v in headers.items(): if k.lower() in ignored: continue self.send_header(k, v) self.send_header("Content-Length", str(len(body))) self.send_header("Connection", "close") self.end_headers() if self.command != "HEAD" and body: self.wfile.write(body) def _handle_proxy(self): req_body = self._read_request_body() req_headers = self._copy_request_headers() req_headers = rewrite_request_headers(req_headers, self.path) req_body = rewrite_request_body(req_body, req_headers, self.path) upstream_url = build_upstream_url(UPSTREAM_BASE_URL, self.path) request_log = { "timestamp": utc_now_iso(), "client_ip": self.client_address[0] if self.client_address else "", "method": self.command, "path": self.path, "upstream_url": upstream_url, "headers": dict(self.headers.items()), "body": decode_body_for_log(req_body), "body_length": len(req_body), } try: upstream_req = Request( url=upstream_url, data=req_body if req_body else None, headers=req_headers, method=self.command, ) with urlopen(upstream_req, timeout=UPSTREAM_TIMEOUT) as resp: resp_status = resp.getcode() resp_headers = dict(resp.headers.items()) resp_body = resp.read() request_log["response"] = { "status": resp_status, "headers": resp_headers, "body": decode_body_for_log(resp_body), "body_length": len(resp_body), } append_log(request_log) self._send_response(resp_status, resp_headers, resp_body) return except HTTPError as e: err_body = e.read() if hasattr(e, "read") else b"" err_headers = dict(e.headers.items()) if getattr(e, "headers", None) else {} request_log["response"] = { "status": e.code, "headers": err_headers, "body": decode_body_for_log(err_body), "body_length": len(err_body), } append_log(request_log) self._send_response(e.code, err_headers, err_body) return except (URLError, TimeoutError, Exception) as e: error_payload = { "error": "gateway_upstream_error", "message": str(e), } error_body = json.dumps(error_payload, ensure_ascii=False).encode("utf-8") request_log["response"] = { "status": 502, "headers": {"Content-Type": "application/json; charset=utf-8"}, "body": {"encoding": "utf-8", "text": error_body.decode("utf-8")}, "body_length": len(error_body), } append_log(request_log) self._send_response( 502, {"Content-Type": "application/json; charset=utf-8"}, error_body, ) def main(): server = ThreadingHTTPServer((LISTEN_HOST, LISTEN_PORT), ClaudeGatewayHandler) print(f"[gateway] listening on http://{LISTEN_HOST}:{LISTEN_PORT}") print(f"[gateway] upstream: {UPSTREAM_BASE_URL}") print(f"[gateway] auth token configured: {bool(UPSTREAM_AUTH_TOKEN)}") print(f"[gateway] log file: {LOG_PATH}") server.serve_forever() if __name__ == "__main__": main() 1 个帖子 - 1 位参与者 阅读完整话题
这么高缓存命中,太原生了,真是一点没掺水啊。有缓存真的价格低了好多 39 个帖子 - 25 位参与者 阅读完整话题
当前对话出现retry,重开另一个session却可以正常使用,切回原对话还是retry 。这是any轮询的问题吗?还是新版cluade code的原因 而且感觉any现在retrying明显变多了 个人感觉还和上下文有关,上下文一长retry出现概率更大 报错多为: API Error: 503 {“error”:{“message”:“Service Unavailable”,“type”:“error”},“type”:“error”} · check status.claude.com 明明前一周还能爽蹬 2 个帖子 - 2 位参与者 阅读完整话题
已经三周周限了不能使用 any 每次使用告诉我下周再试,已经几乎要心灰意冷了。今天居然可以用了。 4 个帖子 - 4 位参与者 阅读完整话题
用的 any 的 opus 4.7,感觉一股 gpt 味,项目研究也不如 5.3-codex 1 个帖子 - 1 位参与者 阅读完整话题
求问佬们 这是什么情况呢 14 个帖子 - 9 位参与者 阅读完整话题
自从any大善人的cc不稳定之后,我立刻转向了codex的怀抱,前两天any大善人更新了4.7之后,我赶紧在晚上体验了下,但是体验之后我只有两个感受,一个是any好久没有这么快了,另一个就是我发现这个快好像是建立在没有explore和委托subagent的前提下的。我是在我的实验项目文件夹下启动cc的,我自认为我的项目是足够复杂的,毕竟我做这个实验做了三个多月,vibe的内容多到爆炸,然后那天晚上我让cc去帮我分析实现下一步如何进一步提升结果,cc思考了一下就直接输出了。虽然很久没有使用cc了,但是我印象中cc在处理大型项目之前不是惯例会使用explore的嘛?是只有我有这个问题还是cc真的降低工具调用频率了? 5 个帖子 - 4 位参与者 阅读完整话题
Read an article about analyzing Garmin data with AI. Sounded great — except I didn't want to send my health data to any cloud service. So I asked Claude to write me 2-3 scripts and a dashboard. This escalated a bit. 30 days and 20$ later I have this: A local-first Garmin archive with interactive HTML dashboards, Excel exports, weather and pollen context, AES-256 encrypted token storage, and a self-healing data pipeline with 515 automated tests. Windows desktop app, no terminal needed. Nothing leaves your machine. I never wrote a line of Python. I understood the problems and made the architectural decisions. Claude wrote everything else. GitHub: github.com/Wewoc/Garmin_Local_Archive Comments URL: https://news.ycombinator.com/item?id=47814208 Points: 2 # Comments: 0
今天闲的没事干试了试any能不能用,甚至还出新模型了 4 个帖子 - 4 位参与者 阅读完整话题
已经在cc-switch中勾选了应用到vscode中,cc插件更新到最新版本,不选opus 1m会提示1m 上下文已经全量可用,选了1m,报错如下,终端的话是正常使用的: 1 个帖子 - 1 位参与者 阅读完整话题
API Error: 400 {“error”:“claude-opus-4-6 已下线,请切换到 claude-opus-4-7 模型”,“type”:“error”} no,我不要伪人 4.7 啊,我要 4.6 这是opus4.7调用超时的报错,是官转吗 API Error: 503 {“error”:{“message”:“ServiceUnavailable”,“type”:“error”},“type”:“error”} · check status.claude.com 3 个帖子 - 3 位参与者 阅读完整话题
版本2.1.112 兄弟们加油蹬。 CC这边我是这样设置的: 8 个帖子 - 6 位参与者 阅读完整话题
AnyRouter的怎么API要怎么接入我的IDE? 原理:客户端中子代理在请求体里不传递思考参数,haiku请求头不带1M,导致any后端校验不正确,所以请求会错误。 知道原理就好干了,以cch为例。 1.给any的所有请求,追加请求头,写入1M 这个请求头是直接在我IDE(Breezell)的API设置里面添加吗? 有佬可以发一下请求头JSON吗? 1 个帖子 - 1 位参与者 阅读完整话题
我已经被any大善人周限好几周了,然后因为claude 4.7出来了,昨天升级了一下cc到2.1.112版本,抱着测试的心态用了一下any大善人的key,没想到可以跑了。 然后我就安心睡觉了,等待今天猛猛用了,然后今天顺手升级了一下cc到114,发现因为a/的原因114版本在Windows有兼容性问题 就把包退到110版本了,因为说是口碑比较好的一个版本嘛,没想到在110版本使用any大善人就又503了…… 此时我以为是any又抽风了呢,怎么配模型都是什么503,429啥的各种报错。 一起之下就又升级到112版本,发现又可以用了 所以如果你也被any大善人的玄学可用性困扰,不妨按一下cc 112版本试试。不过只是玄学哈,不保证一定可行,佬们如果不行勿喷。 11 个帖子 - 5 位参与者 阅读完整话题
还挺快的,就是4.7没4.6好用 1 个帖子 - 1 位参与者 阅读完整话题
用了两三条消息然后突然就这样了。claude4.7,什么原因有没有大佬? 2 个帖子 - 2 位参与者 阅读完整话题
2 个帖子 - 2 位参与者 阅读完整话题
一个月没用AnyRouter了,今天cursor月付到期又用回了AnyRouter。然后看到了 。 随后来到了AnyRouter里,发现了公告: 但是很明显,定价里面并没有那个模型写上了1m。 解决方案:给你的每个模型后面手动加上一个[1m](雾 又是水帖的一天。。。 6 个帖子 - 6 位参与者 阅读完整话题
3 个帖子 - 2 位参与者 阅读完整话题
坏消息:两个工具同时故障: 后台 Agent:连续 500 panic(服务端问题) WebSearch:返回"1m 上下文已经全量可用,请启用 1m 上下文后重试"——需要你在界面里启用 1M context 才能走通 是否有佬遇到过类似问题,恳请交流分享 4 个帖子 - 3 位参与者 阅读完整话题