An architect is designing the Messages API integration for a streaming chatbot. The frontend displays tokens as they are generated. After receiving a message_start event, the client receives repeated content_block_delta events, then unexpectedly receives an error event mid-stream. What is the correct handling strategy?
Select an answer to reveal the explanation.
Short Explanation and Infographic
Here's the deal — when an SSE stream is interrupted by an error event, the correct UX and architectural response is: close the connection cleanly, preserve and display the partial content already received (it was valid output), mark it as incomplete with a visual indicator, and present a retry option to the user. Option A (auto-retry without user awareness) degrades UX and wastes compute for long generations.
Full explanation below image
Full Explanation
When an SSE stream is interrupted by an error event, the correct UX and architectural response is: close the connection cleanly, preserve and display the partial content already received (it was valid output), mark it as incomplete with a visual indicator, and present a retry option to the user. Option A (auto-retry without user awareness) degrades UX and wastes compute for long generations. Option B is incorrect — the Anthropic API does not provide a partial-retry offset; you must restart the full request from the beginning. Option C (buffer everything, display only on message_stop) defeats the purpose of streaming and creates bad UX; errors should surface immediately so the user isn't left waiting on a failed connection. Option D correctly prioritizes user transparency and graceful degradation.