litellm/tests/unit/test_router
joshua-berri 59fbef8f59
fix(router): preserve destination bearer credentials on Anthropic fallbacks (#54271)
* fix(router): send the fallback deployment's own key instead of an inherited Anthropic key

On a fallback from an Anthropic group, a recognizable Anthropic caller key (sk-ant-) no longer
replaces the credential a Bedrock or Bedrock Mantle bearer deployment, or an OpenAI deployment,
resolves on its own default endpoint. The Bedrock bearer comes from the deployment api_key, a
router default or the provider env bearer. The OpenAI key comes from the deployment, a router
default, OPENAI_API_KEY, litellm.api_key or litellm.openai_key.

The existing IAM behavior is unchanged for every caller key. Opaque or destination-shaped caller
keys, blank keys, fallback targets that set api_key, explicit Authorization headers, custom
endpoints (deployment, request, dict target, router defaults, provider env, litellm.api_base),
mixed-group members, Claude Platform, and OpenAI deployments with no key of their own all keep
today's behavior.

* fix(router): check the caller key owner before resolving fallback destination auth

leaves_caller_key_behind now classifies the destination by provider and checks the Anthropic
owner before it reads any endpoint env var or secret, so direct and non-Anthropic calls resolve
nothing new, as before. The OpenAI own-key check reuses openai_static_api_key, and a non-string
deployment api_key keeps the caller key.

Tests add an OpenAI fallback whose explicit Authorization header keeps the forwarded caller key,
and direct and OpenAI-to-OpenAI calls that keep an sk-ant caller key without an Anthropic origin.

* test(router): key the alias fallback case on the requested alias

* test(router): keep the caller key when a router default api_key is not a string

* fix(router): admit fallbacks using their effective caller credentials

---------

Co-authored-by: Joshua Valluru <326636767+joshua-berri@users.noreply.github.com>
2026-11-24 17:12:02 -08:00
..
core test(router): pin the usage minute in the request scoped rpm check test (#54300) 2026-11-25 00:27:16 +00:00
__init__.py test: add __init__.py to every tests/unit directory phase 16 touches 2026-09-20 11:52:38 +00:00
test_enforce_model_rate_limits.py refactor(router): count the whole router_usage family on the native store (#50862) 2026-11-13 03:22:28 +00:00
test_io_token_rate_limits.py fix(router): count a Responses WebSocket turn's input against deployment ITPM (#53594) 2026-11-24 04:26:36 -08:00
test_router.py fix(router): preserve provider PDF preflight compatibility (#54208) 2026-11-24 12:36:47 -08:00
test_router_callback_hook_sequence.py test: replace 61 live logging and otel tests with offline unit and integration coverage (#45362) 2026-10-08 15:55:57 -07:00
test_router_endpoints.py fix(proxy): resolve admin oidc api_key references on batch cancel, fine-tuning listing, OCR, /v1/messages and cache prediction (#53678) 2026-11-23 10:11:10 -08:00
test_router_entry_points.py feat(proxy): mixed Codex model picker and LiteLLM routing on native codex routes (#49408) 2026-11-06 11:14:47 -08:00
test_router_facade.py refactor(router): delete the python router core, the rust core is the only core (#50178) 2026-11-05 10:40:46 -08:00
test_router_fallbacks.py fix(router): preserve destination bearer credentials on Anthropic fallbacks (#54271) 2026-11-24 17:12:02 -08:00
test_router_fuzz_regressions_rust_only.py ci(unit): cut unit check time with cheaper per-test resets and fewer non-unit tests (#51864) 2026-11-14 15:41:30 -08:00
test_router_get_deployments.py refactor(router): delete the python router core, the rust core is the only core (#50178) 2026-11-05 10:40:46 -08:00
test_router_helper_utils.py fix(router): count a Responses WebSocket turn's input against deployment ITPM (#53594) 2026-11-24 04:26:36 -08:00
test_router_host.py ci(unit): cut unit check time with cheaper per-test resets and fewer non-unit tests (#51864) 2026-11-14 15:41:30 -08:00
test_router_max_parallel_requests.py feat(tts)!: stream audio from the provider as it arrives on /v1/audio/speech (#46222) 2026-11-17 15:03:12 +00:00
test_router_provider_endpoints.py feat(redis): serve the proxy's common Redis call with Rust stores (#50170) 2026-11-06 06:01:11 +00:00
test_router_retries.py refactor(router): delete the python router core, the rust core is the only core (#50178) 2026-11-05 10:40:46 -08:00
test_router_surface_check.py chore: move workspace packages under litellm (#51000) 2026-11-12 04:19:57 +00:00
test_router_timeout.py feat(messages): serve bedrock invoke messages on rust only (#51330) 2026-11-15 16:58:31 -08:00
test_router_vector_store_endpoints.py test: migrate SDK and proxy-booting legacy CircleCI tests to their tiers (#45758) 2026-10-11 00:17:21 -07:00