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/07-reference/stream-helpers/05-stream-to-response.mdx
+54-2
Original file line number
Diff line number
Diff line change
@@ -5,12 +5,64 @@ description: Learn to use streamToResponse helper function in your application.
5
5
6
6
# `streamToResponse`
7
7
8
-
This method will pipe a ReadableStream to a Node.js ServerResponse object. It can be helpful to combine this with other AI stream utilities, such as OpenAIStream, in Node.js environments. Similar to StreamingTextResponse, it automatically sets the status code to 200 and the Content-Type header to 'text/plain; charset=utf-8'
8
+
`streamToResponse` pipes an AI stream to a Node.js `ServerResponse` object and sets the status code and headers.
9
+
10
+
This is useful to create AI stream responses in environments that use `ServerResponse` objects, such as Node.js HTTP servers.
11
+
12
+
The status code and headers can be configured using the `options` parameter.
13
+
By default, the status code is set to 200 and the Content-Type header is set to `text/plain; charset=utf-8`.
9
14
10
15
## Import
11
16
12
17
### React
13
18
14
19
<Snippettext={`import { streamToResponse } from "ai"`}prompt={false} />
0 commit comments