litellm/tests/unit/router_rust
martenj4 b099ac8118
fix(responses): bill the provider-reported input on a cut bridged stream (#53394)
* fix(responses): bill the provider-reported input on a cut bridged stream

A /v1/responses stream that runs through the chat bridge and is cut mid-answer now bills the input and cache counts the provider sent before the cut, and the spend row carries the 499 ClientDisconnected marker that /v1/responses reads from litellm_metadata

* fix(responses): bill cut Claude streams on relayed providers and build the partial off the event loop

* fix(responses): log the cost of the provider-reported usage on a cut stream

The cut partial took its usage from the rebuild over every kept chunk but kept
the response_cost the first build stamped from the estimate, and the logger
uses a stamped cost before it prices the usage. The partial now carries the
rebuild's cost along with its usage.

* fix(responses): drop the message_start placeholder on every stream Anthropic's parser reads

Anthropic's stream parser marks its message_start chunk, and the placeholder reset reads that mark
instead of a provider list plus a Claude model name. Bedrock application inference profile ARNs and
OpenCode Go's non-Claude models stream Anthropic's events too, and kept the 1-token output placeholder
on a cut stream before.

* fix(responses): bill a stream cut before its first relayed chunk

A client that drops a bridged /v1/responses stream after the provider's first usage event but before any text logged no spend row, since the partial response was built only from relayed chunks. The partial now falls back to the chunks the stream wrapper kept, so the row bills the provider's input and cache counts with no output text

* fix(responses): bill a cut background cancel or fallback once

A cancelled background response whose stream teardown had already billed the cut also logged a second, failed 499 row. The background task now skips its own failure log once the teardown billed. A client cut after a mid-stream fallback billed both deployments' tokens at the fallback's price with no cache split, and now sums both partials' tokens, cache counts and cost the way MCP rounds are billed

* fix(responses): charge the fixed cost margin once on a cut fallback stream

Each deployment's partial price already includes the fixed fee from cost_margin_config, so adding the first deployment's price to the fallback's charged that fee twice. The sum now takes off one fee, and the logged cost breakdown matches the billed total

* test: annotate the new disconnect test bindings as Final

* fix(router): bill a cut fallback's first deployment at its own price

A client cut after a mid-stream fallback now prices the first deployment's
partial when the fallback starts, before the fallback changes the shared
logging object's model, so its tokens keep their own price. An unpriced
deployment bills nothing and keeps the other side's cost breakdown. The
fixed fee is charged once at the final round's amount, and a fallback that
fails after the cut leaves no breakdown from the first deployment's partial.

* fix(router): bill the first deployment at its own price when a client cuts while the fallback connects

* fix(router): report a cut fallback's billed cost as its usage cost

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-23 06:20:25 +00:00
..
invoke fix(anthropic): skip a stream data line that is not a JSON object (#53393) 2026-11-22 22:54:02 +00:00
__init__.py
test_atomic_upsert.py fix(management): keep classifier deployments serving during reloads (#51111) 2026-11-11 18:48:06 +00:00
test_invoke_streaming.py fix(responses): bill the provider-reported input on a cut bridged stream (#53394) 2026-11-23 06:20:25 +00:00
test_routing_stores.py feat(redis): serve the health checks' deployment states from a native store (#50357) 2026-11-13 03:22:28 +00:00
test_surface_fallbacks.py
test_walk.py fix(router): keep the request's metadata on rust core fallback hop kwargs (#50263) 2026-11-06 08:46:44 +09:00