litellm/tests/documentation_tests
Mateo Wang f7044efd78
fix(responses): bill a client-cancelled native Responses stream with the usage the provider reports (#54752)
* fix(responses): bill a client-cancelled native Responses stream with the usage the provider reports

When a client leaves a native /v1/responses stream, keep reading the provider's stream to its terminal event so the spend log carries the provider's own usage (reasoning tokens and the cached split included), including when the client left before any output. cancel_on_disconnect keeps cancelling the upstream call

Resolves LIT-10916

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* refactor(responses): name the check for a stream that can be read on after its consumer left

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* test(proxy): assert the budget reservation is not refunded while a cancelled Responses stream is read on

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(responses): keep a provider event that arrived just as the consumer was cancelled

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(responses): let the success event of an already finished stream own the disconnect cleanup

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(responses): leave the slot to the failure a cut stream logged while it was read on

A provider failure during the disconnect drain is logged by the stream, and the legacy
limiter's failure callback already released the parallel-request slot, so the cleanup's
explicit release freed a second one. The cleanup now skips that release and settles the
reservation, which no failure hook does for a request whose client left

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* Revert "fix(responses): leave the slot to the failure a cut stream logged while it was read on"

This reverts commit d17ea4b325.

* fix(responses): bill a cut stream whose provider fails while it is read on as the cut stream it is

A provider failure during the disconnect drain ran the stream's failure handlers, whose
legacy limiter callback released the parallel-request slot the disconnect cleanup releases
too, and marked the relayed text as billed by a failure log no spend row follows. The
failure handlers now stay out of the drain, so the cleanup bills what was relayed and
releases the slot once, as it does for a stream that is not read on

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(responses): bill a response the provider fails after its client left with the usage that event reports

With failure handlers kept out of the disconnect drain, a response.failed event that
arrived while the stream was read on was billed nowhere: no failure log ran and the
terminal event blocked the cut stream's partial bill. That bill now carries the usage
the failed event reported, or the local estimate when it reported none

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(responses): bill a drained response whose success logging raised as the cut stream it is

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-11-27 01:41:06 +00:00
..
test_api_docs.py test: drop the cwd-relative sys.path.insert calls from the test suite (#37802) 2026-08-22 09:25:58 -07:00
test_circular_imports.py
test_env_keys.py fix(responses): bill a client-cancelled native Responses stream with the usage the provider reports (#54752) 2026-11-27 01:41:06 +00:00
test_exception_types.py test: drop the cwd-relative sys.path.insert calls from the test suite (#37802) 2026-08-22 09:25:58 -07:00
test_general_setting_keys.py [Fix] Scope documentation workflow to match CircleCI and add missing router settings 2026-03-28 11:23:53 -07:00
test_optional_params.py Litellm dev 12 28 2024 p1 (#7463) 2024-12-28 20:26:00 -08:00
test_readme_providers.py feat(vector_stores): add Valkey as a managed vector store provider (#37002) 2026-08-18 21:45:22 +00:00
test_requests_lib_usage.py LITELLM: Remove requests library usage (#7235) 2024-12-17 12:50:04 -08:00
test_router_settings.py test(docs): read only the first column of the router_settings reference table 2026-09-18 19:11:39 +00:00
test_standard_logging_payload.py test: drop the cwd-relative sys.path.insert calls from the test suite (#37802) 2026-08-22 09:25:58 -07:00