Settings & Usage
Budget Guard
A monthly spend cap you drag on the chart — forecast at the current pace, the day it's hit, and what happens then.
1 variantMIT
Preview
Budget guard
Nov 2026 · resets Dec 1
$530 over cap
- Spent
- $1,03952% of cap
- Forecast
- $2,530at $88/day
- Cap
- $2,000hits Nov 24
Cap$2K
$1,039 spent of a $2,000 cap by Nov 13. At $88 a day the month ends near $2,530; Cap hit on Nov 24.
- Agents$53852%
- Chat$41240%
- Embeddings$899%
When the cap is hit
Running agents finish their current step, then pause until Dec 1. Chat keeps working.
Installation
Copies the component into components/ui and installs its dependencies and theme tokens.
pnpm dlx shadcn@latest add https://tuffui.com/r/budget-guard.jsonUsage
Pass your own data and wire the callbacks to your agent runtime.
import { BudgetGuard } from "@/components/ui/budget-guard";
// Workspace settings → Usage. Spend comes from your billing export.
export function SpendCap({ usage, policy }: Props) {
const [cap, setCap] = useState(policy.cap);
const [rule, setRule] = useState(policy.onCapHit);
return (
<BudgetGuard
month={usage.month} // "2026-11-01"
daily={usage.dailySpend} // [38, 72, 81, …] one entry per day so far
breakdown={[
{ id: "agents", label: "Agents", value: usage.byType.agents },
{ id: "chat", label: "Chat", value: usage.byType.chat },
{ id: "embeddings", label: "Embeddings", value: usage.byType.embeddings },
]}
cap={cap}
onCapChange={setCap}
rules={[
{ value: "pause", label: "Pause agents", description: "Agents pause until the 1st." },
{ value: "downgrade", label: "Cheaper model", description: "Requests move to a smaller model." },
{ value: "notify", label: "Notify only", description: "Owners get an alert." },
]}
rule={rule}
onRuleChange={setRule}
onSave={(c, r) => savePolicy({ cap: c, onCapHit: r })}
/>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
| daily* | number[] | — | Spend per day so far this month, the 1st first. Its length is today: the solid line ends there and the forecast takes over. |
| month* | string | Date | — | Any day in the tracked month, e.g. `"2026-11-01"`. Sets the number of days and the date labels. |
| pace | number | average of the last 7 days | Spend a day from today on, drawn as the dashed forecast. |
| cap | number | — | Controlled cap. Where the forecast crosses it, the chart marks the day it's hit. |
| defaultCap | number | the forecast, rounded | Starting cap when uncontrolled. |
| onCapChange | (cap: number) => void | — | Called while the cap line is dragged anywhere along it, or its handle is moved with the arrow keys (Shift or Page Up/Down for bigger steps). |
| maxCap | number | a round number well above the forecast | Top of the chart and the highest cap. Fixed, so the axis holds still while dragging. |
| capStep | number | 50 | The cap snaps to this step when dragged or moved with keys. |
| breakdown | SpendCategory[] | — | Spend by type as a thin stacked bar with a legend under the chart. |
| rules | BudgetRule[] | — | What happens when the cap is hit, as a segmented control. The chosen rule's description shows under it. |
| rule | string | — | Controlled rule value. |
| defaultRule | string | the first rule | Starting rule when uncontrolled. |
| onRuleChange | (rule: string) => void | — | Called when another rule is picked. |
| onSave | (cap: number, rule: string) => void | — | Shows the primary Save button. |
| saving | boolean | false | Spinner on the Save button while the policy is stored. |
| saveLabel | string | "Save cap" | Label of the primary button. |
| title | string | "Budget guard" | Header title. |
| subtitle | string | "Nov 2026 · resets Dec 1" | Secondary line under the title. |
| icon | Icon | ShieldCheck | Phosphor icon in the header tile. |
| intro | boolean | true | Draws the spend line in on mount. Skipped with reduced motion. |
| formatMoney | (value: number) => string | "$1,284" | Formats the stats, the header pill and the legend. |
| formatAxis | (value: number) => string | "$1.5K" | Formats the y axis and the value on the cap handle. |
| className | string | — | Extra classes for the root element. |
type SpendCategory = {
id: string;
label: string; // "Agents"
value: number; // spend so far this month
color?: string; // any CSS color; defaults to accent shades, then grays
};
type BudgetRule = {
value: string; // "pause"
label: string; // "Pause agents"
description?: React.ReactNode;
};