pub struct StreamChunk {
pub text: String,
pub thinking_content: Option<String>,
pub token_usage: Option<TokenUsage>,
pub tool_calls: Option<Vec<ToolCall>>,
}Expand description
A single streaming chunk emitted by BaseChatModel::stream_chat.
Replaces the bare String chunk so streaming paths can observe token
usage without a separate non-streaming invoke. Most providers only
populate StreamChunk::token_usage on the final chunk; intermediate
chunks carry text with token_usage: None. Providers that do not report
usage (Ollama, local, proxy passthrough) always yield token_usage: None.
0.20.0 S3.2: StreamChunk::tool_calls carries the complete tool calls
requested by the model, accumulated from the provider’s streaming
tool_calls deltas. OpenAI-family providers (OpenAI / Azure / their
delegates) attach them to the terminal chunk — the usage chunk, or a
dedicated tool-calls chunk when the stream ends without usage; providers
without streaming tool-call support always yield None. Consumers that only
stream text can ignore the field.
Fields§
§text: StringThe text delta for this chunk.
thinking_content: Option<String>Model’s chain-of-thought / reasoning delta for this chunk, when the
provider exposes one on a separate channel (DeepSeek reasoning_content,
Anthropic thinking, Cohere thinking…). 0.25.0: previously the
field existed on some raw provider types but was dropped on the way to
BaseChatModel::stream_chat.
token_usage: Option<TokenUsage>Token usage for the whole streaming call, typically only on the last chunk (when the provider reports it).
tool_calls: Option<Vec<ToolCall>>Complete tool calls requested by the model in this streaming call, if
any. 0.20.0 S3.2: filled on the terminal chunk by providers that support
streaming tool_calls (OpenAI / Azure and their delegates); None
otherwise.