UI

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
Budget38
Alert at
  • Actual
  • Forecast
  • Likely range
  • Over budget

Drag the budget line or use the arrow keys.

API calls, day 1 to 30
DayReadingLikely range
Day 11.8Measured
Day 23.5Measured
Day 35.2Measured
Day 46.9Measured
Day 58.6Measured
Day 69.4Measured
Day 710.2Measured
Day 812Measured
Day 913.7Measured
Day 1015.4Measured
Day 1117.1Measured
Day 1218.8Measured
Day 1319.6Measured
Day 1420.4Measured
Day 1522.2Measured
Day 1624.1Measured
Day 1726Measured
Day 1827.9Measured
Day 1929.7Measured
Day 2030.5Measured
Day 2131.3Measured
Day 2233.1Measured
Day 23 (forecast)34.65733.853 to 35.792
Day 24 (forecast)36.21434.955 to 37.992
Day 25 (forecast)37.77136.114 to 40.111
Day 26 (forecast)39.32937.304 to 42.187
Day 27 (forecast)40.18537.811 to 43.537
Day 28 (forecast)41.04138.332 to 44.867
Day 29 (forecast)42.59939.564 to 46.883
Day 30 (forecast)44.15640.803 to 48.888
Loading interactive preview…

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
Budget36
Alert at
  • Actual
  • Forecast
  • Likely range
  • Over budget

Drag the budget line or use the arrow keys.

API calls, day 1 to 30
DayReadingLikely range
Day 10.9Measured
Day 21.8Measured
Day 32.7Measured
Day 43.6Measured
Day 54.5Measured
Day 65Measured
Day 75.5Measured
Day 86.4Measured
Day 97.3Measured
Day 108.2Measured
Day 119.1Measured
Day 1210Measured
Day 1310.5Measured
Day 1411Measured
Day 1511.9Measured
Day 1612.8Measured
Day 1713.7Measured
Day 1814.6Measured
Day 19 (forecast)15.38614.98 to 15.959
Day 20 (forecast)15.81815.182 to 16.715
Day 21 (forecast)16.2515.414 to 17.43
Day 22 (forecast)17.03616.014 to 18.478
Day 23 (forecast)17.82116.623 to 19.513
Day 24 (forecast)18.60717.24 to 20.537
Day 25 (forecast)19.39317.861 to 21.555
Day 26 (forecast)20.17918.487 to 22.567
Day 27 (forecast)20.61118.762 to 23.22
Day 28 (forecast)21.04319.041 to 23.87
Day 29 (forecast)21.82919.675 to 24.869
Day 30 (forecast)22.61420.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
Budget65
Alert at
  • Actual
  • Forecast
  • Likely range
  • Over budget

Drag the budget line or use the arrow keys.

Build minutes, day 1 to 30
DayReadingLikely range
Day 14.2Measured
Day 28.6Measured
Day 313.1Measured
Day 417.4Measured
Day 521.8Measured
Day 624Measured
Day 726.2Measured
Day 830.8Measured
Day 935.4Measured
Day 1040.1Measured
Day 1144.7Measured
Day 1249.2Measured
Day 1351.6Measured
Day 1454Measured
Day 1558.8Measured
Day 1663.6Measured
Day 1768.4Measured
Day 1873.1Measured
Day 1977.8Measured
Day 2082.4Measured
Day 21 (forecast)84.8282.548 to 88.028
Day 22 (forecast)89.2285.662 to 94.243
Day 23 (forecast)93.6288.938 to 100.23
Day 24 (forecast)98.0292.298 to 106.098
Day 25 (forecast)102.4295.711 to 111.891
Day 26 (forecast)106.8299.163 to 117.63
Day 27 (forecast)109.24100.664 to 121.348
Day 28 (forecast)111.66102.187 to 125.033
Day 29 (forecast)116.06105.71 to 130.672
Day 30 (forecast)120.46109.247 to 136.29

Forecast model, budget handle, and alerts

Narrative states

Crossing conditionHeadlineVisual treatment
Never crosses (crossingDay === null)At this pace you stay under budgetEntire 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 NPortion 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 NBoth 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 at 0.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 between minBudget and maxBudget. The strip sets touch-action: none so touch drags move the budget without scrolling the page, while the day scrubber uses touch-action: pan-y.
  • Alert chips: Each entry in defaultAlertRules (fraction of budget, default [0.5, 0.8, 1]) computes when the curve hits budget × 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.

ArgumentType / defaultDescription
titlestringDefault: "Usage forecast"Heading naming the forecast
metricLabelstringDefault: "API calls"What the readings measure; names the chart and the budget
subtitlestringDefault: "Scale plan · Renews day 1"Context line under the heading
unitstringDefault: "M calls"Unit shown beside every value
currencystringDefault: "USD"ISO 4217 currency for the cost-above-budget figure
daysintegerDefault: 30Length of the billing period in days
readingsnumber[]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
defaultBudgetnumberDefault: 38Initial budget line
minBudgetnumberDefault: 10Lowest budget the handle reaches
maxBudgetnumberDefault: 50Highest budget the handle reaches
budgetStepnumberDefault: 1Budget keyboard and snap step
overageRatenumberDefault: 200Cost charged per unit above budget, in the currency; 0 hides pricing
defaultAlertRulesnumber[]Default: [0.5,0.8,1]Alert rule fractions of the budget, as toggleable chips; every rule but the first is on by default
valueFormatNumberFormatDefault: {"style":"decimal"}Number format for readings and budget
localestring—Number locale; inherited from the application when omitted
recipestudio | softDefault: "studio"Visual treatment; behavior is identical
motionnone | subtle | expressiveDefault: "subtle"Arc motion; reduced motion wins
motionOptionsUsageForecastMotionOptions—Chart morph overrides; durations are milliseconds
dirltr | rtl—Reading direction; omitted inherits
themeUsageForecastTheme—Color mode, accent and typed token overrides
  • readings is an array of cumulative daily totals (2 to days + 1 entries; index 0 is period start, last index is today).
  • defaultAlertRules accepts 1 to 6 fractions between 0.05 and 4 (every rule except the first starts pressed).
  • valueFormat accepts a NumberFormat object ({ style?, currency?, minimumFractionDigits?, maximumFractionDigits?, useGrouping? }).

React integration

PropPurpose
budgetControlled 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.
presetApplication defaults overridden by explicit instance arguments.
tokensCSS variables applied after the typed theme, applied to the root card.
ref, className, styleApplied to the root <section> element.
Native attributesid, aria-*, data-*, and remaining <section> props forwarded to the root element.

Keyboard & accessibility

KeyAction
ArrowLeft / ArrowRight / ArrowUp / ArrowDownOn the day scrubber, steps one day; on the budget handle, adjusts the budget by one budgetStep.
PageUp / PageDownJumps 7 days on the day scrubber, or 5 × budgetStep on the budget handle.
Home / EndJumps to day 1 / days on the scrubber, or minBudget / maxBudget on the budget handle.
EscapeClears the inspected day on the day scrubber.
Enter / SpaceToggles focused alert-threshold chips (aria-pressed).
  • Both the day scrubber and the horizontal budget handle expose role="slider" with aria-orientation, aria-valuemin, aria-valuemax, aria-valuenow, and plain-language aria-valuetext.
  • The <svg> plot carries a full-sentence aria-label and aria-describedby pointing 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 every OdometerNumber pairs hidden full text with aria-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 below 440px.

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 groupCSS 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": []
}

On this page