You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/anthropic.md
+285-2Lines changed: 285 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -77,9 +77,41 @@ A successful **non-streaming** request returns a `Message` object.
77
77
78
78
#### Streaming Response (200 OK)
79
79
80
-
If`stream: true` is set, the API streams back a sequence of server-sent events. The response is a series of JSON events that incrementally build the complete message object.
80
+
When`stream: true` is set, the API streams the response using server-sent events (SSE). Each event is named (e.g., `event: message_start`) and contains associated JSON data.
81
81
82
-
According to the documentation, the `stop_reason` provides insight into the stream's state: in the initial `message_start` event, the `stop_reason` field will be `null`. In all other events, it will be non-null once the stopping condition is known.
82
+
The event flow for a stream is as follows:
83
+
84
+
1.`message_start`: Contains a `Message` object with empty `content`.
85
+
2. A series of content blocks. Each block has a `content_block_start` event, one or more `content_block_delta` events, and a `content_block_stop` event. The `index` in these events corresponds to the content block's position in the final `content` array.
86
+
3. One or more `message_delta` events, which indicate top-level changes to the final `Message` object. The `usage` field in this event contains cumulative token counts.
87
+
4. A final `message_stop` event.
88
+
89
+
The stream may also include `ping` events to keep the connection alive and `error` events if issues occur.
90
+
91
+
##### Content Block Delta Types
92
+
93
+
Each `content_block_delta` event contains a `delta` object that updates a content block.
-**Input JSON Delta**: Used for `tool_use` blocks, these deltas contain partial JSON strings for the tool's `input` field. The partial strings must be accumulated and parsed into a final JSON object upon receiving the `content_block_stop` event.
-**Thinking Delta**: When extended thinking is enabled, these deltas update the `thinking` field of a thinking content block. A special `signature_delta` event is sent just before the `content_block_stop` to verify the block's integrity.
110
+
111
+
```json
112
+
event: content_block_delta
113
+
data: {"type": "content_block_delta", "index": 0, "delta": {"type": "thinking_delta", "thinking": "Let me solve this step by step:\n\n1. First break down 27 * 453"}}
114
+
```
83
115
84
116
#### The Usage Object
85
117
@@ -93,6 +125,257 @@ The `usage` object details billing and rate-limit token counts.
93
125
|`cache_read_input_tokens`| integer | The number of input tokens read from the cache. |
94
126
|`service_tier`| string | The service tier used for the request (`standard`, `priority`, or `batch`). |
data: {"type": "content_block_delta", "index": 0, "delta": {"type": "thinking_delta", "thinking": "Let me solve this step by step:\n\n1. First break down 27 * 453"}}
0 commit comments