Streaming uses Anthropic’s server-sent events (SSE) protocol to deliver the response incrementally as it is generated. The SDK yieldsDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/phpaisdk/anthropic/llms.txt
Use this file to discover all available pages before exploring further.
TextDeltaPart, ReasoningDeltaPart, and ToolCallDeltaPart chunks as they arrive, so your application can begin rendering output without waiting for the full response to complete.
Basic Streaming
Call.stream() instead of .run() to receive a stream handle. Iterate over $stream->chunks() to receive each text delta as a string, then call $stream->run() to obtain the fully-assembled TextModelResponse once the stream is exhausted.
$stream->chunks() is a generator that yields plain text delta strings — the same content you would read from $result->text if you called .run() directly, but delivered piece by piece. After iterating all chunks, $stream->run() returns the complete TextModelResponse with final usage counts and finish reason.
Stream Events
The Anthropic SSE protocol sends a sequence of typed events. The SDK’s stream parser handles the following event types internally:message_start
Emitted once at the beginning of the stream. Contains the message ID and initial input token count. The SDK emits a
ProviderMetadataPart carrying the Anthropic message ID.content_block_start
Signals the start of a new content block. When the block type is
tool_use, the parser emits a ToolCallStartPart with the tool call’s index, id, and name.content_block_delta
Carries incremental content. The SDK maps the three delta subtypes as follows:
text_delta→ yields aTextDeltaPartwith the text fragmentthinking_delta→ yields aReasoningDeltaPartwith the reasoning fragmentinput_json_delta→ yields aToolCallDeltaPartwith a partial JSON string
message_delta
Emitted once near the end of the stream. Contains the
stop_reason and the final output token count. The SDK uses this to set the FinishReason on the assembled response.FinishPart carrying the resolved FinishReason and a Usage object with the complete input and output token counts.
The
stream: true flag is set automatically when you call .stream(). Do not pass it manually via .providerOptions() — doing so would conflict with the SDK’s own stream handling.