litellm/tests/unit/router_strategy
drewv19 ea90a9e26a
fix(router): count least-busy calls under the deployment's group and free rejected pass-through calls (#54171)
* fix(router): count least-busy calls under the deployment's own group

Least-busy counted an in-flight call under the name the caller asked for,
while picks read counts under the group they pick in. A call that reached a
deployment through a complexity router, a model_group_alias, or a wildcard
was invisible to the next pick for that deployment's group, so overlapping
calls stacked on one deployment.

Picks and counts now both key on the deployment's own model_name, falling
back to the requested group when no deployment name is known. Direct group
calls keep the exact counter key they had before.

* fix(router): count Vertex pass-through and stale-metadata calls under the deployment's own group

Vertex pass-through now stamps the resolved deployment's model_name after the caller's metadata merge, so its least-busy count uses the same key as the pick. The count's group now comes only from the metadata bucket stamped for the call's own deployment, so an outer router's leftover bucket cannot rename it. The in-flight test bounds its wait and cleans up its tasks

* fix(router): free least-busy counts when a pass-through call fails upstream

Pass-through upstream errors skip the logging failure handlers and reach
callbacks only through async_post_call_failure_hook, so a rejected Vertex
call kept its deployment counted busy until the 1 hour TTL ran out.
Least-busy now settles pass-through calls from that hook, and a second
settle for the same call is a no-op

Also covers a Vertex call by alias followed by one by the group name

* fix(proxy): drop a client-sent deployment_model_name from request metadata

* fix(router): free a pass-through least-busy count only for a call it saw start

A failure hook payload without a litellm_call_id, such as a 401 body or a pre-call rejection, no longer lowers a deployment's count

* fix(router): free a pass-through failure's least-busy count only for a pass-through start

The proxy failure hook gets the client's own body when a pass-through request
fails before the provider call, on a 401 or a pre-call 429. A body that named
a running chat call's litellm_call_id and deployment freed that call's count,
so the next pick went to the busy deployment. A chat caller picks its own id
with x-litellm-call-id, so the id is not a secret

Each started call now records whether it started as a pass-through call, and
the failure hook frees a count only for a pass-through start under the call id
the failure names. The logging success and failure paths still end any start

* fix(logging): keep the logged call type when a request param is named call_type

update_environment_variables spread optional_params after setting call_type,
so a provider that keeps unknown body keys (Gemini on Vertex) let a chat body's
"call_type": "pass_through_endpoint" replace the call type every callback sees.
Least-busy reads that value to flag a pass-through start, so a caller could mark
its own chat call as pass-through and free its count with a failing
pass-through request naming its x-litellm-call-id

call_type now goes after the optional_params spread. The pass-through routes
still set it through additional_params, which no caller fills from a request

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-12-03 17:29:06 -08:00
..
adaptive_router fix(anthropic): log the safeguards classifier and compaction summary calls in the parent request's session (#53405) 2026-11-24 01:31:04 -08:00
complexity_router fix(router): count pre-call context-window tokens with each deployment's tokenizer (#49764) 2026-11-25 03:04:19 +00:00
switchyard_router fix(anthropic): log the safeguards classifier and compaction summary calls in the parent request's session (#53405) 2026-11-24 01:31:04 -08:00
__init__.py test: add __init__.py to intermediate tests/unit packages 2026-09-20 12:55:27 +00:00
test_auto_router.py refactor(router): route the router family through RoutingContext and close the outside surface (#49118) 2026-10-30 19:18:54 -07:00
test_auto_router_model_naming.py fix(auto-router): reject classifier and default-model writes the router cannot load (#55573) 2026-12-01 16:37:25 -08:00
test_auto_router_tuning_baseline.py refactor(router): fence the router surface and document the router-core boundary (#48839) 2026-10-29 00:01:52 +00:00
test_base_routing_strategy.py refactor(rust): rename the compiled module _native to _rust (#55198) 2026-12-01 07:08:38 -08:00
test_baseline_request.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_budget_limiter.py fix(gemini): return an error instead of an empty 200 when a Gemini image request gets no image (#29125) 2026-11-25 20:55:23 +00:00
test_budget_limiter_hotpath.py test(router_strategy): keep foreign asyncio task noise out of the budget limiter caplog asserts (#43375) 2026-10-29 06:22:06 -07:00
test_complexity_router.py fix(llms): treat chat-latest and gpt-chat-latest as gpt-5 family models (#51151) 2026-11-24 04:02:51 -08:00
test_complexity_tier_predictor.py test: move tests/test_litellm core utils, routing, responses, caching and rust_bridge into tests/unit (#43199) 2026-09-25 17:10:13 -07:00
test_fuse_presets.py test: move tests/test_litellm core utils, routing, responses, caching and rust_bridge into tests/unit (#43199) 2026-09-25 17:10:13 -07:00
test_lar1_routing.py refactor(router): route the router family through RoutingContext and close the outside surface (#49118) 2026-10-30 19:18:54 -07:00
test_least_busy.py fix(router): count least-busy calls under the deployment's group and free rejected pass-through calls (#54171) 2026-12-03 17:29:06 -08:00
test_litellm_encoder.py fix(router): restore four base behaviors the RoutingContext refactor changed (#49395) 2026-10-31 22:58:34 +00:00
test_llm_v2.py feat(redis): serve the router's session pins from a native store (#50870) 2026-11-13 03:22:28 +00:00
test_lowest_cost.py refactor(rust_bridge): route every Rust-to-Python call through host modules (#50822) 2026-11-11 01:57:54 +00:00
test_lowest_latency.py fix(router): share successful latency-routing rpm and tpm counts (#55015) 2026-11-30 16:28:18 -08:00
test_lowest_tpm_rpm.py refactor(router): count the whole router_usage family on the native store (#50862) 2026-11-13 03:22:28 +00:00
test_lowest_tpm_rpm_v2.py fix(gemini): return an error instead of an empty 200 when a Gemini image request gets no image (#29125) 2026-11-25 20:55:23 +00:00
test_quality_router.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_routing_groups.py refactor(router): count the whole router_usage family on the native store (#50862) 2026-11-13 03:22:28 +00:00
test_router_routing_plugins.py feat(lens): add authenticated SDK Lens callback (#55012) 2026-11-28 18:22:56 -08:00
test_router_tag_regex_routing.py refactor(router): route the router family through RoutingContext and close the outside surface (#49118) 2026-10-30 19:18:54 -07:00
test_router_tag_routing.py fix(router): preserve routing tags after guardrail metadata enrichment (#50488) 2026-11-16 11:34:48 -08:00
test_savings_baseline.py fix(router): register a model_id Bedrock deployment after an ARN deployment for the same profile (#53461) 2026-11-22 22:27:56 +00:00
test_simple_shuffle.py test: move tests/test_litellm core utils, routing, responses, caching and rust_bridge into tests/unit (#43199) 2026-09-25 17:10:13 -07:00
test_stall_detector.py test: move tests/test_litellm core utils, routing, responses, caching and rust_bridge into tests/unit (#43199) 2026-09-25 17:10:13 -07:00