litellm/tests/unit/router_utils
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
..
pre_call_checks fix(logging): log Anthropic base64 sources on /v1/messages and pass-through routes as a size placeholder (#54161) 2026-11-24 12:13:09 -08:00
__init__.py
test_access_windows.py refactor(router): route the router family through RoutingContext and close the outside surface (#49118) 2026-10-30 19:18:54 -07:00
test_add_retry_fallback_headers.py fix(responses): accept a string or tuple allowed_openai_params on Responses models instead of answering 500 (#51751) 2026-11-14 04:32:38 -05:00
test_client_initalization_utils.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_cooldown_cache.py feat(redis): serve the proxy's common Redis call with Rust stores (#50170) 2026-11-06 06:01:11 +00:00
test_cooldown_handlers.py refactor(typing): clear basedpyright Any errors across 35 files (#53599) 2026-11-24 00:39:02 +00:00
test_deployment_pricing.py refactor(router): route the router family through RoutingContext and close the outside surface (#49118) 2026-10-30 19:18:54 -07:00
test_dynamic_queue.py feat(router): add bounded congestion queue controller (#51883) 2026-11-17 17:15:24 -08:00
test_dynamic_queue_redis.py feat(router): coordinate congestion queues through Redis (#52367) 2026-11-17 19:29:39 -08:00
test_dynamic_queue_router.py fix(router): preserve destination bearer credentials on Anthropic fallbacks (#54271) 2026-11-24 17:12:02 -08:00
test_embedding_batch_size_check.py feat(embeddings): enforce per-request input batch limit (#44574) 2026-10-20 11:35:18 +00:00
test_endpoint_eligibility.py refactor(router): delete router code nothing calls (#52516) 2026-11-19 06:11:10 +09:00
test_fallback_event_handlers.py refactor(router): delete router code nothing calls (#52516) 2026-11-19 06:11:10 +09:00
test_fallback_event_v2_dispatch.py feat(custom-logger-v2): add types, dispatcher and route callback call sites (step 0) (#51214) 2026-11-13 22:08:05 +00:00
test_get_retry_from_policy.py refactor(router): route the router family through RoutingContext and close the outside surface (#49118) 2026-10-30 19:18:54 -07:00
test_handle_error.py refactor(router): delete router code nothing calls (#52516) 2026-11-19 06:11:10 +09:00
test_health_check_allowed_fails_integration.py feat(redis): serve the proxy's common Redis call with Rust stores (#50170) 2026-11-06 06:01:11 +00:00
test_health_state_cache.py feat(redis): serve the health checks' deployment states from a native store (#50357) 2026-11-13 03:22:28 +00:00
test_kubernetes_pod_discovery.py refactor(router): delete router code nothing calls (#52516) 2026-11-19 06:11:10 +09:00
test_pattern_match_deployments.py refactor(typing): clear 1146 basedpyright Any errors across 365 files (#52768) 2026-11-21 04:25:33 +00:00
test_prompt_caching_cache.py fix(logging): log Anthropic base64 sources on /v1/messages and pass-through routes as a size placeholder (#54161) 2026-11-24 12:13:09 -08:00
test_ptu_shares.py refactor(router): route the router family through RoutingContext and close the outside surface (#49118) 2026-10-30 19:18:54 -07:00
test_reasoning_effort_capability.py fix(openai): drop or refuse an o-series reasoning_effort level the model map turns off (#54066) 2026-11-24 06:42:03 -08:00
test_request_priority.py fix(openai): relay provider error codes, types, and Responses params from OpenAI-compatible backends (#51809) 2026-11-24 02:23:00 +00:00
test_router_health_check_routing.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_interactions_endpoints.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_utils_common_utils.py fix(responses): accept a string or tuple allowed_openai_params on Responses models instead of answering 500 (#51751) 2026-11-14 04:32:38 -05:00
test_routing_read_batch.py refactor(redis): delete the Python RedisBatch now that every request op is native (#51383) 2026-11-13 03:22:28 +00:00