A team is implementing a streaming response handler in Python. They observe that occasionally an event arrives with event: 'error' and the stream terminates. The current code does not handle this event type and the application crashes. What is the complete set of SSE event types that a robust streaming handler must handle?
Select an answer to reveal the explanation.
Short Explanation
Here's the deal — you need the full set of message lifecycle events plus the error event, because the streaming API can send a structured error event mid-stream. If you don't handle it, your handler crashes instead of surfacing the API error.
Full Explanation
The correct answer is the complete set that includes message_start, content_block_start, ping, content_block_delta, content_block_stop, message_delta, message_stop, and error. The Anthropic streaming API emits all seven message lifecycle events plus an error event for API-level errors, such as context length exceeded mid-stream or server errors. The error event carries a structured JSON body with error type and message. The robust handler must explicitly handle error events to log error details and gracefully terminate the stream rather than crashing on an unexpected event type. The option that lists only the seven lifecycle events and claims the error event is a client-side network exception is wrong because the error event is documented as a server-sent event type in the Anthropic streaming specification, not a client-side network exception; network exceptions are raised at the socket level and are distinct from streaming error events. The option that lists only start, delta, stop, and error is wrong because the simplified four-event schema does not match the Anthropic API specification; the actual event taxonomy is more granular, as described by the complete lifecycle set. The option that lists message_start, content_block_delta, message_stop, and error is wrong because content_block_start and content_block_stop are present for all content blocks, not only when tool use is active; they bracket every text and thinking block in the stream.