Anthropic::MessageStream
Inherits Enumerable < Reference < Object
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.
Parse the final message's structured output into T.
Returns nil when no final message exists yet, the message has no
text content, or the text does not parse as JSON.
Parse the final message's structured output into T.
Raises StructuredOutputParseError when no final message exists,
the message has no text content, or the text does not parse as T.