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
MessageDeltaPayload
MessageStartPayload
StreamParser
Accumulates streaming data and produces StreamEvent values.

Enums§

RawContentBlock
RawDelta
RawSseEvent
Raw SSE data payload (deserialized from each data: line).
StreamEvent
Events yielded by the stream parser.