litellm/tests/unit/interactions
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
..
__init__.py test: move tests/test_litellm root and small trees into tests/unit (#43186) 2026-09-25 11:30:43 -07:00
conftest.py test(interactions): read the spec from a vendored snapshot and canary the live one daily (#48002) 2026-10-23 17:20:40 +00:00
interactions.openapi.json feat(interactions): forward continuation_token and type requires_continuation so callers can resume a long decode (#50151) 2026-11-05 15:38:44 -08:00
test_agents_http_handler.py fix(gemini)!: accept Google's current Managed Agents fields on create and interactions (#48750) 2026-10-28 12:37:59 -07:00
test_agents_main_and_utils.py fix(gemini)!: accept Google's current Managed Agents fields on create and interactions (#48750) 2026-10-28 12:37:59 -07:00
test_background_cost_polling.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_gemini_interactions_transformation.py fix(responses): preserve incomplete status in synthetic streams (#52489) 2026-11-19 22:24:50 -08:00
test_interactions_streaming_iterator.py fix(interactions): retain async stream success logging task so it survives GC and shutdown drain (#52300) 2026-11-17 09:43:45 -08:00
test_litellm_responses_bridge.py refactor(typing): clear about 1,100 basedpyright Any errors across 303 files (#49986) 2026-11-06 13:31:15 -08:00
test_main.py fix(interactions): bind Deep Research agents and record their costs (#51517) 2026-11-13 00:20:53 -08:00
test_openapi_compliance.py feat(interactions): forward continuation_token and type requires_continuation so callers can resume a long decode (#50151) 2026-11-05 15:38:44 -08:00