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: content/docs/05-ai-sdk-ui/20-streaming-data.mdx
+20-15
Original file line number
Diff line number
Diff line change
@@ -5,15 +5,24 @@ description: Welcome to the Vercel AI SDK documentation!
5
5
6
6
# Streaming Data
7
7
8
-
Depending on your use case, you may want to stream additional data alongside the model's response. This can be achieved with [`StreamData`](/docs/reference/stream-helpers/stream-data).
8
+
Depending on your use case, you may want to stream additional data alongside the model's response.
9
+
This can be achieved with [`StreamData`](/docs/reference/stream-helpers/stream-data).
9
10
10
11
## What is StreamData
11
12
12
-
The `StreamData` class allows you to stream arbitrary data to the client alongside your LLM response. This can be particularly useful in applications that need to augment AI responses with metadata, auxiliary information, or custom data structures that are relevant to the ongoing interaction.
13
+
The `StreamData` class allows you to stream arbitrary data to the client alongside your LLM response.
14
+
This can be particularly useful in applications that need to augment AI responses with metadata, auxiliary information,
15
+
or custom data structures that are relevant to the ongoing interaction.
13
16
14
17
## How To Use StreamData
15
18
16
-
To use `StreamData`, create a `StreamData` value on the server, append some data and then return it alongside the model response with [`StreamingTextResponse`](/docs/reference/stream-helpers/streaming-text-response). On the client, the [`useChat`](/docs/reference/ai-sdk-ui/use-chat) hook returns `data`, which will contain the additional data.
19
+
To use `StreamData`, create a `StreamData` value on the server,
20
+
append some data, and then include it in `toAIStreamResponse`.
21
+
22
+
You need to call `close()` on the `StreamData` object to ensure the data is sent to the client.
23
+
This can best be done in the `onFinish` callback of `streamText`.
24
+
25
+
On the client, the [`useChat`](/docs/reference/ai-sdk-ui/use-chat) hook returns `data`, which will contain the additional data.
17
26
18
27
### On the server
19
28
@@ -22,9 +31,9 @@ To use `StreamData`, create a `StreamData` value on the server, append some data
0 commit comments