feat(gateway): accept legacy X-AnyLLM-Key header for back-compat#50
Merged
feat(gateway): accept legacy X-AnyLLM-Key header for back-compat#50
Conversation
PR #45 renamed the auth header from X-AnyLLM-Key to AnyLLM-Key (RFC 6648) without a migration path. Restore back-compat by also accepting the legacy X-AnyLLM-Key header. Precedence is AnyLLM-Key > X-AnyLLM-Key > Authorization, so the canonical header continues to win when both are sent. - core/config.py: add LEGACY_API_KEY_HEADER constant. - api/deps.py: check the legacy header in _extract_bearer_token between the canonical header and Authorization fallback. - main.py: allow the legacy header through CORS preflight. - tests/unit/test_extract_bearer_token.py: cover legacy header success, precedence vs. canonical and Authorization, and malformed legacy.
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
X-AnyLLM-KeytoAnyLLM-Key(RFC 6648) without a migration path, breaking any client still sending the old name.X-AnyLLM-Keyas an alias ofAnyLLM-Key. Precedence isAnyLLM-Key>X-AnyLLM-Key>Authorization, so the canonical header wins when both are present.Changes
src/gateway/core/config.py: addLEGACY_API_KEY_HEADER = "X-AnyLLM-Key"constant.src/gateway/api/deps.py: include the legacy header in_extract_bearer_token, between the canonical header and theAuthorizationfallback.src/gateway/main.py: addLEGACY_API_KEY_HEADERto the CORSallow_headerslist.tests/unit/test_extract_bearer_token.py: cover legacy-header success, canonical-beats-legacy precedence, legacy-beats-Authorization precedence, and malformed-legacy-raises-401.Scope notes
x-api-keyshim removed in e26c7c3 is not reintroduced here.Test plan
uv run pytest tests/unit/test_extract_bearer_token.py -v— 10 pass (4 new + 6 existing).uv run pytest tests/unit tests/integration/test_messages_endpoint.py tests/integration/test_client_args.py tests/integration/test_provider_kwargs_override.py -v— 97 pass.uv run ruff check src tests scripts— clean.uv run mypy src— clean.uv run python scripts/generate_openapi.py --check— up to date.