litellm/tests/unit/proxy/hooks
Mateo Wang 3821e09071
feat(batches): share a model_info batch_enqueued_token_limit pool across teams and projects (#55618)
* feat(batches): share a model_info batch_enqueued_token_limit pool across teams and projects

A model_list entry's model_info.batch_enqueued_token_limit is now one enqueued-token pool per model group, shared by every caller. Teams can hold per-model allocations in model_batch_enqueued_token_limit like projects, and team and project writes answer 400 when the allocations for a model would add up past its pool

The pool never lifts the per-minute counters. A team allocation that covers every model in the batch lifts them like a team-wide limit. Pool and team allocation scopes are saved in a new trailing model_scopes field on the reservation record, so older pods still refund the rest

* fix(proxy): draw wildcard-routed models from the wildcard route's batch enqueued-token pool

* fix(proxy): charge a batch row's pool to the model serving it, not the deployment model an upload rewrote it to

* fix(proxy): keep batch pools on the serving group and lift limits only for pooled team allocations

A named model_list entry no longer draws from a wildcard route's pool, a team
allocation lifts the per-minute and daily batch limits only when every model
serving the batch has a pool, coverage reads the model serving each row so
model-routed uploads count, the allocation query gets a bounded span name, and
the file-reading opt-outs log one warning when they skip a configured pool.

* fix(proxy): lift team batch limits only when the serving entry has a pool and keep project coverage on row models

* fix(proxy): return batch allocation errors as plain text

* fix(proxy): expire each batch pool reservation on its own and keep team allocations from lifting limits

A model pool or team allocation reservation now lives in a per-scope sorted set with its own
expiry, so a batch nobody retrieves through the proxy frees its tokens after the TTL even while
other teams keep sending batches on that model. Key, team and project counters keep the shared
counter older pods charge and refund.

A team's per-model allocation now only caps the team's batches. Only a key or team-wide
batch_enqueued_token_limit, which was admin-only before, lifts the per-minute and daily limits,
so values a team admin saved before the upgrade never lift them.

* perf(proxy): keep a running total beside each batch pool's reservations

A pool or team allocation reserve summed every open reservation in Redis, so
a pool with 10,000 open batches blocked Redis for about 11 ms on each batch
create. The reserve now reads a running total, subtracts only the
reservations that expired since, and rebuilds the total from the
reservations when Redis evicts it. Both keys share one hash slot
2026-12-02 16:03:49 -08:00
..
litellm_skills refactor(typing): clear 42 basedpyright Any errors across 8 files (#55497) 2026-12-01 23:18:08 +00:00
model_capacity_golden feat(model_capacity): replace the python dynamic rate limiter v3 with a rust callback (#51540) 2026-11-17 22:20:54 +00:00
__init__.py
native_capacity_handler.py fix(realtime): enforce TPM limits during realtime sessions (#53689) 2026-11-24 05:15:04 -08:00
parallel_request_limiter_v3_golden.json feat(batches): share a model_info batch_enqueued_token_limit pool across teams and projects (#55618) 2026-12-02 16:03:49 -08:00
test_async_post_call_streaming_iterator_hook.py fix(guardrails): run the end-of-stream post_call scan when the client disconnects mid-stream (#43839) 2026-10-05 01:44:43 -07:00
test_autorouter_baseline_cache.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_banned_keyword_list.py chore: move workspace packages under litellm (#51000) 2026-11-12 04:19:57 +00:00
test_batch_enqueued_tokens.py feat(batches): share a model_info batch_enqueued_token_limit pool across teams and projects (#55618) 2026-12-02 16:03:49 -08:00
test_batch_enqueued_tokens_rust.py feat(batches): share a model_info batch_enqueued_token_limit pool across teams and projects (#55618) 2026-12-02 16:03:49 -08:00
test_batch_file_validation.py feat(batches): share a model_info batch_enqueued_token_limit pool across teams and projects (#55618) 2026-12-02 16:03:49 -08:00
test_batch_rate_limiter.py feat(batches): share a model_info batch_enqueued_token_limit pool across teams and projects (#55618) 2026-12-02 16:03:49 -08:00
test_dynamic_rate_limiter.py refactor(rust_bridge): route every Rust-to-Python call through host modules (#50822) 2026-11-11 01:57:54 +00:00
test_dynamic_rate_limiter_v3_on_native_limiter_rust.py feat(model_capacity): replace the python dynamic rate limiter v3 with a rust callback (#51540) 2026-11-17 22:20:54 +00:00
test_dynamic_rate_limiter_v3_rust.py refactor(rust): rename the compiled module _native to _rust (#55198) 2026-12-01 07:08:38 -08:00
test_image_generation_guardrails.py test(proxy): move auth, hooks, policy_engine and client tests into tests/unit/proxy (#43998) 2026-10-01 10:11:45 -07:00
test_key_management_event_hooks.py feat(proxy): add /team/key/bulk_generate to create one key per team member (#55272) 2026-12-01 12:31:01 -08:00
test_max_budget_per_session_limiter.py refactor(rust): rename participle functions in llms, bridge, redis and router crates (#55222) 2026-12-01 15:46:37 +00:00
test_max_iterations_limiter.py refactor(typing): clear about 1,100 basedpyright Any errors across 303 files (#49986) 2026-11-06 13:31:15 -08:00
test_message_thread_ownership.py refactor(auth_cache): type auth cache keys and keep the cache always native (#51130) 2026-11-21 17:20:30 +09:00
test_model_budget_shared_windows.py feat(proxy)!: model family and access group entries in model_max_budget (#47722) 2026-10-28 15:40:57 -07:00
test_model_capacity_native.golden.json feat(model_capacity): replace the python dynamic rate limiter v3 with a rust callback (#51540) 2026-11-17 22:20:54 +00:00
test_model_capacity_native.py refactor(rust): rename the compiled module _native to _rust (#55198) 2026-12-01 07:08:38 -08:00
test_model_max_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_parallel_request_limiter.py fix(proxy): refuse Responses and realtime socket turns over TPM and count their usage on the legacy limiter (#55315) 2026-12-01 19:07:27 +00:00
test_parallel_request_limiter_v3.py fix(proxy): keep token rate-limit reservations for embeddings the provider reports as 0 tokens (#54088) 2026-11-24 08:11:49 -08:00
test_parallel_request_limiter_v3_native.py feat(batches): share a model_info batch_enqueued_token_limit pool across teams and projects (#55618) 2026-12-02 16:03:49 -08:00
test_parallel_request_limiter_v3_rust.py fix(proxy): keep a request's slot, TPM and budget holds while it runs MCP tools (#54469) 2026-11-26 08:11:44 +00:00
test_post_call_failure_hook_integration.py test(proxy): move auth, hooks, policy_engine and client tests into tests/unit/proxy (#43998) 2026-10-01 10:11:45 -07:00
test_post_call_response_headers_hook.py test(proxy): move auth, hooks, policy_engine and client tests into tests/unit/proxy (#43998) 2026-10-01 10:11:45 -07:00
test_post_call_streaming_hook_integration.py test(proxy): move auth, hooks, policy_engine and client tests into tests/unit/proxy (#43998) 2026-10-01 10:11:45 -07:00
test_post_call_success_hook_integration.py test(proxy): move auth, hooks, policy_engine and client tests into tests/unit/proxy (#43998) 2026-10-01 10:11:45 -07:00
test_priority_class_share.py feat(dynamic_rate_limiter): customer organizations and keys borrow idle model capacity and split class shares (#51705) 2026-11-15 12:05:58 -08:00
test_prompt_cache_observer.py fix(proxy): keep a retried /v1/messages stream's spend log by logging the superseded attempt as a failure (#45136) 2026-10-16 21:19:58 +00:00
test_prompt_injection_detection.py refactor(rust_bridge): route every Rust-to-Python call through host modules (#50822) 2026-11-11 01:57:54 +00:00
test_proxy_hooks_init.py chore: move workspace packages under litellm (#51000) 2026-11-12 04:19:57 +00:00
test_proxy_rate_limit_provider_field.py feat(model_capacity): replace the python dynamic rate limiter v3 with a rust callback (#51540) 2026-11-17 22:20:54 +00:00
test_proxy_rate_limit_provider_field_capacity_rust.py feat(model_capacity): replace the python dynamic rate limiter v3 with a rust callback (#51540) 2026-11-17 22:20:54 +00:00
test_proxy_rate_limit_provider_field_rust.py feat(callbacks-parallel-request-limiter): port parallel request limiter v3 to a rust callback (#51537) 2026-11-16 22:56:38 -08:00
test_proxy_track_cost_callback.py feat(proxy): add per AI tool limits for teams and members (#55520) 2026-12-01 22:08:26 +00:00
test_proxy_track_cost_callback_ledger.py feat(budgets): run the ledger's post-call spend counter step in rust (#52166) 2026-11-20 16:31:03 -08:00
test_proxy_track_cost_callback_rust.py feat(proxy): add per AI tool limits for teams and members (#55520) 2026-12-01 22:08:26 +00:00
test_rate_limiter_toctou_capacity_rust.py feat(model_capacity): replace the python dynamic rate limiter v3 with a rust callback (#51540) 2026-11-17 22:20:54 +00:00
test_rate_limiter_toctou_rust.py feat(model_capacity): replace the python dynamic rate limiter v3 with a rust callback (#51540) 2026-11-17 22:20:54 +00:00
test_search_free_tier.py fix(proxy): scope the search free-tier counter to the request's provider (#47646) 2026-10-20 22:01:53 +00:00
test_send_invite_email.py test(proxy): move auth, hooks, policy_engine and client tests into tests/unit/proxy (#43998) 2026-10-01 10:11:45 -07:00
test_sensitive_data_routing.py refactor(rust): rename participle functions in llms, bridge, redis and router crates (#55222) 2026-12-01 15:46:37 +00:00
test_tpm_concurrent.py fix(proxy): leave cache-read tokens out of the priority limiter's token count (#52209) 2026-11-17 11:32:25 -08:00
test_tpm_concurrent_rust.py fix(proxy): reserve TPM for the system prompt on Messages and instructions on Responses (#54318) 2026-11-24 19:55:39 -08:00
test_unit_test_max_model_budget_limiter.py fix(router): inspect image content without translating routed requests (#49371) 2026-10-31 10:44:24 -07:00
test_user_management_event_hooks.py test(proxy): move auth, hooks, policy_engine and client tests into tests/unit/proxy (#43998) 2026-10-01 10:11:45 -07:00