0
Fork 0
mirror of https://github.com/TanStack/ai.git synced 2026-11-16 19:38:41 +00:00
ai/docs/reference/functions/streamToText.md
github-actions[bot] f4f32bdcc2
docs: regenerate API documentation (#1195)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-08-22 08:16:20 +00:00

951 B

id title
streamToText streamToText

Function: streamToText()

function streamToText(stream): Promise<string>;

Defined in: packages/ai/src/stream-to-response.ts:45

Collect all text content from a StreamChunk async iterable and return as a string.

This function consumes the entire stream, accumulating content from TEXT_MESSAGE_CONTENT events, and returns the final concatenated text.

Parameters

stream

AsyncIterable<AGUIEvent>

AsyncIterable of StreamChunks from chat()

Returns

Promise<string>

Promise - The accumulated text content

Example

const stream = chat({
  adapter: openaiText('gpt-5.5'),
  messages: [{ role: 'user', content: 'Hello!' }]
});
const text = await streamToText(stream);
console.log(text); // "Hello! How can I help you today?"