litellm/tests/unit/proxy/hooks
martenj4 9b5fe500e1
fix(proxy): bill an OpenAI pass-through background response to the key that created it (#53586)
* fix(proxy): bill an OpenAI pass-through background response to the key that created it

A background create through the OpenAI pass-through comes back queued with no
usage, so it logged $0, and the first key to read the finished response paid
for it. A response nobody read through the proxy was never billed.

A queued background create now records its creator in a new
LiteLLM_BackgroundResponseCreator table and starts a poll. The poll, or a read
that settles the response first, bills the creator once through the existing
settlement claim, and the reader's own log stays unbilled. A restarted proxy
resumes polling unfinished responses with the pass-through's configured key.

* fix(proxy): keep background response creator bills recoverable, leased, and complete

A failed creator bill now releases its settlement claim and keeps the creator row, so the poll or a later read retries it. Only the settler whose bill went through forgets the row

A read whose claim the database could not record leaves the reader unbilled and leaves the creator bill to the poll or a later read

A streamed background create that ends without a terminal event records its creator and starts a poll, like a non-streamed create

The creator bill keeps the create's no-log flag and disabled callbacks, and it ends at the response's completed_at

Each creator row carries a poll lease, so one worker polls each response. A periodic sweep resumes unleased polls and deletes rows older than 30 days

A DELETE of a tracked response settles it before the proxy forwards the DELETE

* fix(proxy): defer the creator bill on a failed lookup, send it to the creator key's logging, settle DELETE after admission

A read that cannot look up a background response's creator now bills nobody, so the poll or a later read bills
the creator instead of the reader. A create whose key or team sets its own logging callbacks sends its creator
bill to the callbacks that key resolves to at bill time, and records spend only when the key cannot be loaded.
A pass-through DELETE settles the creator bill only after auth and the pre-call hooks admit it.

* fix(proxy): free no legacy rate-limit slot on a background bill, keep Azure on main's billing, cap background fetches and key reloads

* fix(proxy): keep the background bill from holding a legacy limiter slot, retry an expired poll token, skip the creator lookup on Azure reads

A usage-only bill that lands in a minute with no limiter counter records no request, so the creator's next request is not refused by max_parallel_requests

A poll GET that gets 401 reads once more with the pass-through's current credential, so an expired workload identity token does not stop the poll

Azure OpenAI reads and stream reads no longer look up the creator table, so they keep main's billing even when the lookup fails

* fix(proxy): bill the creator on configured OpenAI route reads and cap polls per worker

A read, stream read or DELETE through any pass-through route that targets api.openai.com now looks up the creator, so a configured route no longer bills the reader and claims the response before the creator's poll. Creates are tracked only on the built-in /openai_passthrough route, and a stream no longer assumes OpenAI when the route names no provider

One worker polls at most 1000 background responses at once. Past that a create starts no poll and the sweep picks its row up once the lease lapses, and the sweep leases only as many rows as it has room for

The usage-only flag moves from the shared rebuild_logging_obj onto the OpenAI creator bill, so the interactions poller keeps main's legacy limiter behavior

* fix(proxy): settle a claim the database records late and log the creator bill apart from its create

* fix(proxy): log the creator bill over the response's run so it keeps its latency

* fix(proxy): give back a settlement claim whose caller is cancelled before the insert answers

* test(proxy): run the never-answering provider test over a unix socket

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-23 20:14:58 +00:00
..
litellm_skills 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
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 feat(model_capacity): replace the python dynamic rate limiter v3 with a rust callback (#51540) 2026-11-17 22:20:54 +00:00
parallel_request_limiter_v3_golden.json refactor(redis): move per-request miss, settlement and shutdown-drain tracking from Python into Rust (#51384) 2026-11-20 17:57:37 +09:00
test_async_post_call_streaming_iterator_hook.py
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(callbacks-parallel-request-limiter): port parallel request limiter v3 to a rust callback (#51537) 2026-11-16 22:56:38 -08:00
test_batch_enqueued_tokens_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_batch_file_validation.py fix(proxy): count Vertex and Bedrock batch input tokens (#53257) 2026-11-22 18:02:42 -08:00
test_batch_rate_limiter.py fix(proxy): count Vertex and Bedrock batch input tokens (#53257) 2026-11-22 18:02:42 -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 feat(redis): serve the dynamic rate limiter's active teams from a native store (#52995) 2026-11-20 10:58:19 +09:00
test_image_generation_guardrails.py
test_key_management_event_hooks.py feat(control_plane): dataplane registry, credential strategies and client (#49655) 2026-11-16 17:36:23 +00:00
test_max_budget_per_session_limiter.py fix(redis): share one native circuit breaker between RedisCache and the Rust stores (#50473) 2026-11-07 17:50:06 +09: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 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_max_budget_limiter.py feat(realtime)!: serve GPT-Live over WebRTC with sideband attach, and bill WebRTC calls from a proxy sideband (#53282) 2026-11-21 22:49:26 -08:00
test_parallel_request_limiter.py fix(proxy): bill an OpenAI pass-through background response to the key that created it (#53586) 2026-11-23 20:14:58 +00:00
test_parallel_request_limiter_v3.py feat(anthropic): price Claude subscription OAuth allowance usage at $0, overage at API rates (#52901) 2026-11-19 15:08:39 -08:00
test_parallel_request_limiter_v3_native.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_parallel_request_limiter_v3_rust.py fix(responses): stop the background stream when a polling response is cancelled (#49384) 2026-11-18 14:33:39 +00:00
test_post_call_failure_hook_integration.py
test_post_call_response_headers_hook.py
test_post_call_streaming_hook_integration.py
test_post_call_success_hook_integration.py
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
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 refactor(auth_cache): type auth cache keys and keep the cache always native (#51130) 2026-11-21 17:20:30 +09: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 app groups with shared budgets and usage (#53232) 2026-11-21 12:50:58 -08: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_sensitive_data_routing.py fix(redis): share one native circuit breaker between RedisCache and the Rust stores (#50473) 2026-11-07 17:50:06 +09: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(google_genai): honor snake_case generation_config on generateContent (#51139) 2026-11-18 03:47:08 +00: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