nextui.dev
Home
Docs
Saved
Pricing
Components37
  • Forms & inputs7
  • Cards13
  • Buttons, badges & avatars8
  • Feedback & display6
  • Effects3
Agents23
  • Chat inputNew
  • Task checklistNew
  • ReasoningNew
  • Tool callNew
  • Model pickerNew
  • Tool approvalNew
  • AttachmentsNew
  • SourcesNew
  • Agent timelineNew
  • Context meterNew
  • Artifact panelNew
  • Message actionsNew
  • Streaming messageNew
  • Sub-agentsNew
  • Conversation shellNew
  • Agent questionNew
  • Voice agentNew
  • Voice orbNew
  • Thinking ring
  • Thinking waveNew
  • Thinking sparkle
  • Thinking bot
  • Prompt deckNew
Blocks20
  • Agent chatNew
  • Pill heroNew
  • Grid hero
  • Moodboard generatorNew
  • Waitlist heroNew
  • Intro bannerNew
  • Creative home heroNew
  • Chat heroNew
  • App shelfNew
  • Usage card
  • Design resultsNew
  • Pricing tiers
  • Dashboard home
  • The shiftNew
  • Launch perksNew
  • Testimonials
  • Quote
  • Team
  • Leads tableNew
  • Sign in
Pages13
  • ASCII workspace$49
  • Research agent$49
  • Support agent$49
  • Coding agent$49
  • CRM overviewNew
  • Marketing dashboardNew
  • Developer portfolio$49
  • Particle landing$49
  • Particle story$49
  • Statement converter$49
  • AI photo studio$49
  • Group card launch$49
  • Month-end storyNew
Themes9
  • Default
  • Ember
  • Ocean
  • Forest
  • Grape
  • Rose
  • Amber
  • Clay
  • Brutal
Upgrade
nextui.dev

nextui components, blocks and themes you install with one command.

Product

  • Components
  • Blocks
  • Themes
  • Pricing

Resources

  • Docs
  • Roadmap
  • GitHub

Legal

  • License
  • Privacy
  • Terms
  • Refunds

nextUI

[ 200 OK ] · nextUI

© 2026 NEXTUI • All rights reserved.

Upgrade
ComponentsAI & agentsContext meter
Copy promptCopy prompt

Customize

Size of the model's context window in tokens

200000

Share of the window where the meter turns amber and offers to compact; red from 95%

0.8

Show the compacting state while you summarize

Starting open state when uncontrolled

Loop a conversation filling the window, warning and compacting, for demos

JSX · copied with Copy prompt

<ContextMeter autoPlay />

Context meterNew

How full the model's context window is: a ring that opens into a per-source token breakdown, with a Compact action near the limit.

Installation

Set your access key from API keys as NEXTUI_TOKEN in .env.local and add the @nextui namespace below to components.json once. Then every item installs by name. Each install counts as a copy on a free account.

$pnpm dlx shadcn@latest add @nextui/context-meter
1{
2 "registries": {
3 "@nextui": {
4 "url": "https://nextui.dev/r/{name}.json",
5 "headers": { "Authorization": "Bearer ${NEXTUI_TOKEN}" }
6 }
7 }
8}

Usage

1"use client";
2
3import { useChat } from "@ai-sdk/react";
4import { ContextMeter } from "@/components/nextui/context-meter";
5
6export function ChatHeader() {
7 const { messages } = useChat();
8 // Send token usage from your route with messageMetadata, e.g.
9 // result.toUIMessageStreamResponse({ messageMetadata: ({ part }) =>
10 // part.type === "finish" ? { inputTokens: part.totalUsage.inputTokens } : undefined })
11 const last = messages.at(-1)?.metadata as { inputTokens?: number } | undefined;
12 const used = last?.inputTokens ?? 0;
13
14 return (
15 <ContextMeter
16 max={200_000}
17 segments={[
18 { label: "System + tools", tokens: 15_000 },
19 { label: "Messages", tokens: Math.max(0, used - 15_000) },
20 ]}
21 onCompact={() => {
22 /* summarize older turns, then replace them with the summary */
23 }}
24 />
25 );
26}

API reference

Edit props live in the preview above, or see all 10 props
PropTypeDefaultDescription
segments{ label: string; tokens: number }[]–What fills the window, in order. Each gets a shade in the bar and a row in the breakdown
maxnumber200000Size of the model's context window in tokens
warnAtnumber0.8Share of the window where the meter turns amber and offers to compact; red from 95%
onCompact() => void–Called by the Compact button. Leave out to hide the button
compactingbooleanfalseShow the compacting state while you summarize
openboolean–Controlled open state of the breakdown
defaultOpenbooleanfalseStarting open state when uncontrolled
onOpenChange(open: boolean) => void–Called when the pill is clicked
autoPlaybooleanfalseLoop a conversation filling the window, warning and compacting, for demos
classNamestring–Extra classes on the wrapper

Related

All components

Chat inputNew

Task checklistNew

Free

ReasoningNew

Sign in to see the code

Preview it freely. A free account copies code and prompts a few times a day.

Sign in