Skip to content
Sign upPro
ComposerToken estimateMenu

Token estimate (Pro)

ProIncluded in $99

A live token and cost estimate under the composer that never jitters, knows the model's context window, and says how much room is left before it runs out.

ProA contracts lead types a question, then pastes a clause again and again. The count glides, the row never shifts, and it warns near the limit.

Installation

$ pnpm dlx shadcn@latest add @chatcn-pro/token-estimate

Needs chatcn Pro

This command works with a Pro license, along with every Pro component.

Or start free: sign up and get three Pro components on us, with a new one every month.

Usage

tsx
import { TokenEstimate } from "@/components/ui/chatcn/pro/token-estimate"

<PromptInput value={draft} onValueChange={setDraft}>…</PromptInput>
<TokenEstimate
  text={draft}
  model={{ name: "Claude Opus 5.5", contextWindow: 128_000, inputPrice: 5 }}
  context={[{ key: "messages", label: "Conversation", tokens: 71_940 }]}
  reserve={8_000}
  onStatusChange={(s) => setBlocked(s === "over")}
/>

The row says what this message costs: its tokens, the input cost of sending it with everything already in the context, and how full the window is. Each number sits in a slot reserved for its widest value and aligned to the end, so it grows into empty space and nothing beside it moves; between values it glides for 160 ms, so a paste reads as one change instead of a flicker of digits. Near the limit the start of the row turns amber and says how much room is left; over it, red, with by how much and what to do, and onStatusChange lets you hold Send. The ring is the free ContextMeter, with this message and the reply reserve as their own segments in its breakdown. The default estimateTokenCount is a fast heuristic within about 10% on English prose and code; pass your tokenizer as estimate for exact counts.

Examples

States

ProNothing typed, a short question, a pasted clause with a reply reserve, near the limit, over it, no price, and attached files.

Props

PropTypeNotes
textstringThe draft. Estimated on every change
model{ name, contextWindow, inputPrice? }Price is US dollars per million input tokens. No price hides the cost
contextContextSegment[]What is already in the window: system, conversation, files
attachednumberTokens that go with this message, such as files
reservenumberTokens kept free for the reply, counted against the limit
estimate(text) => numberYour tokenizer. Default estimateTokenCount
nearAtnumberFraction of the window that warns. Default 0.85
onStatusChange("empty" | "ok" | "near" | "over") => voidFor example to disable Send when over
labelsPartial<TokenEstimateLabels>Every string, for translation

Accessibility

  • Crossing into near or over is announced once in a polite live region, never per keystroke.
  • Warnings carry an icon and words, not color alone.
  • The ring is a button that opens the breakdown, named with the share of the window in use.
  • The cost has a title that names the price it was computed at.

Motion

Numbers glide to their new value in 160 ms on an ease out cubic, in place, inside reserved tabular slots. Reduced motion shows the value directly. Nothing else animates.