Skip to content

feat(gateway): accept legacy X-AnyLLM-Key header for back-compat#50

Merged
tbille merged 1 commit intomainfrom
feat/legacy-x-anyllm-key-compat
Apr 17, 2026
Merged

feat(gateway): accept legacy X-AnyLLM-Key header for back-compat#50
tbille merged 1 commit intomainfrom
feat/legacy-x-anyllm-key-compat

Conversation

@tbille
Copy link
Copy Markdown
Contributor

@tbille tbille commented Apr 17, 2026

Summary

  • PR feat(gateway): rename auth header to AnyLLM-Key (RFC 6648) #45 renamed the auth header from X-AnyLLM-Key to AnyLLM-Key (RFC 6648) without a migration path, breaking any client still sending the old name.
  • Restore back-compat by also accepting X-AnyLLM-Key as an alias of AnyLLM-Key. Precedence is AnyLLM-Key > X-AnyLLM-Key > Authorization, so the canonical header wins when both are present.
  • Allow the legacy header through CORS preflight so browser clients aren't blocked.

Changes

  • src/gateway/core/config.py: add LEGACY_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 the Authorization fallback.
  • src/gateway/main.py: add LEGACY_API_KEY_HEADER to the CORS allow_headers list.
  • 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

  • Kept intentionally minimal per request. The Anthropic x-api-key shim removed in e26c7c3 is not reintroduced here.
  • No deprecation logging — silent acceptance, as requested.
  • No API surface change; OpenAPI spec is unaffected.

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.

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.
@tbille tbille temporarily deployed to integration-tests April 17, 2026 09:28 — with GitHub Actions Inactive
@tbille tbille merged commit 9f193b4 into main Apr 17, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant