About
A developer-focused AI telemetry widget visualizing system, context, and output token allocation across a segmented animated bar with interactive hover breakdowns and real-time cost estimation.
Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Interactive LLM Token & Context Window Visualizer to your project and fits it to your theme.
Code
How Interactive LLM Token & Context Window Visualizer is used: the demo's code. The component's own source comes with a free account.
Usage.tsx
// This is a file with a demo for your component
// That's what users will see in the preview
// Create new files in this directory to add more demos
"use client";
import * as React from "react";
import { Component, type TokenSegment } from "@/components/ui/interactive-llm-token-context-window-visualizer";
import { cn } from "@/lib/utils";
/* ------------------------------------------------------------------ */
/* Demo data */
/* ------------------------------------------------------------------ */
const MAX_TOKENS = 128_000;
// Prices are per million tokens. Completion costs more than input.
const BASE: Omit<TokenSegment, "tokens">[] = [
{ id: "system", label: "System prompt", costPerMillion: 3, colorClass: "bg-violet-500" },
{ id: "rag", label: "RAG context", costPerMillion: 3, colorClass: "bg-sky-500" },
{ id: "history", label: "Chat history", costPerMillion: 3, colorClass: "bg-emerald-500" },
{ id: "completion", label: "Completion", costPerMillion: 15, colorClass: "bg-amber-500" },
];
const PRESETS: { name: string; tokens: number[] }[] = [
{ name: "Short chat", tokens: [1_200, 0, 3_400, 900] },
{ name: "RAG heavy", tokens: [2_400, 54_000, 12_500, 6_200] },
{ name: "Long session", tokens: [2_400, 18_000, 62_000, 9_000] },
{ name: "Near the limit", tokens: [3_000, 52_000, 58_000, 12_000] },
];
export default function DemoOne() {
const [tokens, setTokens] = React.useState<number[]>(PRESETS[1].tokens);
const [preset, setPreset] = React.useState(1);
const segments: TokenSegment[] = BASE.map((s, i) => ({ ...s, tokens: tokens[i] }));
return (
<div className="flex min-h-[640px] w-full flex-col items-center justify-center gap-6 bg-background px-4 py-12 text-foreground">
<Component modelName="GPT-4o · 128k" maxTokens={MAX_TOKENS} segments={segments} />
{/* Controls to play with the numbers */}
<div className="w-full max-w-2xl space-y-5 rounded-2xl border border-border bg-card p-5 sm:p-6">
<div role="group" aria-label="Presets" className="flex flex-wrap gap-2">
{PRESETS.map((p, i) => (
<button
key={p.name}
type="button"
aria-pressed={preset === i}
onClick={() => {
setTokens(p.tokens);
setPreset(i);
}}
className={cn(
"h-8 rounded-full border px-3.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
preset === i ? "border-primary bg-primary text-primary-foreground" : "border-border text-muted-foreground hover:text-foreground"
)}
>
{p.name}
</button>
))}
</div>
<div className="grid gap-4 sm:grid-cols-2">
{BASE.map((s, i) => (
<label key={s.id} className="block text-sm">
<span className="flex items-center justify-between text-muted-foreground">
<span className="flex items-center gap-2">
<span className={cn("size-2 rounded-full", s.colorClass)} />
{s.label}
</span>
<span className="tabular-nums text-foreground">{tokens[i].toLocaleString("en-US")}</span>
</span>
<input
type="range"
min={0}
max={70_000}
step={500}
value={tokens[i]}
onChange={(e) => {
const next = [...tokens];
next[i] = Number(e.target.value);
setTokens(next);
setPreset(-1);
}}
className="mt-2 w-full accent-[hsl(var(--primary))]"
/>
</label>
))}
</div>
</div>
</div>
);
}
















