litellm/litellm-rust/crates/inference-chat
Nate Armstrong 0099dad675
fix(gateway): estimate stream usage an openai-compatible provider does not send (#47367)
* fix(gateway): estimate stream usage an openai-compatible provider does not send

A client asking for stream_options.include_usage from mistral, cerebras,
perplexity and the other providers whose configs drop stream_options got
no usage chunk, since the provider streamed none. Python's stream wrapper
adds one estimated with token_counter; the relay now does the same, with
cl100k: prompt tokens from the messages alone, completion tokens from the
content plus each tool call as model_dump_json() writes it, plus the
reasoning counted apart. The chunk is shaped like Python's, comes before
[DONE] and is recorded as the call's usage.

* fix(gateway): bound the tokenizing a stream usage estimate does

Encoding runs inline and grows faster than the text on a long run of one
character, so a large prompt could hold a worker for seconds and allocate
gigabytes. Each estimate now encodes at most 64 KiB and extrapolates the rest
at the rate of the text encoded.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-19 12:55:28 -07:00
..
src fix(gateway): estimate stream usage an openai-compatible provider does not send (#47367) 2026-10-19 12:55:28 -07:00
tests feat(gateway): land the chat provider series and full-feature load test on the poc branch (#47388) 2026-10-19 12:47:12 -07:00
AGENTS.md feat(gateway): native OpenAI chat completions with SSE passthrough (#46813) 2026-10-16 12:43:00 -07:00
Cargo.toml fix(gateway): estimate stream usage an openai-compatible provider does not send (#47367) 2026-10-19 12:55:28 -07:00