Skip to content
GitHub (opens in a new tab)

UsageMeter

Plan usage or AI credits against a limit: total, usage by category, daily bars toned against the cap, and a warning near the limit. Composes kit Meter, UsageList, BarChart and Alert.

stableOrganismcontracts/usagemeter.json

Preview

UsageMeter

Plan usage and AI credits. Built from Meter, UsageList and BarChart.

Master

Near the limit: the Meter turns warning, an Alert says what is left and Upgrade is the primary. Variants shows normal, limit reached and over limit.

AI credits · Pro plan

Near limit

9,240/ 10,000 credits

Nov 1Limit 10,000 · resets Dec 1
Chat3,510 credits
Code agent3,140 credits
Tool calls1,390 credits
Other1,200 credits

Daily usage

today 968 · cap 1,000 a day · 4 days near the cap

760 credits left

At this pace you hit the limit in ~2 days.

Usage

UsageMeter composes kit Meter (total), UsageList (by category), BarChart (daily, toned near and over the cap) and Alert (near limit). Upgrade becomes the solid primary only near or over the limit.

Do's

  • show credits or plan usage for the current period
  • warn before a limit and offer the upgrade
  • break usage down by category and day
  • a compact credits block on a settings or billing page (compact)

Don'ts

  • one value without breakdown — Meter
  • several independent limits — UsageList
  • prompt context in a thread — ContextWindow
<UsageMeter
  title="AI credits · Pro plan"
  used={9240}
  limit={10000}
  categories={categories}
  periodStart="Nov 1"
  resetLabel="resets Dec 1"
  daily={daily}
  dailyCap={1000}
  paceNote="At this pace you hit the limit in ~2 days."
  onUpgrade={upgrade}
  onViewUsage={viewUsage}
/>

When to use

  • show credits or plan usage for the current period
  • warn before a limit and offer the upgrade
  • break usage down by category and day
  • a compact credits block on a settings or billing page (compact)

When not to use

  • one value without breakdown — Meter
  • several independent limits — UsageList
  • prompt context in a thread — ContextWindow

What an agent reads

import { UsageMeter } from "agentic-ds-kit";
must
  • section aria-labelledby the h3 title
  • the total is a kit Meter with a full text label
  • past the limit the badge reads Over limit and the meter's name says how far over and, with overage, the amount so far
  • categories are a kit UsageList
  • the daily bars are a kit BarChart with its data table; the chart note counts days near and over the cap, so tone is not colour alone
  • near limit and limit reached are said in a Badge and a kit Alert, not colour alone
  • aria-busy while loading; the error is a kit LoadError (role=alert)
defaults
  • unit credits
  • warnAt 0.8
  • compact false
  • upgradeLabel Upgrade plan
  • loading false
stops if
  • Do not invent a local CreditMeter or BillingUsage
  • Do not reimplement Meter, UsageList or LineChart inside it
  • Do not show Upgrade as the primary when usage is normal
  • Do not use raw hex

From contracts/usagemeter.json: must is the a11y requirements, defaults the prop defaults, stops if the doNot rules where the agent asks instead of inventing a cousin.

Props

NameTypeRequiredDefaultNotes
titlestringYes——
usednumberYes——
limitnumberYes——
unitstringNocredits—
categoriesarrayNo—{ id, label, value }[] listed with a kit UsageList against the limit.
periodStartstringNo——
resetLabelstringNo——
dailynumber[]No—Kit BarChart, one bar a day.
dailyLabelsstring[]No——
dailyCapnumberNo—Days from warnAt of the cap take status.warningBorder, days over it status.dangerBorder; the chart note says the cap and counts them.
warnAtnumberNo0.8Same 80% threshold as UsageList.
paceNotestringNo——
overageobjectNo—{ rateLabel, amount }, pre-formatted. Usage past the limit keeps running and is billed: the warning and the meter's name say the rate and the amount so far.
compactbooleanNofalseOne block for a settings page: title, badge and Upgrade on one line, then used of limit · reset · pace, the meter and categories in a row. No figure, axis, daily bars or Alert. Spans its container; under 40rem categories drop and Upgrade goes full width below the meter.
onUpgradefunctionNo—Upgrade plan, the one solid primary; shown near or over the limit.
upgradeLabelstringNoUpgrade plane.g. "Upgrade to Business".
onViewUsagefunctionNo—View usage (outline).
loadingbooleanNofalse—
errorstringNo——
onRetryfunctionNo——
  • Component
    →

    Meter

    How far along or how full something is, from 0 to 100, as a bar, a ring, or a half ring, with optional red, amber, and green zones.

  • Component
    →

    UsageList

    A list of usage limits, one a row: the limit's name, how much is used of it, a bar, and a short note.

  • Component
    →

    ContextWindow

    How full the prompt context is and what uses the space, by segment, with a warning near the limit, Trim oldest and compaction with Undo.

  • Component
    →

    Alert

    Inline status banner that stays on the page.