pub struct StreamDelta {
pub content: String,
pub thinking: Option<String>,
pub usage: Option<Usage>,
pub model: Option<String>,
pub stop_reason: Option<StopReason>,
pub is_final: bool,
}Expand description
An incremental chunk from a streaming language model response.
Fields§
§content: StringIncremental text content (may be empty on non-content events).
thinking: Option<String>Extended-thinking / reasoning text emitted on this chunk. Streamed
alongside (or before) content on providers that expose
chain-of-thought as a distinct content block:
- Bedrock Converse: populated from
ContentBlockDelta::Reasoningevents (gpt-oss, DeepSeek R1, Magistral, MiniMax M2, Nemotron-super on the Runtime endpoint).
None on the OpenAI Chat Completions surface (reasoning isn’t
streamed per OpenAI spec — it shows up only in
completion_tokens_details.reasoning_tokens accounting), and on
adapters that haven’t been extended to surface reasoning yet
(Anthropic thinking blocks, Mantle Responses reasoning events).
usage: Option<Usage>Token usage statistics. Presence and timing depend on the provider:
- Anthropic: populated on
message_deltaevents (mid-stream, sometimes on multiple events as token counts evolve). The finalmessage_stopevent carriesNone. - OpenAI / Ollama: populated only on the final pre-
[DONE]chunk, because we setstream_options.include_usage = trueon the request. Without that flag the field would beNonefor every chunk. - Default
generate_streamimpl (non-streaming providers wrapped into a one-item stream): populated on the single delta which is alsois_final.
Consumers that need cost tracking should accumulate or take the
last non-None value rather than expect usage on every chunk.
model: Option<String>The model name — typically only present on the first chunk.
stop_reason: Option<StopReason>Normalized reason generation stopped — populated on whichever chunk carries the wire-level stop signal:
- OpenAI Chat Completions: the final content chunk with a non-null
finish_reason. - Anthropic Messages: the
message_deltaevent (which also carries final usage). - Bedrock Converse: the
MessageStopevent (precedes the terminatingMetadatachunk that carries usage). - Mantle Responses: the
response.completedevent (also carries usage).response.incompleteevents with recoverable reasons (max_output_tokens,content_filter) surface their stop reason here too instead of being raised as errors.
None on intermediate content deltas and on providers that
don’t surface this on streams. Downstream consumers comparing
against max_tokens should prefer this field when present rather
than inferring truncation from output-token counts.
is_final: boolWhether this is the final chunk in the stream.
Trait Implementations§
Source§impl Clone for StreamDelta
impl Clone for StreamDelta
Source§fn clone(&self) -> StreamDelta
fn clone(&self) -> StreamDelta
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for StreamDelta
impl RefUnwindSafe for StreamDelta
impl Send for StreamDelta
impl Sync for StreamDelta
impl Unpin for StreamDelta
impl UnsafeUnpin for StreamDelta
impl UnwindSafe for StreamDelta
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more