fix(openrouter): stop leaking Anthropic auth headers to fallback providers - #8
Merged
Merged
Conversation
…iders buildProviderHeaders forwarded all of Claude Code's incoming headers to OpenRouter/Z.AI except 4 hop-by-hop ones, including x-api-key. OpenRouter treats a stray x-api-key as a restricted data-policy request and returns '404: No endpoints available matching your guardrail restrictions' — so the OpenRouter fallback was dead for every real (Claude Code) request, even though the model slug and endpoint were correct. Strip Anthropic-specific routing/auth headers (x-api-key, anthropic-version, anthropic-beta, anthropic-dangerous-direct-browser-access) and content-length (recomputed after cleanBody) from the cross-provider passthrough. Verified end-to-end: OpenRouter now returns 200 with full Opus via ~anthropic/claude-opus-latest.
0xPuncker
force-pushed
the
feat/run-podman-containers
branch
from
June 24, 2026 20:04
e676c40 to
6ccfc70
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The OpenRouter fallback was returning 404 on every real request — not because of the model slug or endpoint (both correct), but because the proxy leaked Claude Code's
x-api-keyheader to OpenRouter.Root cause
buildProviderHeadersforwarded all of Claude Code's incoming headers to OpenRouter/Z.AI, stripping only 4 hop-by-hop headers (authorization,transfer-encoding,connection,host). Claude Code always sendsx-api-key(its Anthropic auth header). When OpenRouter receives a strayx-api-key, its privacy/guardrail layer routes the request into a restricted data-policy path and returns:The proxy logged the gzip-compressed error body as raw bytes (
� ��1), which hid the real message.Reproduced deterministically against live OpenRouter:
POST /api/v1/messageswith~anthropic/claude-opus-latest, nox-api-key→ 200x-api-key→ 404 (guardrail)Fix
Strip Anthropic-specific routing/auth headers from the cross-provider passthrough in
buildProviderHeaders:x-api-key,anthropic-version,anthropic-beta,anthropic-dangerous-direct-browser-access, pluscontent-length(recomputed aftercleanBody). Refactored both branches (zai + openrouter) to share oneblockedForwardHeadersdeny-list, with case-insensitive matching.Verification
tsc+eslintclean; 102/102 tests pass (the existing OpenRouter test now also assertsx-api-key/anthropic-*are stripped and OpenRouter's own auth/attribution headers are present).anthropic/claude-4.8-opusvia OpenRouter — full Opus, no downgrade, no 404.Follow-up to #6 (which fixed the Opus→Sonnet mapping; this fixes why that corrected slug still 404'd).