Open History to see the last commit
1---
2id: streamToText
3title: streamToText
4---
5
6```ts
7function streamToText(stream): Promise<string>;
8```
9
10Defined in: [packages/ai/src/stream-to-response.ts:49](https://github.com/TanStack/ai/blob/main/packages/ai/src/stream-to-response.ts#L49)
11
12Collect all text content from a StreamChunk async iterable and return as a string.
13
14This function consumes the entire stream, accumulating content from TEXT_MESSAGE_CONTENT events,
15and returns the final concatenated text.
16
17## Parameters
18
19### stream
20
21`AsyncIterable`\<[`AGUIEvent`](../type-aliases/AGUIEvent.md)\>
22
23AsyncIterable of StreamChunks from chat()
24
25## Returns
26
27`Promise`\<`string`\>
28
29Promise<string> - The accumulated text content
30
31## Example
32
33```typescript
34const stream = chat({
35 adapter: openaiText('gpt-5.5'),
36 messages: [{ role: 'user', content: 'Hello!' }]
37});
38const text = await streamToText(stream);
39console.log(text); // "Hello! How can I help you today?"
40```