Skip to main content

Function: streamText()

streamText(opts): StreamTextResult

Defined in: packages/agentos/src/api/streamText.ts:140

Stateless streaming text generation with optional multi-step tool calling.

Returns a StreamTextResult immediately; the underlying provider call begins lazily when a consumer starts iterating textStream or fullStream. Awaiting text, usage, or toolCalls will also drain the stream.

Parameters

opts

GenerateTextOptions

Generation options (same shape as generateText).

Returns

StreamTextResult

A StreamTextResult with async iterables and awaitable promises.

Example

const { textStream } = streamText({ model: 'openai:gpt-4o', prompt: 'Tell me a joke.' });
for await (const chunk of textStream) {
process.stdout.write(chunk);
}