litellm/tests/unit/responses
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
..
litellm_completion_transformation refactor(types): type the dict-style accessors on the response models and their read sites (#54620) 2026-11-26 04:15:22 +00:00
mcp 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
__init__.py
test_additional_tools.py feat(proxy): mixed Codex model picker and LiteLLM routing on native codex routes (#49408) 2026-11-06 11:14:47 -08:00
test_custom_tool_call.py
test_input_items_query.py fix(proxy): forward limit, order, after, before and include on GET /v1/responses/{id}/input_items (#51259) 2026-11-20 07:54:26 -08:00
test_instructions_length.py fix(responses): send bridged system prompts too long for instructions as input (#52964) 2026-11-20 11:56:47 -08:00
test_metadata_codex_callback.py
test_no_duplicate_spend_logs.py
test_null_test_fix.py
test_responses_api_bridge_flag.py fix(responses): reject an unresolvable previous_response_id on the chat completions bridge (#53766) 2026-11-25 13:32:42 +00:00
test_responses_api_lifecycle.py fix(responses): log the resolved provider on Responses API calls (#52622) 2026-11-18 22:34:16 +00:00
test_responses_api_request_body.py refactor(types): type the kwargs reads in the responses, images, realtime, files, rerank, batches and fine-tuning entrypoints (#54653) 2026-11-26 10:07:19 +00:00
test_responses_prompt_management.py refactor(types): type the kwargs reads in the responses, images, realtime, files, rerank, batches and fine-tuning entrypoints (#54653) 2026-11-26 10:07:19 +00:00
test_responses_router_cooldown.py fix(openai): relay provider error codes, types, and Responses params from OpenAI-compatible backends (#51809) 2026-11-24 02:23:00 +00:00
test_responses_streaming_iterator.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_responses_supported_endpoints_passthrough.py
test_responses_utils.py fix(responses): reject an unresolvable previous_response_id on the chat completions bridge (#53766) 2026-11-25 13:32:42 +00:00
test_responses_websocket_all_providers.py fix(responses): reject an unresolvable previous_response_id on the chat completions bridge (#53766) 2026-11-25 13:32:42 +00:00
test_rust_bridge_websocket.py refactor(rust-bridge): require the native extension (#48852) 2026-10-28 13:16:56 -07:00
test_sse_output_recovery.py
test_streaming_iterator.py fix(responses): always stream tool argument fields as strings for every Responses provider (#53953) 2026-11-24 03:45:17 +00:00
test_streaming_iterator_error_events.py fix(openai): relay provider error codes, types, and Responses params from OpenAI-compatible backends (#51809) 2026-11-24 02:23:00 +00:00
test_text_format_conversion.py refactor: expose core private helpers under public names (#44871) 2026-10-07 00:05:27 +00:00