Skip to main content

From events to invoice

Usage-based (metered) billing rates real consumption at period close. The moving parts:
  1. A billable metric — a named aggregation (count, sum, max, unique) over raw usage events. Its code doubles as the event dimension.
  2. A usage charge on a plan that prices that metric (per-unit or tiered).
  3. Usage events you record as consumption happens, each optionally carrying a transaction_id for idempotency.
  4. A rating read — windowed usage buckets, or the live current-period amount.
Rate units differ from flat prices. A per-unit or tier unit_amount is a decimal string in major currency units (e.g. "0.0035" = $0.0035 per unit). Flat plan prices and package amounts stay as integer minor units.
1

Construct a client

2

Create a billable metric

The code is the dimension your events will report against and is immutable after creation. field_name is required only for the unique aggregation (the event property whose distinct values are counted) and forbidden otherwise.
3

Set usage charges on a plan

Charges use PUT replace semantics: the list you send becomes the plan’s complete usage-charge set (charges absent from it are removed). Flat plan prices are untouched — a plan with both is hybrid (flat fee in advance, usage in arrears on the same renewal invoice). Reference the metric by its id.A per-unit charge prices every unit at one rate:
A tiered (graduated) charge prices bands separately; the final tier is unbounded (up_to: null):
The ChargeAmounts model was missing from an earlier generated build of the Python client; it’s now present, so set_plan_charges works in all three SDKs. Install a Python build that includes it (from a current checkout of the repo).
4

Record usage events

Record consumption as it happens against the subscription and its dimension. Pass a transaction_id to make ingestion idempotent: a retried event with the same (subscription, transaction_id) collapses to the original instead of double-counting.
5

Query windowed usage

Aggregate events into time buckets over a window. At least one of subscription_id or customer_id is required; the window defaults to the last 30 days at day granularity.
6

Get the current usage amount

Rating preview: what the current period’s metered usage would bill to if invoiced now, per charge, with a total_amount in minor units.
recurso.subscriptions.usage(id) (Node) / client.Subscriptions.Usage(ctx, id) (Go) / get_subscription_usage.sync(...) (Python recurso.api.usage) is the sibling read: raw current-period quantities per dimension plus lifetime totals and entitlement limits, without rating them to money.