Loading component…
Loading component…
How many tokens an agent's runs take against a limit – the average per run large, every run as a bar in its model's color, the part above the limit in pink
To reuse this local React demo, copy all files from the Code tab into the same folder, then import TokenBudget from ./token-budget.
import { TokenBudget, type BudgetRun, type BudgetModel } from "@/components/ui/token-budget";
const models: BudgetModel[] = [
{ id: "opus", name: "Opus 5.5" },
{ id: "gpt", name: "GPT-5" },
];
const runs: BudgetRun[] = recent.map((r) => ({ id: r.id, label: `Run #${r.number}`, model: r.model, tokens: r.totalTokens }));
<TokenBudget title="Research agent tokens" runs={runs} limit={250_000} models={models} onAction={() => openUsage()} />| Name | Type | Default | Description |
|---|---|---|---|
| runs | BudgetRun[] | { id, tokens, model?, label? } – oldest first, the last one is the latest; ids keep the bars in place as new runs come in | |
| limit | number | Tokens per run to stay under – a pink line with its number on the left; the part of a bar above it turns pink | |
| models | BudgetModel[] | { id, name, color? } – the bars' colors and the legend; colors default to green, cyan, purple, amber, blue | |
| title | string | "Token Budget" | Heading on the frame |
| icon | ReactNode | A small mark before the title – defaults to a coin, in green | |
| actionLabel / onAction | string / () => void | "Open" | The button on the top right – it shows when onAction is given |
| formatTokens | (n: number) => string | "184k" / "1.2M" | Formats every count |
| className | string | Extra class on the root |
Built on a container query; under 420px the limit pill steps aside (the limit stays on the chart) – the card keeps the same size as every agent chart card
The oldest runs fade out at the left edge
Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"