Conversational chat
Render chatbot output progressively while the model is still generating.
AI Tools · Const
Streaming exposes parts of an AI response as soon as they are generated, so a UI can begin rendering earlier than with a blocking response. It improves perceived responsiveness for conversational interfaces.
Streaming sends portions of a model response as soon as they are available instead of waiting for the complete response. In the AI SDK, streamText produces an asynchronous text stream that consumers can iterate over incrementally.
streamText({ model, prompt })An incremental stream of response text consumed as chunks become available.
import { streamText } from 'ai';
import { openai } from '@ai-sdk/openai';
const result = streamText({
model: openai('gpt-4o-mini'),
prompt: 'Explain streaming in one sentence.',
});
for await (const chunk of result.textStream) {
process.stdout.write(chunk);
}Streams generated text chunks to the terminal as they arrive.
Render chatbot output progressively while the model is still generating.
Show the first useful words quickly in a long-form generation workflow.
Reduce perceived waiting time in an interactive AI interface.
streamTexttextStreamuseChatuseCompletion