mirror of
https://github.com/BerriAI/litellm.git
synced 2026-12-05 01:59:27 +00:00
* fix(cost): set the SDK stream wrapper's response_cost once the stream ends A streamed completion's wrapper reported response_cost 0.0 when it was created and kept it after the last chunk, so SDK callers reading it after the stream saw every call as free. The wrapper now starts at None while the cost is unknown and takes the finished response's cost when the stream ends. Cached streams keep their 0.0 and pre-priced replay streams keep the cost they were built with. Based on #49397. Co-authored-by: vanshsingh3711-wq <289212929+vanshsingh3711-wq@users.noreply.github.com> * fix(streaming): keep the 0.0 start cost and take the final cost at stream end, including Router and provider-billed streams * fix(streaming): price the stream's final response off the event loop and drop the unobservable pricing guard The async stream end now runs the cost calculator through asyncify, the same way it builds the final response, so an unpriced or provider-billed model's pricing no longer blocks the event loop. The pricing_left_unrecorded guard is gone, since the logged payloads match with and without it. * fix(streaming): keep stream-end logging on client disconnect, report the MCP chat stream's billed total, and bill Router fallback streams * fix(streaming): price the stream end again only when the builder could not, so unpriced chat streams skip a second cost lookup The stream builder already prices every chat response it assembles. The wrapper now takes that cost, and runs the calculator itself only for a provider that bills from its own usage fields or for a response the builder did not assemble (its failure path), where the builder leaves the cost unset. * fix(router): count a twice-continued stream's cut legs once in its final response_cost --------- Co-authored-by: vanshsingh3711-wq <289212929+vanshsingh3711-wq@users.noreply.github.com> |
||
|---|---|---|
| .. | ||
| __init__.py | ||
| conftest.py | ||
| test_aresponses_api_with_mcp.py | ||
| test_chat_completions_handler.py | ||
| test_litellm_proxy_mcp_handler.py | ||
| test_mcp_streaming_iterator.py | ||
| test_parked_stream_dispatch.py | ||
| test_round_billing.py | ||
| test_tool_precheck.py | ||