Function streamText

  • 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

    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);
    }