Skip to main content
Hooks for the “X of Y used” reading of a single metric, the daily usage trajectory a point-in-time meter can’t show, and how fast a credit wallet is being consumed. All three are scoped to the portal customer and read server-aggregated endpoints, so they stay correct at any event or ledger volume. Every hook returns isLoading: boolean and error: Error | null (see Introduction); the sections below list each hook’s specific returns.

useUsageMeter

Reads a single metric’s current-period usage against its entitlement limit — the live “X of Y used” reading that powers progress bars and quota warnings. It hits GET /v1/usage?metricId=… scoped to the portal customer. Parameters
string
required
The billable metric to meter. The query stays disabled until a non-empty metricId (and a customer) is present.
Returns
  • meter — the UsageMeter for this metric, or null while loading:
string
The metric identifier.
string
Human-readable metric name for display.
number
Units consumed this period.
number | null
The period allowance, or null when unlimited.
boolean
true when the plan grants unlimited usage of this metric.
number
Server-computed percent consumed (0100). 0 when unlimited.

useUsageHistory

Returns daily usage totals over a trailing window, one continuous series per event name. It reads the server-aggregated GET /v1/usage/aggregate endpoint (one row per UTC day × event, summed in Postgres) so it’s correct at any event volume — a customer with a million events returns the same ~30 rows as one with ten. The hook returns the raw series only; charting is the caller’s job. Parameters
number
default:"30"
Window length in trailing UTC days. The series is zero-filled across the whole window so charts render a continuous day axis even on quiet days.
Returns
  • seriesRecord<eventName, Array<{ date, total }>> — for each event name, a continuous daily series ordered oldest → today. Each point has date (UTC day, YYYY-MM-DD) and total (total quantity for that event on that day, 0 on days with no events). Day buckets are UTC-pinned on the server and the axis is built in UTC too, so they line up exactly.
  • hasDatatrue when the server returned at least one aggregate row in the window. Use it to switch between an empty state and a populated chart.

useCreditBurn

Reports how fast one credit wallet is being consumed over a trailing window. It reads the server-aggregated GET /v1/credits/stats endpoint scoped to a single credit currency — the daily consumed series is summed in Postgres from the append-only ledger, so it’s correct at any ledger volume. Parameters
string
required
The credit wallet (currency) to measure. The query stays disabled until this and a customer are present.
number
default:"30"
Window length in trailing UTC days. The series is zero-filled across the whole window.
Returns
  • seriesArray<{ date, consumed }> — zero-filled daily consumption ordered oldest → today. date is the UTC day (YYYY-MM-DD), consumed is credits consumed that day (0 on quiet days).
  • avgPerDaynumber — mean consumed per day over the window (windowSum / days, including zero days). The honest steady-state rate, not a cherry-picked active-day average.
  • windowSumnumber — total consumed across the window.
  • peaknumber — highest single-day consumption in the window.
  • daysnumber — the window length echoed back.
  • hasBurnbooleantrue when windowSum > 0. Use it to switch between an idle-wallet state and the burn chart.
Runway is intentionally left to the caller: divide the wallet balance you already show on the card by avgPerDay, so the number matches the displayed balance exactly. Read the balance from useCreditAccounts.

See also

Credits & wallets

Wallet balances and the ledger useCreditBurn aggregates.

Entitlements & gates

The entitlement limit useUsageMeter reads against.