Skip to main content

Module stream

Module stream 

Source
Expand description

SSE (Server-Sent Events) stream parser.

Parses the text/event-stream format used by LLM APIs for streaming responses. Yields StreamEvent values as content blocks arrive.

The stream processes these SSE event types:

  • message_start — initializes the response with usage data
  • content_block_start — begins a new content block (text, tool_use, thinking)
  • content_block_delta — appends partial data to the current block
  • content_block_stop — finalizes and yields the completed block
  • message_delta — final usage and stop_reason
  • message_stop — stream complete

Structs§

ErrorPayload
Payload from an error SSE event.
MessageDeltaPayload
Payload from the message_delta SSE event (stop reason, final usage).
MessageStartPayload
Payload from the message_start SSE event (model, initial usage).
StreamParser
Accumulates streaming data and produces StreamEvent values.

Enums§

RawContentBlock
Raw content block from content_block_start (text, tool_use, or thinking).
RawDelta
Raw delta from content_block_delta (text, JSON input, thinking, signature).
RawSseEvent
Raw SSE data payload (deserialized from each data: line in the Anthropic stream).
StreamEvent
Events yielded by the stream parser.