TypeScript
fix(server): restore Claude subscription usage through proxies (#12069)
Nand7e52513a13d9
diff --git a/apps/server/src/usage/cliproxyApi.test.ts b/apps/server/src/usage/cliproxyApi.test.tsindex ba7f5de41ac..bca612a044f 100644--- a/apps/server/src/usage/cliproxyApi.test.ts+++ b/apps/server/src/usage/cliproxyApi.test.ts@@ -317,8 +317,9 @@ describe("CLIProxyAPI built-in management API", () => {Effect.gen(function* () {const test = fixture({accounts: [{ ...accounts[0]!, provider: "claude" }],- upstream: () => ({- status: 200,+ // The usage endpoint answers 429 to requests without a Claude Code user agent.+ upstream: (request) => ({+ status: request.header?.["User-Agent"]?.startsWith("claude-code/") ? 200 : 429,body: {five_hour: { utilization: 10, resets_at: null },seven_day: { utilization: 50, resets_at: "2099-01-01T00:00:00Z" },diff --git a/apps/server/src/usage/cliproxyApi.ts b/apps/server/src/usage/cliproxyApi.tsindex f097aa7a358..4c981b96dfb 100644--- a/apps/server/src/usage/cliproxyApi.ts+++ b/apps/server/src/usage/cliproxyApi.ts@@ -214,7 +214,12 @@ export const makeCliproxyApi = Effect.gen(function* () {? { "Chatgpt-Account-Id": account.id_token.chatgpt_account_id }: {}),}- : { Authorization: "Bearer $TOKEN$", "anthropic-beta": "oauth-2025-04-20" };+ : {+ Authorization: "Bearer $TOKEN$",+ "anthropic-beta": "oauth-2025-04-20",+ // The OAuth usage endpoint can return 429 without a Claude Code user agent.+ "User-Agent": "claude-code/2.1.273",+ };const raw = yield* management(config, "api-call", {auth_index: account.auth_index,method: data === undefined ? "GET" : "POST",