Anthropic model streaming responses are delivered in event chunks. Below is a list of the event types with some notes on what they mean.
# Event Types
```json
event: message_start
data: {"type": "message_start", "message": {"id": "msg_1nZdL29xx5MUA1yADyHTEsnR8uuvGzszyY", "type": "message", "role": "assistant", "content": [], "model": "claude-3-5-sonnet-20241022", "stop_reason": null, "stop_sequence": null, "usage": {"input_tokens": 25, "output_tokens": 1}}}
```
This indicates the beginning of a message. It is notable for giving the model-provided count of the input tokens, as well as the initial output token count.
```json
event: content_block_start
data: {"type": "content_block_start", "index": 0, "content_block": {"type": "text", "text": ""}}
```
The beginning of a block of response content, whether it's text or something else.
```json
event: ping
data: {"type": "ping"}
```
```json
event: content_block_delta
data: {"type": "content_block_delta", "index": 0, "delta": {"type": "text_delta", "text": "Hello"}}
```
The content block delta from the previous content block event. Either a `content_block_start` or another `content_block_delta`.
```json
event: content_block_delta
data: {"type": "content_block_delta", "index": 0, "delta": {"type": "text_delta", "text": "!"}}
```
```json
event: content_block_stop
data: {"type": "content_block_stop", "index": 0}
```
The end of a content block, but not necessarily a whole message/response.
```json
event: message_delta
data: {"type": "message_delta", "delta": {"stop_reason": "end_turn", "stop_sequence":null}, "usage": {"output_tokens": 15}}
```
The `message_delta` event signifies any "top-level" or message-level changes to the response with additional metadata for the message, such as the `stop_reason`, `stop_sequence`, and final count of `output_tokens`, including changes to the output tokens. This count is the **total** count of output tokens that were used (see [here](https://github.com/anthropics/anthropic-sdk-python/issues/424#issuecomment-2228024007)), not a number that needs to be added to the initial `output_tokens` count.
```json
event: message_stop
data: {"type": "message_stop"}
```
The final message end event.
# Source
https://docs.anthropic.com/en/api/messages-streaming