Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

AI Tools · Const

Streaming Responses

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.

How it works

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.

Syntax

streamText({ model, prompt })

Returns

An incremental stream of response text consumed as chunks become available.

Key points

  • Streaming delivers response fragments incrementally, allowing the interface to show output before generation completes.
  • Streaming improves perceived responsiveness because users can see the beginning of an answer sooner.
  • A non-streaming interface cannot render partial model output while the response is still being generated.
  • Choose streaming or blocking behavior according to the interface requirements and their respective trade-offs.

Common mistakes

  • A blocking response delays all visible output until generation finishes, so use streaming when early rendering matters.

Example: Stream text incrementally

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.

When to use it

Conversational chat

Render chatbot output progressively while the model is still generating.

Long responses

Show the first useful words quickly in a long-form generation workflow.

Responsive user interfaces

Reduce perceived waiting time in an interactive AI interface.

  • streamText
  • textStream
  • useChat
  • useCompletion

Source: Streaming. Checked 2026-10-15.