litellm/litellm-rust/crates/inference-chat/Cargo.toml
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

38 lines
1.3 KiB
TOML

[package]
name = "litellm-inference-chat"
version = "0.1.0"
edition.workspace = true
license.workspace = true
repository.workspace = true
[dependencies]
base64.workspace = true
bytes.workspace = true
futures-util.workspace = true
litellm-auth = { workspace = true, features = ["aws", "azure", "gcp"] }
litellm-cache-response.workspace = true
litellm-core-utils.workspace = true
litellm-framer.workspace = true
litellm-host.workspace = true
litellm-http.workspace = true
litellm-inference.workspace = true
litellm-llms.workspace = true
litellm-llms-types.workspace = true
litellm-secrets.workspace = true
litellm-token-counter = { path = "../token-counter", default-features = false, features = ["tiktoken"] }
reqwest.workspace = true
serde_json = { workspace = true, features = ["preserve_order"] }
tokio = { workspace = true, features = ["time"] }
tokio-util = { version = "0.7", features = ["codec"] }
tracing.workspace = true
uuid.workspace = true
[dev-dependencies]
litellm-cache-memory.workspace = true
litellm-host-native.workspace = true
litellm-http = { workspace = true, features = ["test-support"] }
litellm-inference-testing.workspace = true
litellm-tracing.workspace = true
rstest.workspace = true
tokio = { workspace = true, features = ["io-util", "sync"] }
wiremock.workspace = true