Usage forecast
Billing-period usage projection with a weekday-aware confidence cone, a draggable horizontal budget handle that dates the crossing live, interactive day scrubbing, and toggleable alert-threshold chips.
import { UsageForecast } from '@uthereal/ui/usage-forecast'Usage forecast playground
Usage forecast
Scale plan · Renews day 1
At this pace you reach the budget on day 26
4 days before the period closes, likely between day 25 and day 28.
API calls: At this pace you reach the budget on day 26. 4 days before the period closes, likely between day 25 and day 28.
- Used so far
- 33.1M calls
- 33.1 M calls, 87% of budget
- Projected by day 30
- 44.156M calls
- 44.156 M calls, likely 40.803 to 48.888 M calls
- Cost above budget
- $1,231
- $1,231, $1,231 above budget
| Day | Reading | Likely range |
|---|---|---|
| Day 1 | 1.8 | Measured |
| Day 2 | 3.5 | Measured |
| Day 3 | 5.2 | Measured |
| Day 4 | 6.9 | Measured |
| Day 5 | 8.6 | Measured |
| Day 6 | 9.4 | Measured |
| Day 7 | 10.2 | Measured |
| Day 8 | 12 | Measured |
| Day 9 | 13.7 | Measured |
| Day 10 | 15.4 | Measured |
| Day 11 | 17.1 | Measured |
| Day 12 | 18.8 | Measured |
| Day 13 | 19.6 | Measured |
| Day 14 | 20.4 | Measured |
| Day 15 | 22.2 | Measured |
| Day 16 | 24.1 | Measured |
| Day 17 | 26 | Measured |
| Day 18 | 27.9 | Measured |
| Day 19 | 29.7 | Measured |
| Day 20 | 30.5 | Measured |
| Day 21 | 31.3 | Measured |
| Day 22 | 33.1 | Measured |
| Day 23 (forecast) | 34.657 | 33.853 to 35.792 |
| Day 24 (forecast) | 36.214 | 34.955 to 37.992 |
| Day 25 (forecast) | 37.771 | 36.114 to 40.111 |
| Day 26 (forecast) | 39.329 | 37.304 to 42.187 |
| Day 27 (forecast) | 40.185 | 37.811 to 43.537 |
| Day 28 (forecast) | 41.041 | 38.332 to 44.867 |
| Day 29 (forecast) | 42.599 | 39.564 to 46.883 |
| Day 30 (forecast) | 44.156 | 40.803 to 48.888 |
Overview
UsageForecast warns customers before they cross a billing-period budget. Supply cumulative daily readings through today, and the block computes a deterministic weekday-aware median forecast with an expanding likely-range confidence cone, a one-sentence headline summarizing whether and when usage crosses the budget, and KPI readouts for Used so far, Projected by day N, and Cost above budget.
Readers drag the horizontal Budget line directly up or down (or adjust it with the keyboard) to see the over-budget danger clip, crossing date pill, projected overage cost, and alert-threshold dates recalculate live. Scrubbing horizontally across the plot displays a vertical crosshair, forecast range bar, and floating day readout panel.
Use UsageForecast on billing and usage pages where customers need early warning and what-if budget modeling. For a full metered dashboard with multiple resource bars, alerts editor, invoices, and plan upgrades, use Usage billing. For seat-based subscription settings, use Billing overview.
Usage
'use client'
import { useState } from 'react'
import { UsageForecast } from '@uthereal/ui/usage-forecast'
export function ApiQuotaForecast({
readings,
initialBudget,
}: {
readings: number[]
initialBudget: number
}) {
const [budget, setBudget] = useState(initialBudget)
return (
<UsageForecast
title="Usage forecast"
subtitle="Scale plan · Renews day 1"
metricLabel="API calls"
unit="M calls"
currency="USD"
days={30}
readings={readings}
budget={budget}
minBudget={10}
maxBudget={60}
budgetStep={1}
overageRate={200}
onBudgetChange={(next) => {
setBudget(next)
void fetch('/api/billing/budget', {
method: 'PUT',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ budget: next }),
})
}}
onAlertToggle={(index, pressed) => {
void fetch('/api/billing/alert-rules', {
method: 'PATCH',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ index, enabled: pressed }),
})
}}
/>
)
}Omit budget to run uncontrolled from defaultBudget. Because the forecast math is pure and deterministic with no randomness or clock reads, server-rendered HTML and hydrated client geometry always match.
Examples
Within-budget healthy trajectory
When steady usage projects below the budget line through day 30, the crossing marker and danger clip clear completely, the headline reads "At this pace you stay under budget", Cost above budget rests at $0 (Within budget), and the 100% alert chip reports Not expected.
Usage forecast
Growth plan · Renews day 1
At this pace you stay under budget
Heading for 22.614 M calls by day 30, 63% of budget.
API calls: At this pace you stay under budget. Heading for 22.614 M calls by day 30, 63% of budget.
- Used so far
- 14.6M calls
- 14.6 M calls, 41% of budget
- Projected by day 30
- 22.614M calls
- 22.614 M calls, likely 20.311 to 25.866 M calls
- Cost above budget
- $0
- $0, Within budget
| Day | Reading | Likely range |
|---|---|---|
| Day 1 | 0.9 | Measured |
| Day 2 | 1.8 | Measured |
| Day 3 | 2.7 | Measured |
| Day 4 | 3.6 | Measured |
| Day 5 | 4.5 | Measured |
| Day 6 | 5 | Measured |
| Day 7 | 5.5 | Measured |
| Day 8 | 6.4 | Measured |
| Day 9 | 7.3 | Measured |
| Day 10 | 8.2 | Measured |
| Day 11 | 9.1 | Measured |
| Day 12 | 10 | Measured |
| Day 13 | 10.5 | Measured |
| Day 14 | 11 | Measured |
| Day 15 | 11.9 | Measured |
| Day 16 | 12.8 | Measured |
| Day 17 | 13.7 | Measured |
| Day 18 | 14.6 | Measured |
| Day 19 (forecast) | 15.386 | 14.98 to 15.959 |
| Day 20 (forecast) | 15.818 | 15.182 to 16.715 |
| Day 21 (forecast) | 16.25 | 15.414 to 17.43 |
| Day 22 (forecast) | 17.036 | 16.014 to 18.478 |
| Day 23 (forecast) | 17.821 | 16.623 to 19.513 |
| Day 24 (forecast) | 18.607 | 17.24 to 20.537 |
| Day 25 (forecast) | 19.393 | 17.861 to 21.555 |
| Day 26 (forecast) | 20.179 | 18.487 to 22.567 |
| Day 27 (forecast) | 20.611 | 18.762 to 23.22 |
| Day 28 (forecast) | 21.043 | 19.041 to 23.87 |
| Day 29 (forecast) | 21.829 | 19.675 to 24.869 |
| Day 30 (forecast) | 22.614 | 20.311 to 25.866 |
Unpriced capacity forecast already past budget
Set overageRate={0} to hide the third Cost above budget KPI cell and render a two-column capacity bar (such as compute hours or build minutes). When actual readings already crossed the budget before today, the headline dates the historical crossing and tints the exceeded portion of the solid actual curve in danger.
CI build capacity
Team pool · Renews day 1
You passed the budget on day 17
Usage is 27% over today and heading for 120.46 k min by day 30.
Build minutes: You passed the budget on day 17. Usage is 27% over today and heading for 120.46 k min by day 30.
- Used so far
- 82.4k min
- 82.4 k min, 127% of budget
- Projected by day 30
- 120.46k min
- 120.46 k min, likely 109.247 to 136.29 k min
| Day | Reading | Likely range |
|---|---|---|
| Day 1 | 4.2 | Measured |
| Day 2 | 8.6 | Measured |
| Day 3 | 13.1 | Measured |
| Day 4 | 17.4 | Measured |
| Day 5 | 21.8 | Measured |
| Day 6 | 24 | Measured |
| Day 7 | 26.2 | Measured |
| Day 8 | 30.8 | Measured |
| Day 9 | 35.4 | Measured |
| Day 10 | 40.1 | Measured |
| Day 11 | 44.7 | Measured |
| Day 12 | 49.2 | Measured |
| Day 13 | 51.6 | Measured |
| Day 14 | 54 | Measured |
| Day 15 | 58.8 | Measured |
| Day 16 | 63.6 | Measured |
| Day 17 | 68.4 | Measured |
| Day 18 | 73.1 | Measured |
| Day 19 | 77.8 | Measured |
| Day 20 | 82.4 | Measured |
| Day 21 (forecast) | 84.82 | 82.548 to 88.028 |
| Day 22 (forecast) | 89.22 | 85.662 to 94.243 |
| Day 23 (forecast) | 93.62 | 88.938 to 100.23 |
| Day 24 (forecast) | 98.02 | 92.298 to 106.098 |
| Day 25 (forecast) | 102.42 | 95.711 to 111.891 |
| Day 26 (forecast) | 106.82 | 99.163 to 117.63 |
| Day 27 (forecast) | 109.24 | 100.664 to 121.348 |
| Day 28 (forecast) | 111.66 | 102.187 to 125.033 |
| Day 29 (forecast) | 116.06 | 105.71 to 130.672 |
| Day 30 (forecast) | 120.46 | 109.247 to 136.29 |
Forecast model, budget handle, and alerts
Narrative states
| Crossing condition | Headline | Visual treatment |
|---|---|---|
Never crosses (crossingDay === null) | At this pace you stay under budget | Entire curve and confidence cone stay in --ui-series-1; crossing marker and date pill hide. |
Crosses in the future (crossingDay > today) | At this pace you reach the budget on day N | Portion above the budget clips to --ui-danger; dashed drop line, marker ring, and Day N pill pin the crossing. |
Crossed on or before today (crossingDay <= today) | You passed the budget on day N | Both actual and forecast segments above the budget tint --ui-danger; detail reports current percent over budget. |
Forecast and alert calculations
- Weekday-aware projection: Computes the trailing seven-day average pace from
readings, weights days 6 and 7 of each 7-day cycle at0.55×, and widens the upper/lower likely range with the square root and linear count of forecast days. - Budget handle: Snaps vertical pointer drags and keyboard steps to
budgetStep, clamped betweenminBudgetandmaxBudget. The strip setstouch-action: noneso touch drags move the budget without scrolling the page, while the day scrubber usestouch-action: pan-y. - Alert chips: Each entry in
defaultAlertRules(fraction ofbudget, default[0.5, 0.8, 1]) computes when the curve hitsbudget × fraction(Reached day N, Expected day N, or Not expected) and toggles its labeled tick directly on the chart curve.
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
title | stringDefault: "Usage forecast" | Heading naming the forecast |
metricLabel | stringDefault: "API calls" | What the readings measure; names the chart and the budget |
subtitle | stringDefault: "Scale plan · Renews day 1" | Context line under the heading |
unit | stringDefault: "M calls" | Unit shown beside every value |
currency | stringDefault: "USD" | ISO 4217 currency for the cost-above-budget figure |
days | integerDefault: 30 | Length of the billing period in days |
readings | number[]Default: [0,1.8,3.5,5.2,6.9,8.6,9.4,10.2,12,13.7,15.4,17.1,18.8,19.6,20.4,22.2,24.1,26,27.9,29.7,30.5,31.3,33.1] | Running daily readings from day 1 through today; the forecast continues from the last one |
defaultBudget | numberDefault: 38 | Initial budget line |
minBudget | numberDefault: 10 | Lowest budget the handle reaches |
maxBudget | numberDefault: 50 | Highest budget the handle reaches |
budgetStep | numberDefault: 1 | Budget keyboard and snap step |
overageRate | numberDefault: 200 | Cost charged per unit above budget, in the currency; 0 hides pricing |
defaultAlertRules | number[]Default: [0.5,0.8,1] | Alert rule fractions of the budget, as toggleable chips; every rule but the first is on by default |
valueFormat | NumberFormatDefault: {"style":"decimal"} | Number format for readings and budget |
locale | string— | Number locale; inherited from the application when omitted |
recipe | studio | softDefault: "studio" | Visual treatment; behavior is identical |
motion | none | subtle | expressiveDefault: "subtle" | Arc motion; reduced motion wins |
motionOptions | UsageForecastMotionOptions— | Chart morph overrides; durations are milliseconds |
dir | ltr | rtl— | Reading direction; omitted inherits |
theme | UsageForecastTheme— | Color mode, accent and typed token overrides |
readingsis an array of cumulative daily totals (2todays + 1entries; index0is period start, last index is today).defaultAlertRulesaccepts1to6fractions between0.05and4(every rule except the first starts pressed).valueFormataccepts aNumberFormatobject ({ style?, currency?, minimumFractionDigits?, maximumFractionDigits?, useGrouping? }).
React integration
| Prop | Purpose |
|---|---|
budget | Controlled budget value (clamped to [minBudget, maxBudget]). Leave undefined to run uncontrolled from defaultBudget. |
onBudgetChange(budget) | Called on every snapped drag or keyboard change to the budget line, in both controlled and uncontrolled modes. |
onAlertToggle(index, pressed) | Called when an alert-threshold chip is toggled on or off. |
onAction(action, itemId?) | Accepted for host parity; this block registers no host actions. |
preset | Application defaults overridden by explicit instance arguments. |
tokens | CSS variables applied after the typed theme, applied to the root card. |
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 / ArrowUp / ArrowDown | On the day scrubber, steps one day; on the budget handle, adjusts the budget by one budgetStep. |
PageUp / PageDown | Jumps 7 days on the day scrubber, or 5 × budgetStep on the budget handle. |
Home / End | Jumps to day 1 / days on the scrubber, or minBudget / maxBudget on the budget handle. |
Escape | Clears the inspected day on the day scrubber. |
Enter / Space | Toggles focused alert-threshold chips (aria-pressed). |
- Both the day scrubber and the horizontal budget handle expose
role="slider"witharia-orientation,aria-valuemin,aria-valuemax,aria-valuenow, and plain-languagearia-valuetext. - The
<svg>plot carries a full-sentencearia-labelandaria-describedbypointing to a visually hidden<table>listing every measured and forecast day with its likely range. - A polite
role="status"live region announces headline and detail changes as the budget moves, and everyOdometerNumberpairs hidden full text witharia-hidden="true"digit wheels. - The chart coordinate surface stays
dir="ltr"while the header, story, KPI grid, alert chips, and legend mirror cleanly in RTL (dir="rtl"). - Container queries tighten padding and KPI typography below
560px, and stack KPIs into horizontal rows with full-width alert chips below440px.
Motion & theming
The budget line and handle follow pointer drags directly (0ms lag) and settle on the snappy spring on keyboard steps and release; the crossing marker glides along the forecast curve while OdometerNumber and MorphText transition KPI figures, headline wording, and chip status labels.
Under prefers-reduced-motion: reduce, springs and morph transitions jump immediately while color and control transitions drop to 120ms opacity/color fades. Setting motion="none" makes every motion value and CSS transition immediate (0ms).
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 |
chart | --ui-series-1..--ui-series-8, --ui-series-other, --ui-sequential-1..7, --ui-diverging-1..7 |
include | --ui-surface-radius, --ui-popup-radius, --ui-shadow-raised, --ui-shadow-resting, --ui-font-display |
component | --ui-usage-forecast-gutter (52px), --ui-usage-forecast-pad-top (30px), --ui-usage-forecast-pad-bottom (30px), --ui-usage-forecast-pad-inline-end (10px), --ui-usage-forecast-panel-width (176px) |
An application-wide UtherealProvider supplies defaults.
Composition
In an agent composition, UsageForecast is a leaf block whose budget is persisted host state (onBudgetChange). Provide validated cumulative readings only; never supply derived crossing dates by hand. See Building with agents.
{
"type": "UsageForecast",
"props": {
"title": "Usage forecast",
"metricLabel": "API calls",
"subtitle": "Scale plan · Renews day 1",
"unit": "M calls",
"currency": "USD",
"days": 30,
"defaultBudget": 38,
"minBudget": 10,
"maxBudget": 50,
"overageRate": 200
},
"children": []
}