Skip to main content
By default, the Agent SDK yields a complete AssistantMessage for each non-empty content block, such as a text block or a tool call, after Claude finishes generating that block. To receive incremental updates as text and tool calls are generated, enable partial message streaming.
This page covers output streaming (receiving tokens in real-time). For input modes (how you send messages), see Send messages to agents. You can also stream responses using the Agent SDK via the CLI.

Enable streaming output

To enable streaming, set include_partial_messages (Python) or includePartialMessages (TypeScript) to true in your options. This causes the SDK to yield StreamEvent messages containing raw API events as they arrive, in addition to the usual AssistantMessage and ResultMessage. Your code then needs to:
  1. Check each message’s type to distinguish StreamEvent from other message types
  2. For StreamEvent, extract the event field and check its type
  3. Look for content_block_delta events where delta.type is text_delta, which contain the actual text chunks
The example below enables streaming and prints text chunks as they arrive. Notice the nested type checks: first for StreamEvent, then for content_block_delta, then for text_delta:

StreamEvent reference

When partial messages are enabled, you receive raw Claude API streaming events wrapped in an object. The type has different names in each SDK: Both contain raw Claude API events, not accumulated text. You need to extract and accumulate text deltas yourself. The parent_tool_use_id field is always None in Python and null in TypeScript. Stream events are emitted for the main session only; token-level deltas from subagents aren’t forwarded. To attribute output to a subagent, use complete messages, which carry parent_tool_use_id. See Detect subagent invocation. Claude Code sets user_message_uuid on the turn’s first non-ping stream event, and again when the message the turn is answering changes, under the conditions in user_message_uuid. The Python StreamEvent doesn’t expose this field. The event field contains the raw streaming event from the Claude API. Common event types include:

Message flow

Claude Code emits an AssistantMessage as each non-empty content block completes, so a response with a text block and a tool call yields two AssistantMessage objects. Each one carries only its own content block, and both share the same message ID, which you read as message.message.id in TypeScript and message.message_id in Python. With partial messages enabled, each AssistantMessage arrives before that block’s content_block_stop event, and you receive messages in this order: