streaming changedbuild-with-claude/streaming
Nearest release: v2.1.307, published an hour after this site recorded the change. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.
Recorded here
Lines+39added
Lines−39removed
From line
284
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits14to this page, all time
The whole hunk
from line 284, old and new numbered
/
from line 284
284284 ```
285285</CodeGroup>
286286
287The `.stream()` (java: `.createStreaming()`; csharp: `.CreateStreaming()`; go: `.NewStreaming()`; php: `->createStream()`) call keeps the HTTP connection alive with server-sent events, then the SDK's message-accumulation helper, `stream.get_final_message()` (typescript: `stream.finalMessage()`; ruby: `stream.accumulated_message`; csharp: `.Aggregate()`; go: `message.Accumulate(event)`; java, php: `MessageAccumulator`), collects all events into the complete `Message` object.
287The `.stream()` (java: `.createStreaming()`; csharp: `.CreateStreaming()`; go: `.NewStreaming()`; php: `->createStream()`) call keeps the HTTP connection alive with server-sent events, and then the SDK's message-accumulation helper, `stream.get_final_message()` (typescript: `stream.finalMessage()`; ruby: `stream.accumulated_message`; csharp: `.Aggregate()`; go: `message.Accumulate(event)`; java, php: `MessageAccumulator`), collects all events into the complete `Message` object.
288288
289289## Event types
290290
from line 303
303303
304304### Ping events
305305
306Event streams may also include any number of `ping` events.
306Event streams might also include any number of `ping` events.
307307
308308### Error events
309309
310The API may occasionally send [errors](https://platform.claude.com/docs/en/api/errors) in the event stream. For example, during periods of high usage, you may receive an `overloaded_error`, which would normally correspond to an HTTP 529 in a non-streaming context:
310The API might occasionally send [errors](https://platform.claude.com/docs/en/api/errors) in the event stream. For example, during periods of high usage, you might receive an `overloaded_error`, which would normally correspond to an HTTP 529 in a non-streaming context:
311311
312312```sse Example error
313313event: error
from line 335
335335
336336The deltas for `tool_use` content blocks correspond to updates for the `input` field of the block. To support maximum granularity, the deltas are *partial JSON strings*, whereas the final `tool_use.input` is always an *object*.
337337
338You can accumulate the string deltas and parse the JSON once you receive a `content_block_stop` event, by using a library like [Pydantic](https://docs.pydantic.dev/latest/concepts/json/#partial-json-parsing) to do partial JSON parsing, or by using the SDK's [streaming helpers](https://platform.claude.com/docs/en/build-with-claude/streaming#streaming-with-sdks). In the Python and TypeScript SDKs, these helpers also give you access to the parsed `input` incrementally, as it streams.
338You can accumulate the string deltas and parse the JSON once you receive a `content_block_stop` event, by using a library such as [Pydantic](https://docs.pydantic.dev/latest/concepts/json/#partial-json-parsing) to do partial JSON parsing, or by using the SDK's [streaming helpers](https://platform.claude.com/docs/en/build-with-claude/streaming#streaming-with-sdks). In the Python and TypeScript SDKs, these helpers also give you access to the parsed `input` incrementally, as it streams.
339339
340340A `tool_use` content block delta looks like:
341341
from line 344
344344data: {"type": "content_block_delta","index": 1,"delta": {"type": "input_json_delta","partial_json": "{\"location\": \"San Fra"}}}
345345```
346346
347Note: Current models only support emitting one complete key and value property from `input` at a time. As such, when using tools, there may be delays between streaming events while the model is working. Once an `input` key and value are accumulated, they are emitted as multiple `content_block_delta` events with chunked partial JSON so that the format can automatically support finer granularity in future models.
347Note: Current models only support emitting one complete key and value property from `input` at a time. As such, when using tools, there might be delays between streaming events while the model is working. Once an `input` key and value are accumulated, they are emitted as multiple `content_block_delta` events with chunked partial JSON so that the format can automatically support finer granularity in future models.
348348
349349### Thinking delta
350350
from line 386
386386
3873874. A `message_stop` event
388388
389There may be `ping` events dispersed throughout the response as well. See [Event types](https://platform.claude.com/docs/en/build-with-claude/streaming#event-types) for more details on the format.
389There might be `ping` events dispersed throughout the response as well. See [Event types](https://platform.claude.com/docs/en/build-with-claude/streaming#event-types) for more details on the format.
390390
391391### Basic streaming request
392392
from line 560
560560### Streaming request with tool use
561561
562562<Tip>
563 Tool use supports [fine-grained streaming](https://platform.claude.com/docs/en/agents-and-tools/tool-use/fine-grained-tool-streaming) for parameter values. Enable it per tool with `eager_input_streaming`.
563 Tool use supports [fine-grained streaming](https://platform.claude.com/docs/en/agents-and-tools/tool-use/fine-grained-tool-streaming) for parameter values. Enable it on individual tools with `eager_input_streaming`.
564564</Tip>
565565
566566This request asks Claude to use a tool to report the weather.
from line 567
567567
568568<CodeGroup>
569569 ```bash cURL
570 curl https://api.anthropic.com/v1/messages \
571 -H "content-type: application/json" \
572 -H "x-api-key: $ANTHROPIC_API_KEY" \
573 -H "anthropic-version: 2023-06-01" \
574 -d '{
575 "model": "claude-opus-5",
576 "max_tokens": 1024,
577 "tools": [
578 {
579 "name": "get_weather",
580 "description": "Get the current weather in a given location",
581 "input_schema": {
582 "type": "object",
583 "properties": {
584 "location": {
585 "type": "string",
586 "description": "The city and state, e.g. San Francisco, CA"
587 }
588 },
589 "required": ["location"]
590 }
570 curl https://api.anthropic.com/v1/messages \
571 -H "content-type: application/json" \
572 -H "x-api-key: $ANTHROPIC_API_KEY" \
573 -H "anthropic-version: 2023-06-01" \
574 -d '{
575 "model": "claude-opus-5",
576 "max_tokens": 1024,
577 "tools": [
578 {
579 "name": "get_weather",
580 "description": "Get the current weather in a given location",
581 "input_schema": {
582 "type": "object",
583 "properties": {
584 "location": {
585 "type": "string",
586 "description": "The city and state, e.g. San Francisco, CA"
587 }
588 },
589 "required": ["location"]
591590 }
592 ],
593 "tool_choice": {"type": "any"},
594 "messages": [
595 {
596 "role": "user",
597 "content": "What is the weather like in San Francisco?"
598 }
599 ],
600 "stream": true
601 }'
591 }
592 ],
593 "tool_choice": {"type": "any"},
594 "messages": [
595 {
596 "role": "user",
597 "content": "What is the weather like in San Francisco?"
598 }
599 ],
600 "stream": true
601 }'
602602 ```
603603
604604 ```bash CLI
from line 1503
15031503
15041504### Error recovery best practices
15051505
15061. **Use SDK features:** Leverage the SDK's built-in message accumulation and error handling capabilities.
15061. **Use SDK features:** Rely on the SDK's built-in message accumulation and error handling capabilities.
150715072. **Handle content types:** Be aware that messages can contain multiple content blocks (`text`, `tool_use`, `thinking`). Tool use and thinking blocks cannot be partially recovered. You can resume streaming from the most recent text block.
15081508
15091509## Next steps
No line in this hunk matches that.