litellm/tests/unit/router_strategy
chaznm 53379abf0a
fix(proxy): bill a refused /v1/messages stream on one failure row with the upstream's tokens (#54238)
* fix(proxy): bill a refused /v1/messages stream on its failure row only

* fix(proxy): count a Presidio block as a guardrail refusal so a refused stream bills one failure row

* fix(proxy): refuse every /v1/messages stream by route so the Rust-served stream also bills one failure row

* fix(proxy): bill refused gateway /v1/messages streams and reads cut mid-event

A refused stream on /claude_code_gateway/v1/messages kept its success row, because the route check missed the gateway prefix. The failure row now also joins the bytes read before parsing them, as the success path does, so an event or a character split across reads still bills

* fix(proxy): count billed failures toward per-model and router budgets

* fix(proxy): stop and fully bill a refused native /v1/messages stream

A post-call hook that refuses a native /v1/messages stream now stops the
provider stream and bills every chunk the provider sent on the one failure
row, instead of only the bytes the hooks had read.

The read tap forwards the stream's attributes, so iterator hooks can still
read the response's hidden params. The agent session budget now counts a
billed failure, as the router budgets do.

* fix(proxy): bill a refused /v1/messages stream once and keep Presidio prompt blocks out of failure logs

A refusal that arrives after the stream's success log already ran no longer bills a second failure row.
A Presidio block now logs a failure only when it refused a stream, so a prompt block sends nothing to the
failure callbacks and a non-stream block keeps its billed tokens. A refused stream the Rust bridge serves is
closed at the block, so the provider stops generating past the bytes the guardrail read

* fix(proxy): keep one spend row when a /v1/messages stream is refused after its success log ran

* fix(proxy): keep the $0 failure row for a stream refused after its success log ran

Skipping the failure row and event for every claimed stream also dropped the refusal on streamGenerateContent and pass-through streams, which log it at base. A refusal after the success log now keeps the billed success row and the usual $0 failure row, so failure callbacks still see it. The test covers /v1/messages and streamGenerateContent on python and bridged streams

* fix(proxy): count a cut stream's partial once in budgets and drop the unused provider-stop path

* test(proxy): cover the key per-model and session budgets counting a retried attempt once

* fix(proxy): subtract only the retried attempts whose failure the budgets counted

* fix(proxy): ignore a request param that claims a success was already counted in budgets

* fix(proxy): mask a refused stream's failure log with logging-only guardrails

* fix(proxy): log a Presidio block after a stream's success log as a refusal

* fix(logging): keep a refused stream's prompt from logging-only guardrails when message logging is off

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-25 10:14:41 +00: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 feat(router): infer custom classifier tiers from model mappings (#48987) 2026-10-29 11:30:23 -07: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(router): count the whole router_usage family on the native store (#50862) 2026-11-13 03:22:28 +00: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(proxy): bill a refused /v1/messages stream on one failure row with the upstream's tokens (#54238) 2026-11-25 10:14:41 +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(proxy): reserve least-busy picks on Vertex pass-through calls (#53588) 2026-11-23 04:21:20 +00: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 feat(tts)!: stream audio from the provider as it arrives on /v1/audio/speech (#46222) 2026-11-17 15:03:12 +00: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(router)!: name the request size when usage-based routing refuses an over-tpm request (#51838) 2026-11-14 16:16:21 -05: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 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_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