A developer notices that when using streaming with extended thinking enabled, the thinking content blocks appear before the text content blocks in the stream. The application needs to display the final answer to the user while optionally showing thinking to developers. What is the correct approach to handle thinking blocks in the stream?
Select an answer to reveal the explanation.
Short Explanation
You should use the content_block_start event's type field to tell thinking blocks apart from text blocks. Then you can stream the text blocks to the user while logging the thinking blocks for developers.
Full Explanation
The correct approach is to use the content_block_start event's type field to differentiate thinking blocks (type: 'thinking') from text blocks (type: 'text'). The SSE stream for extended thinking responses includes these typed content block events, so the application can route delta events to different handlers: stream text deltas to the user-facing display while capturing thinking deltas in a developer console or debug log. This preserves real-time streaming for the user while still providing developer observability into the model's thinking content.
The option that says to set a system prompt instruction such as 'do not show thinking' is wrong because thinking block generation cannot be suppressed that way once extended thinking is enabled. The thinking parameter controls thinking at the API level, and the model generates thinking blocks as part of the extended thinking process.
The option that says to buffer all streamed content until message_stop and then filter out thinking blocks is wrong because it defeats the purpose of streaming for the user. It introduces full response latency before any display update, even though the stream already provides typed events that allow selective handling in real time.
The option that says to disable streaming when extended thinking is enabled is wrong because the Anthropic API does support streaming with extended thinking. The stream simply includes additional event types and content block types for thinking blocks, so streaming remains available.