Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
fix: deduplicate case-variant anthropic-version header in Claude Code patch (#1481)
cloudyde1bea8227ca
diff --git a/open-sse/executors/base.ts b/open-sse/executors/base.tsindex 2857a087f9..38c9d62dfc 100644--- a/open-sse/executors/base.ts+++ b/open-sse/executors/base.ts@@ -531,6 +531,17 @@ export class BaseExecutor {"x-client-request-id": randomUUID(),"X-Claude-Code-Session-Id": randomUUID(),};+ // Remove any existing case variants of ccHeaders keys before merging.+ // The claude provider config sets "Anthropic-Version" (Title-Case) while+ // ccHeaders uses all-lowercase keys. Both JS keys normalise to the same+ // HTTP header name, so undici would combine them into "2023-06-01, 2023-06-01"+ // causing a 400 from Anthropic (see issue #1454).+ const ccKeysLower = new Set(Object.keys(ccHeaders).map((k) => k.toLowerCase()));+ for (const key of Object.keys(headers)) {+ if (ccKeysLower.has(key.toLowerCase())) {+ delete headers[key];+ }+ }Object.assign(headers, ccHeaders);delete headers["X-Stainless-Helper-Method"];diff --git a/tests/unit/executor-default-base.test.ts b/tests/unit/executor-default-base.test.tsindex a76ddfbafe..5d1ce319f9 100644--- a/tests/unit/executor-default-base.test.ts+++ b/tests/unit/executor-default-base.test.ts@@ -789,3 +789,51 @@ test("BaseExecutor.execute clears the startup timeout after headers arrive", asyglobalThis.fetch = originalFetch;}});++// Regression test for issue #1454: duplicate anthropic-version header when+// Claude Code CLI headers are detected on the native `claude` provider.+// The provider config seeds headers with Title-Case "Anthropic-Version" while+// the Claude-Code patch injects lowercase "anthropic-version". Before the fix,+// both keys coexisted in the JS object and undici combined their values into+// "2023-06-01, 2023-06-01", causing a 400 from Anthropic.+test("DefaultExecutor.execute does not produce duplicate anthropic-version header when Claude Code CLI headers are present", async () => {+ const executor = new DefaultExecutor("claude");+ const originalFetch = globalThis.fetch;+ let capturedHeaders: Record<string, string> = {};++ globalThis.fetch = async (_url, init = {}) => {+ // Capture raw headers without normalisation so case-variant duplicate keys are visible.+ capturedHeaders = (init.headers as Record<string, string>) || {};+ return new Response(JSON.stringify({ ok: true }), {+ status: 200,+ headers: { "Content-Type": "application/json" },+ });+ };++ try {+ await executor.execute({+ model: "claude-sonnet-4-6",+ body: {+ model: "claude-sonnet-4-6",+ messages: [{ role: "user", content: "hi" }],+ max_tokens: 1,+ },+ stream: false,+ credentials: { accessToken: "oauth-token" },+ clientHeaders: {+ "x-app": "cli",+ "user-agent": "claude-cli/2.1.116 (external, cli)",+ "anthropic-beta": "oauth-2025-04-20",+ },+ });+ } finally {+ globalThis.fetch = originalFetch;+ }++ // Must be exactly one key — not multiple case variants that undici would combine+ const versionKeys = Object.keys(capturedHeaders).filter(+ (k) => k.toLowerCase() === "anthropic-version"+ );+ assert.equal(versionKeys.length, 1, "Duplicate anthropic-version header keys found");+ assert.equal(capturedHeaders[versionKeys[0]], "2023-06-01");+});