Usage billing
Usage-based billing dashboard with a cumulative daily spend chart and projection, keyboard day cursor, live spend-alert threshold lines, metered resource bars, invoice downloads, and a modal prorated upgrade sheet.
import { UsageBilling } from '@uthereal/ui/usage-billing'Usage billing playground
Usage and billing, March 2025
March 2025 · day 18 of 31
Projected €580 by period end
| Day | Spend |
|---|---|
| Mar 1 | €18.40 |
| Mar 2 | €21.10 |
| Mar 3 | €24.80 |
| Mar 4 | €16.20 |
| Mar 5 | €12.90 |
| Mar 6 | €9.40 |
| Mar 7 | €10.20 |
| Mar 8 | €19.60 |
| Mar 9 | €23.40 |
| Mar 10 | €26.80 |
| Mar 11 | €20.10 |
| Mar 12 | €15.70 |
| Mar 13 | €11.30 |
| Mar 14 | €10.80 |
| Mar 15 | €17.90 |
| Mar 16 | €22.60 |
| Mar 17 | €25.40 |
| Mar 18 | €28.20 |
Daily spend and projection€580 projected
Resources
- API requests912K of 1M requests, projected 1.6M, over the limit
- Storage74 of 100 gigabytes, projected 127, close to the limit
- Seats6 of 10 seats, projected 10, close to the limit
Spend alerts
- Alert at €500.00, email on, Slack on
- Alert at €700.00, email on
Invoices
- INV-0142March 2025 · issued Apr 1, 2025€86.40Paid
- INV-0131February 2025 · issued Mar 1, 2025€104.20Paid
- INV-0118January 2025 · issued Feb 1, 2025€78.90Refunded
- INV-0105December 2024 · issued Jan 1, 2025€64.70Failed
Pro plan
€99.00 per month
- 1M API requests
- 100 GB storage
- 10 seats
- Email and Slack alerts
Visa ending 4242, expires 08/27
Overview
UsageBilling presents a metered billing period in one stacked card: period spend to date with an animated counter, a cumulative daily spend curve that carries the recent seven-day average forward as a dashed projection against the monthly budget, metered resource bars colored by projected attention state, an inline Spend alerts editor whose thresholds appear live on the chart, invoice history with spinner-to-check downloads, and a plan summary card that opens a modal upgrade confirmation sheet with proration math.
Use UsageBilling for usage-priced infrastructure, API, or AI platform billing pages where finance and engineering teams track daily burn alongside quota limits and spend alerts. For seat-based subscription settings with inline card editing, use Billing overview. For a focused single-metric forecast with a draggable budget slider, use Usage forecast.
Usage
'use client'
import { UsageBilling } from '@uthereal/ui/usage-billing'
export function MeteredBilling({ snapshot }: { snapshot: BillingSnapshot }) {
return (
<UsageBilling
period={snapshot.period}
daily={snapshot.dailySpend}
budget={snapshot.budget}
meters={snapshot.meters}
plan={snapshot.plan}
upgrade={snapshot.upgradeOffer}
defaultAlerts={snapshot.alerts}
invoices={snapshot.invoices}
payment={snapshot.card}
currency={snapshot.currency}
onAlertsChange={(alerts) => {
void fetch('/api/billing/alerts', {
method: 'PUT',
headers: { 'content-type': 'application/json' },
body: JSON.stringify(alerts),
})
}}
onUpgrade={async (planId) => {
const res = await fetch('/api/billing/upgrade', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ planId }),
})
if (!res.ok) throw new Error('Upgrade failed')
}}
onDownloadInvoice={async (invoiceId) => {
const res = await fetch(`/api/billing/invoices/${invoiceId}.pdf`)
if (!res.ok) throw new Error('Download failed')
}}
/>
)
}Return a Promise from onUpgrade or onDownloadInvoice to drive the loading, check, and error states until the request settles. Omit onDownloadInvoice to preview a simulated short download; omit onUpgrade to close the upgrade sheet immediately on confirm.
Examples
Enterprise overage without an upgrade offer
Pass upgrade={null} to hide the upgrade trigger and modal sheet on a top-tier Enterprise contract, payment={null} for wire-invoiced accounts without a card on file, currency="USD", and high daily spend exceeding the monthly budget so the pace banner and critical resource bars highlight the overage.
Usage and billing, October 2026
October 2026 · day 20 of 31
Projected $4,909 by period end, $2,409 over budget
| Day | Spend |
|---|---|
| Oct 1 | $118.40 |
| Oct 2 | $126.20 |
| Oct 3 | $134.80 |
| Oct 4 | $121.50 |
| Oct 5 | $98.40 |
| Oct 6 | $84.20 |
| Oct 7 | $91.60 |
| Oct 8 | $142.30 |
| Oct 9 | $156.80 |
| Oct 10 | $168.40 |
| Oct 11 | $174.10 |
| Oct 12 | $152.00 |
| Oct 13 | $114.60 |
| Oct 14 | $108.90 |
| Oct 15 | $164.50 |
| Oct 16 | $179.20 |
| Oct 17 | $188.60 |
| Oct 18 | $196.40 |
| Oct 19 | $204.20 |
| Oct 20 | $212.80 |
Daily spend and projection$4,909 projected
Resources
- API requests24M of 25M requests, projected 37M, over the limit
- Storage1.6K of 2K gigabytes, projected 2.5K, close to the limit
- Worker invocations4.8M of 5M invocations, projected 7.5M, over the limit
Spend alerts
- Alert at $2,000.00, email on, Slack on
- Alert at $2,500.00, email on, Slack on
Invoices
- INV-0418September 2026 · issued Oct 1, 2026$2,642.50Paid
- INV-0392August 2026 · issued Sep 1, 2026$2,318.00Paid
Enterprise plan
$1,200.00 per month
- 25M API requests
- 2 TB storage
- 5M worker invocations
- Dedicated TAM and wire invoicing
Healthy spend within budget
Provide steady daily spend well below the monthly budget and every alert rule, meters comfortably under 75%, three custom alert thresholds, and an empty invoices array for a workspace in its first billing cycle.
Usage and billing, October 2026
October 2026 · day 14 of 31
Projected $358 by period end
| Day | Spend |
|---|---|
| Oct 1 | $11.20 |
| Oct 2 | $12.40 |
| Oct 3 | $13.10 |
| Oct 4 | $10.80 |
| Oct 5 | $9.60 |
| Oct 6 | $7.20 |
| Oct 7 | $7.80 |
| Oct 8 | $12.60 |
| Oct 9 | $13.40 |
| Oct 10 | $14.20 |
| Oct 11 | $11.90 |
| Oct 12 | $10.50 |
| Oct 13 | $8.10 |
| Oct 14 | $12.80 |
Daily spend and projection$358 projected
Resources
- API requests280K of 1M requests, projected 620K
- Storage24 of 100 gigabytes, projected 53
- Seats4 of 10 seats, projected 8.9
Spend alerts
- Alert at $400.00, email on
- Alert at $700.00, email on, Slack on
- Alert at $900.00, email on, Slack on
Invoices
No invoices yet.
Pro plan
$99.00 per month
- 1M API requests
- 100 GB storage
- 10 seats
- Email and Slack alerts
Visa ending 4242, expires 08/27
Spend projection, alerts, and upgrade sheet
Pace and resource attention thresholds
| Surface | ok | warning | critical |
|---|---|---|---|
| Header pace banner | Projected spend ≤ 80% of budget. | Projected spend > 80% and ≤ 100% of budget. | Projected spend > budget (shows overage amount). |
| Resource meter bar | Below 75% of plan.limits[id] and not pacing over. | ≥ 75% of limit, or linear pace used × days / today exceeds limit. | ≥ 90% of limit or already at/above limit. |
Alerts and upgrade proration
- Projection math: Carries the average of the last
7elapsed days indailyacrossperiod.days - daily.lengthremaining days. - Spend alerts: Supports up to
5rules. Editing an amount and blurring (or pressingEnter) validates whole positive integers, re-sorts rules ascending by amount, updates the chart's dashed warning hairlines, and callsonAlertsChange. - Upgrade confirmation sheet: Opens inside a portalled
ModalLayer(role="dialog",aria-modal="true") with a prorated charge/credit breakdown over the remaining days and a side-by-side resource limits table. RejectingonUpgradedisplays an inlinerole="alert"error inside the sheet without closing it.
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
period | UsageBillingPeriodDefault: {"label":"March 2025","start":"2025-03-01","days":31,"today":18} | Billing period window and elapsed days; drives the chart length and the projection. |
daily | number[]Default: [18.4,21.1,24.8,16.2,12.9,9.4,10.2,19.6,23.4,26.8,20.1,15.7,11.3,10.8,17.9,22.6,25.4,28.2] | Spend so far, one value per elapsed day from the period start; the chart sums it into the cumulative line. |
budget | numberDefault: 750 | Spend budget for the period, drawn as a dashed rule with a right-gutter label. |
meters | UsageBillingMeter[]Default: [{"id":"requests","name":"API requests","unit":"requests","used":912400},{"id":"storage","name":"Storage","unit":"gigabytes","used":74},{"id":"seats","name":"Seats","unit":"seats","used":6}] | Metered resources with usage so far; each limit comes from plan.limits by meter id. |
plan | UsageBillingPlanDefault: {"id":"pro","name":"Pro","price":99,"limits":{"requests":1000000,"storage":100,"seats":10},"perks":["1M API requests","100 GB storage","10 seats","Email and Slack alerts"]} | The active plan shown on the plan card, with its perks and price. |
upgrade | UsageBillingPlan | nullDefault: {"id":"business","name":"Business","price":249,"limits":{"requests":5000000,"storage":500,"seats":25},"perks":["5M API requests","500 GB storage","25 seats","Priority support","Spend alerts"]} | Upgrade offer shown in the confirmation sheet; null hides the upgrade action. |
defaultAlerts | UsageBillingSpendAlert[]Default: [{"id":"alert-1","amount":500,"email":true,"slack":true},{"id":"alert-2","amount":700,"email":true,"slack":false}] | Alert rules shown on first render, re-sorted ascending by amount on edit; at most five. |
invoices | UsageBillingInvoice[]Default: [{"id":"inv-0142","number":"INV-0142","period":"March 2025","issued":"2025-04-01","amount":86.4,"status":"paid"},{"id":"inv-0131","number":"INV-0131","period":"February 2025","issued":"2025-03-01","amount":104.2,"status":"paid"},{"id":"inv-0118","number":"INV-0118","period":"January 2025","issued":"2025-02-01","amount":78.9,"status":"refunded"},{"id":"inv-0105","number":"INV-0105","period":"December 2024","issued":"2025-01-01","amount":64.7,"status":"failed"}] | Invoice history, newest first; each row downloads with a spinner-to-check state. |
payment | UsageBillingPayment | nullDefault: {"brand":"Visa","last4":"4242","expires":"08/27"} | Payment card summary under the plan perks; null hides the line. |
currency | stringDefault: "EUR" | ISO 4217 currency code for every amount in the block. |
upgradeAction | string— | Registered host action requested when the upgrade is confirmed. |
downloadInvoiceAction | string— | Registered host action requested when an invoice download starts. |
locale | string— | BCP 47 locale for currency and date formatting. Omitted inherits the application locale, else en-US. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes preserve interaction behavior. |
theme | UsageBillingThemeDefault: {} | Color mode, accent, and typed semantic token overrides. |
motion | none | subtle | expressiveDefault: "subtle" | Animation preset. System reduced-motion preferences take precedence. |
motionOptions | UsageBillingMotionOptionsDefault: {} | Chart draw, alert glide, meter follow and swap timing overrides in milliseconds. |
dir | ltr | rtl— | Reading direction; inherited from the page when omitted. |
UsageBillingPeriodaccepts{ label, start, days, today }, wherestartisYYYY-MM-DDandtoday <= days(daily.lengthmust equalperiod.today).UsageBillingMeteraccepts{ id, name, unit, used }, whereunitis'requests' | 'gigabytes' | 'minutes' | 'invocations' | 'seats'; each meter reads its cap fromplan.limits[meter.id].UsageBillingPlanaccepts{ id, name, price, limits, perks }. Whenupgradeis non-null,upgrade.idmust differ fromplan.id.UsageBillingSpendAlertaccepts{ id, amount, email, slack }(up to5, unique IDs).UsageBillingInvoiceaccepts{ id, number, period, issued, amount, status }, wherestatusis'paid' | 'refunded' | 'failed'(up to24, unique IDs).UsageBillingPaymentaccepts{ brand, last4, expires }ornull.
React integration
| Prop | Purpose |
|---|---|
onAlertsChange(alerts) | Called with the sorted SpendAlert[] whenever an alert is added, edited, toggled, or removed. |
onUpgrade(planId) | Called when the user confirms the upgrade in the modal sheet. Return a Promise to keep the sheet loading until settlement or display an error on rejection. |
onDownloadInvoice(invoiceId) | Called when an invoice download starts. Return a Promise to drive loading, done, and retry states. |
onAction(action, itemId?) | Called with upgradeAction (plus offer plan ID) or downloadInvoiceAction (plus invoice ID). |
portalContainer | Portal target forwarded to the upgrade confirmation ModalLayer. |
preset | Application defaults overridden by explicit instance arguments. |
tokens | CSS variables applied after the typed theme, forwarded to the root card, nested buttons, and portalled upgrade sheet. |
ref, className, style | Applied to the root <section> element. |
| Native attributes | id, aria-*, data-*, and remaining <section> props forwarded to the root element. |
Keyboard & accessibility
| Key | Action |
|---|---|
ArrowLeft / ArrowRight | On the focused spend chart, steps the day cursor backward or forward across elapsed days. |
Home / End | Jumps the chart cursor to the first or latest elapsed day. |
Escape | Clears the chart cursor, or closes the upgrade modal sheet (blocked while an upgrade is in flight). |
Enter (in alert input) | Commits the integer amount and blurs to re-sort alert rules. |
Tab | Moves across chart, table toggle, alert inputs and channel buttons, invoice downloads, and upgrade trigger (trapped inside the modal when open). |
- The spend chart wraps a
ChartFramewith an accessible data-table toggle (Show daily values) and live announcements reading the focused day's spend and cumulative total. - Each meter bar exposes
role="meter"witharia-valuemin,aria-valuemax,aria-valuenow, andaria-valuetext, plus visually hidden status text and warning icons so status never relies on color alone. - Every invoice download button carries a unique
aria-labelnaming the invoice number and current state (Download, Downloaded, or Retry). - The numeric chart frame stays
dir="ltr"while surrounding copy, meter fills (transform-originflipped), alert controls, and modal layout mirror cleanly in RTL (dir="rtl"). - Container queries below
480pxstretch the plan action full width and align wrapped invoice amounts and alert channel toggles cleanly.
Motion & theming
The cumulative spend curve traces in via ChartFrame, alert threshold hairlines glide vertically (alertDuration, 400ms default), alert rows reflow smoothly when re-sorted, meter fills scale via GPU-only transform: scaleX(...) (meterDuration, 400ms default), and the upgrade sheet enters and exits via ModalLayer.
Under prefers-reduced-motion: reduce, chart draw-in, alert reflow, and meter/alert glides turn off while keeping crisp state updates. Setting motion="none" makes every transition immediate (0ms), stops loading spinner rotation, and skips simulated download delays.
theme accepts mode, accent, and typed tokens across these groups:
| Token group | CSS custom properties |
|---|---|
core | --ui-surface, --ui-surface-raised, --ui-text, --ui-text-secondary, --ui-muted, --ui-border, --ui-highlight, --ui-accent, --ui-accent-foreground, --ui-danger, --ui-focus-ring, --ui-radius, --ui-border-width, --ui-shadow, --ui-disabled-opacity, --ui-font, --ui-font-size, --ui-font-weight |
extended | --ui-surface-sunken, --ui-border-strong, --ui-border-subtle, --ui-track, --ui-info, --ui-success, --ui-warning, --ui-tone-foreground, --ui-overlay, --ui-tint-strength |
shape | --ui-radius-sm, --ui-popup-radius, --ui-surface-radius |
accentTones | --ui-accent-strong, --ui-accent-subtle |
control | --ui-control-height, --ui-control-padding-x, --ui-control-gap, --ui-icon-size |
chart | --ui-series-1..--ui-series-8, --ui-series-other, --ui-sequential-1..7, --ui-diverging-1..7 |
include | --ui-shadow-resting, --ui-font-mono |
An application-wide UtherealProvider supplies defaults.
Composition
In an agent composition, UsageBilling is a leaf block. Ensure daily.length === period.today, pass upgrade: null when no higher tier exists, and wire upgradeAction and downloadInvoiceAction only to registered host actions. See Building with agents.
{
"type": "UsageBilling",
"props": {
"budget": 900,
"currency": "USD",
"upgradeAction": "upgrade_usage_plan",
"downloadInvoiceAction": "download_usage_invoice"
},
"children": []
}