feat(gateway): add platform mode for user-token authentication - #1015
Merged
Conversation
tbille
temporarily deployed
to
integration-tests
April 10, 2026 13:33 — with
GitHub Actions
Inactive
Codecov Report❌ Patch coverage is
... and 39 files with indirect coverage changes 🚀 New features to boost your workflow:
|
tbille
temporarily deployed
to
integration-tests
April 10, 2026 14:10 — with
GitHub Actions
Inactive
tbille
force-pushed
the
feat/gateway-platform-mode
branch
from
April 14, 2026 18:42
ef97b9d to
7429e05
Compare
tbille
temporarily deployed
to
integration-tests
April 14, 2026 18:42 — with
GitHub Actions
Inactive
Add platform mode to GatewayProvider that sends user auth via Authorization: Bearer <token> instead of X-AnyLLM-Key. Platform mode activates when platform_mode=True is passed explicitly, or when the GATEWAY_PLATFORM_TOKEN env var is set without an explicit api_key. Platform-mode error handling maps HTTP status codes from the gateway (401/402/403/404/429/502/504) to typed any-llm exceptions, preserves Retry-After headers on RateLimitError, and surfaces X-Correlation-ID in error messages for tracing. New exception types: InsufficientFundsError (402), UpstreamProviderError (502), GatewayTimeoutError (504). RateLimitError gains an optional retry_after attribute.
…patterns Cover all async method overrides (_acompletion, _aresponses, _aembedding, _alist_models) for both platform-mode error wrapping and success paths, plus non-platform passthrough. Add convert_exception tests for InsufficientFundsError, UpstreamProviderError, and GatewayTimeoutError patterns.
tbille
force-pushed
the
feat/gateway-platform-mode
branch
from
April 16, 2026 13:27
7429e05 to
734f6bc
Compare
tbille
temporarily deployed
to
integration-tests
April 16, 2026 13:27 — with
GitHub Actions
Inactive
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.
Description
Add platform mode to
GatewayProviderthat allows users to authenticate with the gateway using a simple user token and URL, without needing a gateway API key.Platform mode sends user auth as
Authorization: Bearer <platform_user_token>(standard OpenAI client behavior) instead of theX-AnyLLM-Keycustom header. It keeps using OpenAI-style/v1/chat/completionspayloads and supports bothprovider:modeland bare model formats.How platform mode activates
platform_mode=Truewithapi_keyparamplatform_mode=Truewithoutapi_keyGATEWAY_PLATFORM_TOKENenv varGATEWAY_PLATFORM_TOKENenv var set, noapi_keypassedapi_keypassed (noplatform_mode=True)Error handling in platform mode
Maps gateway HTTP responses to typed any-llm exceptions:
AuthenticationErrorInsufficientFundsError(new)ModelNotFoundErrorRateLimitError(withretry_afterattribute)UpstreamProviderError(new)GatewayTimeoutError(new)X-Correlation-IDfrom gateway responses is surfaced in error messages for tracing.Files changed
src/any_llm/exceptions.py- New exception types +retry_afteronRateLimitErrorsrc/any_llm/providers/gateway/gateway.py- Platform mode init, error handling, method overridessrc/any_llm/utils/exception_handler.py- Recognize new exception patterns inconvert_exceptiontests/unit/providers/test_gateway_provider.py- 20 new tests for platform mode (31 total)tests/unit/providers/test_cohere_exceptions.py- Updated to expectGatewayTimeoutErrorPR Type
Relevant issues
Checklist
AI Usage Information
AI Model used: Claude Opus 4 (claude-opus-4-6)
AI Developer Tool used: OpenCode
Any other info you'd like to share: Full implementation including exception design, platform mode detection logic, error mapping, and comprehensive test coverage.
I am an AI Agent filling out this form (check box if true)