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

AI Tools · Function

smoothStream

smoothStream smooths text and reasoning output from streamText by buffering content into configurable chunks and releasing them with optional delays. It returns a TransformStream for streamText's experimental_transform option.

How it works

smoothStream creates a TransformStream for streamText. It buffers text and reasoning output, releases content according to the selected chunking strategy, optionally inserts delays between chunks, and forwards other event types immediately.

Syntax

smoothStream(options?: { delayInMs?: number | null; chunking?: "word" | "line" | RegExp | Intl.Segmenter | ((buffer: string) => string | undefined | null) })

Parameters

NameTypeDescription
delayInMsnumber | nullOptional delay in milliseconds between output chunks; defaults to 10 ms, or use null to disable delays.
chunking"word" | "line" | RegExp | Intl.Segmenter | (buffer: string) => string | undefined | nullOptional chunking strategy: word, line, RegExp, Intl.Segmenter, or a custom callback.

Returns

A TransformStream that buffers text and reasoning chunks, releases them at chunk boundaries with optional delays, and immediately passes through other chunk types.

Key points

  • Pass the returned transformer to streamText through experimental_transform.
  • Without configuration, smoothStream waits 10 milliseconds between emitted chunks.
  • The default chunking mode emits text word by word.
  • Intl.Segmenter provides locale-aware boundaries and is the recommended choice for CJK text.
  • Events outside text and reasoning are not buffered by the smoother.

Common mistakes

  • Use null for delayInMs when buffering should remain enabled without adding timing delays.
  • Hidden documents do not receive the configured delay, avoiding timer throttling that could stall streaming.

Example: Smooth streamed text

import { smoothStream, streamText } from 'ai';

const result = streamText({
  model,
  prompt: 'Explain photosynthesis.',
  experimental_transform: smoothStream({
    delayInMs: 20,
    chunking: 'word',
  }),
});

Applies smoothStream to streamText so text is buffered into words and released with a 20 ms interval.

When to use it

Word-by-word display

Streaming generated prose in a chat interface

Line-based output

Displaying generated content organized by paragraphs or lines

Locale-aware segmentation

Supporting languages whose word boundaries differ from whitespace

Mixed stream events

Preserving immediate delivery of tool and lifecycle events

Interview questions

QWhat problem does smoothStream solve?

smoothStream is a utility that returns a TransformStream for the streamText experimental_transform option. It buffers text and reasoning chunks and releases them according to a chunking rule, creating smoother output.

Follow-up: What happens to tool-call events? They bypass the smoothing behavior and are passed through immediately.

QHow does delayInMs affect output?

The optional delayInMs controls the interval between emitted chunks and defaults to 10 milliseconds. Passing null disables those delays while retaining the transformation.

Follow-up: What happens when the page is hidden? The delay is skipped so browser timer throttling does not stall the stream.

QHow can chunk boundaries be customized?

chunking defaults to word and also accepts line, a regular expression, Intl.Segmenter, or a callback. Intl.Segmenter is recommended when locale-aware segmentation is needed, including for CJK languages.

Follow-up: What constraint applies to a custom regular expression? It must not match the empty string.

  • streamText
  • experimental_transform
  • Intl.Segmenter

Source: smoothStream. Checked 2026-10-15.