Launch priceOne payment

Token Stream

Renders a streaming answer. Network chunks arrive in bursts; this lets them out at an even pace and settles each new character in from a soft blur, with a caret while more is coming. Pass the whole text each time and it handles the rest.

CreativeFree145 lines · one file

Ready for AI tools one file typed props installs by name prompt included

The decision inside it

It smooths the network, it does not slow the model

The reveal speeds up with the backlog, so a big burst flows out in a fraction of a second and is never more than a beat behind; when the stream ends it catches up within half a second. Only the newest characters animate, so long answers stay light and nothing already read re-plays.

Installation

How you get it

Paste this into Claude Code, Cursor, Codex or any coding agent. It installs the file and uses it as it is, instead of writing a new one.

Use Layro's Token Stream for this.
Install it: npx shadcn@latest add @layro/token-stream
(the @layro registry is set up in components.json, with LAYRO_KEY in .env.local)
Import it from @/components/ui/token-stream.
Do not rewrite or restyle it. Pass my data through its props
and keep its built-in states.

For the full brief with every prop and the mistakes assistants usually make, use Copy prompt above. Free components install through the @layro registry with your CLI token: see the Namespaced tab.

When to use it

Use Token Stream to show a streamed answer at an even, readable pace whatever the network does. Pass everything received so far as text and set streaming while more is coming.

Usage

components/answer.tsx
import { TokenStream } from "@/components/ui/token-stream";

export function Answer({ text, streaming }: { text: string; streaming: boolean }) {
  return <TokenStream text={text} streaming={streaming} />;
}

API

“Copy prompt” above puts a full brief on your clipboard — install command, dependencies, props, and the mistakes an assistant usually makes with this component.

Props

Read from the component’s own TypeScript interface when the site is built, so this table cannot drift from the file you install.

PropTypeNotes
textrequiredstringEverything received so far.
streamingbooleanMore is coming. Shows the caret and keeps pacing.
pacenumberBase characters per second, before backlog catch-up. Default 70.
rawbooleanShow text exactly as it arrives, no smoothing.

Dependencies

npm packages

clsxframer-motiontailwind-merge

Layro foundations, installed alongside it

layro-theme

Lifetime access

Every component, and everything we ship next.

  • All 132 components, source included
  • Every template, and everything released after you buy
  • shadcn CLI or download — React 18/19, Tailwind v4
  • One payment. No subscription.

More in Creative

All Creative components