affectUI › Components › Agents
Token Budget
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.
Part of affectUI Pro. Install: npx shadcn@latest add https://www.affectui.com/r/token-budget.json · Import from @/components/ui/token-budget
When to use
- How many tokens an agent's runs take against a per-run limit – and which model burned them
- A dashboard tile next to other agent chart cards, live as new runs come in
When not to use
- Where the tokens of one run went – use Token Flow
- How much of a model's context one run fills – use Context Window
- Money over a billing period – use Usage Meter or Cost Waterfall
Usage
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()} />Props
| 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 |
Keyboard
- Tab: Moves into the runs (one stop) and on to Open
- ArrowLeft / ArrowRight: Walks the runs and shows each one's model, tokens and how far it went over; Home and End jump to the oldest and the latest
- Esc: Lets go of the run
Accessibility
- The runs are a single tab stop; the run you're on is its description
- How many runs went over is said in words, not only in pink
Responsive
- 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"
Requirements
- React 19
Related
- Latency Range – How fast an agent answers, hour by hour, like a blood-pressure chart – every hour as a bar from p50 to p95, pink above the target, the latest large and in blue
- Tool Activity – Which tools an agent used, day by day, as a field of dots – each lights up in its tool's color, the stronger the busier, with today's calls and the total on top
- Token Flow – Where an agent's tokens and cost go, as a Sankey diagram of cards – system prompt, tool results and memory flow into the models and on into answered, retried or cancelled
- Context Window – What fills the model's context, as a field of cells – hover a part to light it up, remove files, and compact the conversation while its cells shimmer and clear