litellm/litellm/router_rust/invoke
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
..
__init__.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
cache_controls.py feat(router)!: let a deployment choose which cache controls a request may override (#54219) 2026-11-24 14:33:59 -08:00
endpoints.py fix(bedrock): send pass-through calls the model id chat completions sends (#53836) 2026-11-25 18:42:28 -08:00
prompt_management.py feat(router)!: let a deployment choose which cache controls a request may override (#54219) 2026-11-24 14:33:59 -08:00
README.md feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
shaping.py fix(router): preserve destination bearer credentials on Anthropic fallbacks (#54271) 2026-11-24 17:12:02 -08:00
slots.py feat(tts)!: stream audio from the provider as it arrives on /v1/audio/speech (#46222) 2026-11-17 15:03:12 +00:00
streaming.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
walk.py fix(proxy): the failure row after a failed fallback stands for the attempt the client saw (#53313) 2026-11-21 19:52:06 +00:00
websocket.py fix(router): count a Responses WebSocket turn's input against deployment ITPM (#53594) 2026-11-24 04:26:36 -08:00

invoke

The host side of Host::invoke: running one attempt against the one deployment router-core picked. Nothing here selects, retries, falls back or records cooldowns.

  • shaping: the kwargs an attempt sends to its deployment
  • endpoints: what each public router method does before, around and after the routed call
  • streaming: stream wrappers, so a stream that fails before its first token fails the attempt
  • slots: a deployment's max_parallel_requests
  • walk: the retry and fallback metadata stamped on each attempt
  • prompt_management: prompt-management groups
  • websocket: admission for each turn of a Responses websocket

A Rust host replaces this with native endpoint calls.