mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-30 01:08:33 +00:00
* 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> |
||
|---|---|---|
| .. | ||
| src | ||
| tests | ||
| AGENTS.md | ||
| Cargo.toml | ||