Quota Forecast

Projects current usage to the reset date and warns when you'll run out first, so a usage limit isn't hit by surprise.

StopsHit the usage limit by surprise

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/quota-forecast.json

The files land in your project. They're yours to edit.

Usage

quota-forecast-usage.tsx
import { QuotaForecast } from "@/components/ui/quota-forecast"

<QuotaForecast
  label="API calls"
  used={calls}
  limit={limit}
  periodStart={periodStart}
  resetsAt={resetsAt}
  now={now}
  atLimit="At the limit, new calls fail with a 429 error until {reset}."
  actionLabel="Raise limit"
  onAction={() => setLimit(25_000)}
/>

What it catches

  • Running out before the reset at the current pace, with the date
  • Usage ahead of an even pace
  • Too early in the period to trust a rate: says so
  • What happens at the limit (atLimit)

Props

QuotaForecast props
PropTypeDefault
label* (required)

What is metered, e.g. "API calls".

string—
used* (required)

Amount used so far this period.

number—
limit* (required)

The plan's limit for the period.

number—
periodStart* (required)

When the current period started.

Time—
resetsAt* (required)

When usage resets.

Time—
now

The current time. Defaults to the clock, read after mount so SSR stays stable.

Time—
formatValue

Formats amounts, e.g. bytes as "18.2 GB".

(value: number) => string—
locale

Locale for dates and numbers.

string"en-GB"
atLimit

Plain words for what happens at the limit, e.g. "New calls get a 429 error until {reset}."

string—
actionLabel

Fix offered once it's a warning, e.g. "Add credits".

string—
onAction

Runs the fix, e.g. opens the upgrade dialog.

() => void—
warnAt

Share of the limit (0–1) where the tone turns amber.

number—
dangerAt

Share of the limit (0–1) where the tone turns red.

number—
runsOutText

Templates. `{date}`, `{reset}`, `{days}` and `{percent}` are filled in.

string"At this pace you'll run out {date}, {days} before it res…
onTrackText

Shown when usage is on track to fit.

string"On pace for about {percent}% by the reset on {reset}."
earlyText

Shown while it's too early to forecast.

string"Too early to forecast. Resets {reset}."
outText

Shown when the limit is already reached.

string"You've reached the limit. It resets {reset}."

* required. Also accepts the native props of <div> (className, aria-*, data-*…), passed through to it.

Accessibility

  • role=meter with min, max, now and aria-valuetext including the forecast
  • Forecast text is a polite live region
  • The even-pace marker is aria-hidden; the message says it in words

Only what the source does. Test with your own screen reader and content before shipping.

Limitations

  • Assumes the average rate so far continues; spikes and seasonality aren't modelled
  • Numbers are what you pass; it doesn't meter usage

What it stops

Hit the usage limit by surprise

Also known as

usage · quota · plan limit · credits · api limit · billing · storage · meter

Field type

Dependencies

Pairs well with