Skip to content
TuffTasks, docs and chat for teams and AI agents

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.json

Usage

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

PropTypeDefaultDescription
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.
pacenumberaverage of the last 7 daysSpend a day from today on, drawn as the dashed forecast.
capnumber—Controlled cap. Where the forecast crosses it, the chart marks the day it's hit.
defaultCapnumberthe forecast, roundedStarting 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).
maxCapnumbera round number well above the forecastTop of the chart and the highest cap. Fixed, so the axis holds still while dragging.
capStepnumber50The cap snaps to this step when dragged or moved with keys.
breakdownSpendCategory[]—Spend by type as a thin stacked bar with a legend under the chart.
rulesBudgetRule[]—What happens when the cap is hit, as a segmented control. The chosen rule's description shows under it.
rulestring—Controlled rule value.
defaultRulestringthe first ruleStarting rule when uncontrolled.
onRuleChange(rule: string) => void—Called when another rule is picked.
onSave(cap: number, rule: string) => void—Shows the primary Save button.
savingbooleanfalseSpinner on the Save button while the policy is stored.
saveLabelstring"Save cap"Label of the primary button.
titlestring"Budget guard"Header title.
subtitlestring"Nov 2026 · resets Dec 1"Secondary line under the title.
iconIconShieldCheckPhosphor icon in the header tile.
introbooleantrueDraws 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.
classNamestring—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;
};