feat(gateway): rename auth header to AnyLLM-Key (RFC 6648)#45
feat(gateway): rename auth header to AnyLLM-Key (RFC 6648)#45
Conversation
There was a problem hiding this comment.
Pull request overview
Introduces AnyLLM-Key as the canonical gateway auth header while continuing to accept X-AnyLLM-Key (legacy) with explicit deprecation signaling for clients that still use it.
Changes:
- Update auth token extraction to prefer
AnyLLM-KeyoverX-AnyLLM-Key,Authorization, thenx-api-key, and emit a warning + request flag when legacy header is used. - Add response middleware to attach
DeprecationandSunsetheaders for legacy-header requests; expandVaryand CORS allow-headers to include both gateway header names. - Add unit + integration test coverage for precedence, malformed headers, deprecation signaling,
Vary, and CORS allow-list behavior.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/gateway/core/config.py |
Defines canonical + legacy header constants and RFC-compliant deprecation/sunset constants. |
src/gateway/api/deps.py |
Implements precedence rules, legacy-header flagging, and warning logs in _extract_bearer_token. |
src/gateway/main.py |
Adds deprecation response middleware and updates Vary + CORS allow-headers. |
tests/unit/test_extract_bearer_token.py |
Unit tests covering header precedence, malformed inputs, and legacy flagging behavior. |
tests/integration/test_auth_header_precedence.py |
End-to-end tests for middleware-propagated Deprecation/Sunset, Vary, and CORS allow-list. |
tests/integration/test_provider_kwargs_override.py |
Updates integration tests to use canonical API_KEY_HEADER. |
tests/integration/test_client_args.py |
Updates integration tests to use canonical API_KEY_HEADER. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@peteski22 this looks great. Since the gateway with the platform is not yet live, no need to add all the deprecation code. Could you remove it? |
Adopt an RFC 6648-compliant header name (no `X-` prefix) for gateway Bearer authentication. The gateway has no live deployments yet, so no migration window or legacy-accept path is required — this is a pure rename of the authentication header. - core/config.py: flip constant; document RFC 6648 in the comment. - api/deps.py: update the `_extract_bearer_token` docstring and the three `verify_*` docstrings to reference the new header name. - main.py: replace the hard-coded "X-AnyLLM-Key" string in the CORS allow_headers list with the `API_KEY_HEADER` constant, mirroring how the name is referenced in `deps.py`. - tests/integration/test_client_args.py, tests/integration/test_provider_kwargs_override.py: replace hard-coded header literals with `API_KEY_HEADER` so these tests follow the rename without further edits.
Unit-test ``_extract_bearer_token`` directly so every precedence branch and every failure mode is exercised without spinning up FastAPI or a database. Covers: canonical AnyLLM-Key, Authorization, and x-api-key happy paths; the three precedence pairs among them; malformed (non-Bearer) values on the Bearer-format headers; and the missing-credentials 401.
e66706a to
9aa1760
Compare
|
Force-pushed the branch with the deprecation code removed — PR is now a straight rename from |
Summary
Rename the gateway's Bearer-authentication header from
X-AnyLLM-KeytoAnyLLM-Key, so the name follows RFC 6648 (noX-prefix). The gateway has no live deployments yet, so there is no backward-compatibility path — this is a simple rename.What changes
core/config.py:API_KEY_HEADERflips to"AnyLLM-Key", comment cites RFC 6648.api/deps.py:_extract_bearer_tokenand the threeverify_*docstrings reference the new header name.main.py: the CORSallow_headerslist uses theAPI_KEY_HEADERconstant instead of a hard-coded string, matching how the constant is referenced elsewhere.tests/integration/test_client_args.py,tests/integration/test_provider_kwargs_override.py: hard-coded header literals replaced withAPI_KEY_HEADERso the tests track the rename.tests/unit/test_extract_bearer_token.py(new): unit tests of_extract_bearer_tokencovering every precedence pair amongAnyLLM-Key/Authorization/x-api-key, malformed (non-Bearer) input on each Bearer-format header, and the missing-credentials 401.History
Earlier revisions of this PR shipped a full RFC 6648 / 9745 / 8594 deprecation design (legacy header kept,
Deprecation/Sunsetresponse headers,DeprecationHeadersMiddleware).@tbillepointed out the gateway is not yet live, so there is no old name to deprecate; the branch was force-pushed to drop the deprecation machinery and keep only the rename + tests.Commits
feat(gateway): rename API_KEY_HEADER from X-AnyLLM-Key to AnyLLM-Keytest(gateway): cover bearer-token extraction precedence and error pathsTest plan
make test— 317 passed, 9 skipped, no regressionsmake lint— cleanmake typecheck— clean