What you’ll build
This tutorial builds metered billing end to end for an API product that charges per API call. By the end you’ll have a plan with a base fee plus metered usage, a stream of recorded usage events, a windowed usage query for charts, and a per-subscription usage view your dashboard can show to customers. Everything here uses real endpoints. Follow along against a localmake demo stack (http://localhost:8080, key sk_test_12345) or substitute
https://api.recurso.dev and your own key.
Recurso stores and aggregates usage; the rating (turning quantity into a
charge) happens at invoice time from the plan’s tiers. Enforcing limits in real
time is your application’s job — see feature gating.
Step 1: Create a metered plan
A metered plan is three calls: the plan (flat base fee), a billable metric (the meter), and the charges that price the metric on the plan — the most common SaaS model: predictable revenue plus a usage upside.1
Create the base plan
2
Define the billable metric
The metric’s
code doubles as the usage event dimension it aggregates:3
Attach graduated charges to the plan
graduated tiers charge each tier’s rate across its own range; volume tiers
apply the final tier’s rate to all units. See
Usage-Based Billing for all four
models priced against the same month.subscription_id and customer_id; you need both to record usage.
Step 2: Record usage events
Report usage against the subscription’sdimension throughout the period. All
four fields are required, and the record call is ownership-checked: the
subscription must belong to your tenant and customer_id must match the
subscription’s customer.
{ "status": "recorded", "event_id": "..." }. The
event timestamp is set server-side at ingestion.
Step 3: Query windowed usage
GET /v1/usage aggregates events into day or month buckets over an
arbitrary window — this is the endpoint behind a usage chart. The window
defaults to the last 30 days.
recurso.usage.dimensions()
(GET /v1/usage/dimensions).
Step 4: Show customers their usage
GET /v1/subscriptions/{id}/usage answers “you’ve used 4,231 of 10,000 API
calls this month.” It returns each dimension’s current-period and lifetime
totals — and if you attach an entitlement limit whose feature_key equals
the dimension name, the limit and remaining headroom are joined in
automatically.
Node
Step 5: Bill on usage
You don’t call anything to invoice. At the end of each billing period Recurso aggregates the recorded events and rates them against the plan’s usage tiers, producing invoice line items automatically:
You’ll receive the
invoice.created webhook when the invoice is generated and
invoice.paid once it’s collected. See the end-to-end flow for
the full webhook sequence.
Next Steps
Usage-Based Billing
Full pricing-model reference and the metering + entitlements pattern
Feature Gating
Enforce plan limits and boolean features at request time
Record Usage Event API
Endpoint reference with ownership rules
Analytics
MRR and usage analytics