Skip to main content

Budget meter

How much of its budget an agent has used: calls, tokens and cost, for the hour, the day and the month.

PatternReadyView source
Works with
Reactshadcn/ui
Runs on sample data, with the neutral theme of shadcn/ui.

A meter for agent dashboards. It makes a limit visible before the agent reaches it. The meter takes the budget object of the SDK as it is, and shows a row for each limit that is set.

Installation​

The command adds the file to your project, with the shadcn/ui components that it uses. Your project needs shadcn/ui.

pnpm dlx shadcn@latest add https://examples.lumoauth.dev/r/budget-meter.json

Usage​

Pass what agent.budget() returns.

app/agents/[id]/budget.tsx
import { BudgetMeter, type AgentBudget } from '@/components/budget-meter';

export function Budget({ name, budget }: { name: string; budget: AgentBudget }) {
return <BudgetMeter agentName={name} budget={budget} warnAt={0.8} />;
}

Where the data comes from​

What the pattern showsCall
Limits and usageagent.budget()
Report what a model call usedagent.reportUsage({ tokens, costUsd }). The answer holds the new budget.
The refusal at a limit429 budget_exceeded, LumoAuthBudgetExceededError
Tell your servicesThe webhook agent.budget_exhausted

States​

Runs on sample data, with the neutral theme of shadcn/ui.
  • No budget set.
  • Near a limit. A row turns to a warning at 80 percent, or at warnAt.
  • At a limit. The meter says that the agent is stopped until a period starts again.

Props​

PropTypeDefaultDescription
budgetrequiredAgentBudgetThe budget of the agent, as agent.budget() returns it.
agentNamestringThe name of the agent, for the title.
warnAtnumber0.8The share of a limit at which a row turns to a warning.
classNamestringClass name for the card.

AgentBudget​

OptionTypeDescription
max_api_calls_per_hour, max_api_calls_per_daynumberThe limits on calls. Usage: api_calls_this_hour, api_calls_today.
max_tokens_per_hour, max_tokens_per_daynumberThe limits on tokens. Usage: tokens_used_this_hour, tokens_used_today.
max_cost_per_day_usd, max_cost_per_month_usdnumberThe limits on cost. Usage: cost_today_usd, cost_this_month_usd.
exhaustedbooleanTrue when the server stopped the agent at a limit.