Skip to main content

Module stream

Module stream 

Source
Expand description

SSE Streaming Parser for the Claude Messages API

The Claude API sends Server-Sent Events (SSE) when stream: true. Format: event: <name>\ndata: <json>\n\n

This module provides:

  • SseParser: reads raw bytes from reqwest and yields typed StreamEvents
  • MessageAccumulator: builds a complete MessagesResponse from events

The tricky part: bytes arrive in arbitrary chunks that may split mid-line. We buffer until we see \n\n (end of SSE event), then parse.

Structs§

MessageAccumulator
Accumulates streaming events into a complete MessagesResponse.
MessageDeltaPayload
Top-level message metadata update
SseParser
Parses SSE events from a reqwest byte stream.

Enums§

ContentDelta
Incremental content within a content_block_delta event
StreamEvent
All possible SSE event types from the Claude streaming API. Each variant matches an event: <name> line in the SSE stream.