Anthropic::MessageStream
Inherits Enumerable < Reference < Object
MessageStream class for handling Server-Sent Events (SSE) from streaming API
Events are buffered on first iteration so that helper methods like
text, collect_text, final_message, thinking, and citations
can be called in any order and multiple times.
Constructors
Instance methods
Iterate through all events in the stream.
On the first call this reads from the response IO and buffers all
events. Subsequent calls replay from the buffer so that helpers
like text, collect_text, and final_message can be used in
any order and multiple times.
When the stream contains an SSE error event, this raises an
appropriately-typed Anthropic::APIError subclass immediately after
yielding the preceding events, mirroring the Ruby SDK's behavior. The
raw ErrorEvent is also yielded so callers can still observe it.
Get final message after consuming the entire stream.
Safe to call after text, collect_text, or any other helper --
events are buffered and replayed.