pub enum RawStreamingChoice<R = StreamFinal> {
Show 14 variants
Message(String),
TextStart {
id: StreamPartId,
additional_params: Option<AdditionalParams>,
},
TextAdditionalParams(AdditionalParams),
ToolCall(RawStreamingToolCall),
ToolCallDelta {
id: StreamPartId,
content: ToolCallDeltaContent,
},
ToolInputEnd(ToolInputEnd),
Reasoning {
id: StreamPartId,
provider_id: Option<WireId>,
content: ReasoningContent,
},
ReasoningStart {
id: StreamPartId,
provider_id: Option<WireId>,
},
ReasoningEnd {
id: StreamPartId,
reasoning: Option<Reasoning>,
signature: Option<String>,
wire_sent: bool,
},
TextEnd {
id: StreamPartId,
},
ReasoningDelta {
id: StreamPartId,
provider_id: Option<WireId>,
reasoning: String,
},
FinalResponse(R),
MessageId(String),
Unknown(UnknownPayload),
}Expand description
Enum representing a streaming chunk from the model.
R is the terminal record type. Ordinary streams use the normalized
StreamFinal default; a provider’s inherent raw_stream method
substitutes its own native terminal type over the same event vocabulary,
which is what keeps crate::completion::CompletionModel free of response
associated types.
Variants§
Message(String)
A text chunk from a message response
TextStart
Start a new text content block in the accumulated final choice.
This is an internal provider-normalization event. It is not yielded to public stream consumers, but lets providers preserve block boundaries and metadata for final aggregated assistant text blocks.
Fields
id: StreamPartIdIdentity of the text block being opened.
The same mandatory-identity contract as
RawStreamingChoice::Reasoning::id: distinct wire output items
must aggregate as distinct text parts (two OpenAI Responses
message items must not concatenate), so the accumulator keys
text blocks by identity. Providers propagate the wire’s item
identity (StreamPartId::Wire: the Responses item_id, Anthropic’s
block index) when it exists, or mint one at the boundary
(StreamPartId::Minted, via SyntheticIds). A wire that never
announces text boundaries may skip TextStart entirely: a bare
RawStreamingChoice::Message with no open block opens a
boundary-minted block.
additional_params: Option<AdditionalParams>Provider-specific metadata attached to this text block.
TextAdditionalParams(AdditionalParams)
Provider-specific metadata for the current text content block.
This is not yielded to public stream consumers. The metadata is merged
into the current aggregated Text block.
crate::message::AdditionalParams is non-empty by construction, so
a provider with nothing to attach skips the variant instead of
emitting an empty carrier.
ToolCall(RawStreamingToolCall)
A tool call response (in its entirety) — wires that never fragment
tool input emit this directly; fragmenting wires emit
RawStreamingChoice::ToolCallDelta fragments closed by
RawStreamingChoice::ToolInputEnd, and the shared accumulator
assembles the completed call.
ToolCallDelta
A tool call partial/delta.
All fragments of one call carry one id; the shared accumulator keys
assembly by it and mints the internal correlation id when the call
opens, so adapters never track per-call state.
Fields
id: StreamPartIdIdentity of the tool call this fragment extends, stable across the call’s fragments.
The same mandatory-identity contract as
RawStreamingChoice::Reasoning::id: parallel calls interleave
their fragments on real wires, so the accumulator must key
assembly by identity. Providers propagate the wire’s tool-call id
(StreamPartId::Wire), or mint one at the boundary from the wire’s
own index (StreamPartId::Minted, via SyntheticIds) when the wire
omits it — a shared identity would collapse parallel calls into
one corrupted assembly. A minted identity keys assembly only; it
never becomes the completed call’s durable
ToolCall::id.
content: ToolCallDeltaContentToolInputEnd(ToolInputEnd)
End of a streamed tool call’s input: the shared accumulator finalizes the assembled fragments (or the event’s authoritative payload) into a completed tool call.
Reasoning
A reasoning (in its entirety)
Fields
id: StreamPartIdIdentity of the reasoning item this block belongs to.
Required: reasoning interleaves with other output on real wires
(OpenAI Responses emits the completed item after tool calls), so
the accumulator must key by identity rather than guess by
adjacency. Providers propagate the wire’s item id
(StreamPartId::Wire: item_id on Responses events) or mint a
stream-scoped id at the boundary (StreamPartId::Minted, via
SyntheticIds) when the wire has none. Deltas and the full
block for the same item MUST carry the same key.
provider_id: Option<WireId>The provider-issued reasoning item id, when one exists — the
durable handle that becomes
Reasoning::id and round-trips
upstream. Carried separately from the accumulation key: the key
is opaque and can never leak; the handle is data.
content: ReasoningContentComplete reasoning content block.
ReasoningStart
Open the reasoning part identified by id.
Optional — a bare RawStreamingChoice::ReasoningDelta opens its
part leniently — but a wire that announces block starts should emit
it so arrival order is fixed at the wire’s own boundary. A start for
an already-open key is a no-op; a start for a finished key opens a
new part (key reuse). Not yielded to public stream consumers.
Fields
id: StreamPartIdAccumulation key of the reasoning part being opened.
ReasoningEnd
Close the reasoning part identified by id — the lifecycle
primitive every wire has (or has synthesized by its adapter at the
boundaries it already detects), so “is this part still open?” is
never re-derived per wire.
reasoning is the wire’s authoritative whole-block restatement; it
supersedes the delta accumulation. signature is a provider
signature closing the block; it attaches to the part’s text — and
because an end for an already-finished key with only a signature
attaches to THAT part, a trailing signature signs the block that
holds the chain-of-thought instead of fabricating an empty sibling.
A repeated end with no payload is a no-op: idempotence belongs to
the entity, not to a guard each route must remember.
The completed part is yielded to consumers as
StreamedAssistantContent::Reasoning — the uniform
block-completed signal across every wire — when the wire itself
said something at the boundary: an end carrying a restatement or
signature, or a bare end frame the wire actually sent
(wire_sent). A bare end an adapter synthesized at an
interleaving boundary stays silent: the consumer already received
every delta, and fabricating a completion event the wire never
sent would change what downstream history builders observe.
Fields
id: StreamPartIdAccumulation key of the reasoning part being closed.
TextEnd
Close the text block identified by id: later bare text deltas open
a fresh block instead of extending it. (A later
RawStreamingChoice::TextStart with the same key still
reactivates the block — the keyed collapse is explicit.) Not yielded
to public stream consumers.
Fields
id: StreamPartIdAccumulation key of the text block being closed.
ReasoningDelta
A reasoning partial/delta
Fields
id: StreamPartIdAccumulation key of the reasoning item this delta extends. Same
contract as RawStreamingChoice::Reasoning::id; all deltas of
one block share one key.
provider_id: Option<WireId>The provider-issued reasoning item id, when one exists (see
RawStreamingChoice::Reasoning::provider_id) — what a
delta-built part records as its durable id.
FinalResponse(R)
The final response object, must be yielded if you want the
response field to be populated on the StreamingCompletionResponse
MessageId(String)
Provider-assigned message ID (e.g. OpenAI Responses API msg_ ID).
Captured silently into StreamingCompletionResponse::message_id.
Unknown(UnknownPayload)
A provider-native output item this version does not model — e.g. an
OpenAI Responses hosted-tool result (web_search_call, file_search_call,
computer_call, code_interpreter_call). Carries the raw item object
verbatim. Forwarded to the stream consumer as
StreamedAssistantContent::Unknown but not folded into the accumulated
assistant message (there is no AssistantContent::Unknown history slot).
Implementations§
Source§impl<R> RawStreamingChoice<R>
impl<R> RawStreamingChoice<R>
Sourcepub fn try_map_final<S>(
self,
map: impl FnOnce(R) -> Result<S, CompletionError>,
) -> Result<RawStreamingChoice<S>, CompletionError>
pub fn try_map_final<S>( self, map: impl FnOnce(R) -> Result<S, CompletionError>, ) -> Result<RawStreamingChoice<S>, CompletionError>
Convert only the terminal record, preserving every incremental content event unchanged.
Trait Implementations§
Source§impl<R> Clone for RawStreamingChoice<R>where
R: Clone,
impl<R> Clone for RawStreamingChoice<R>where
R: Clone,
Source§fn clone(&self) -> RawStreamingChoice<R>
fn clone(&self) -> RawStreamingChoice<R>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more