Usage meters
GET /v1/customers/{customer_id}/usage_summary returns what a usage meter in your product needs in one call: every window that applies to the customer, the balance pools, the next credits to expire, this period’s spend and the spend limits in force.
Before you start
- A customer with a subscription. The summary shows every usage window, pool and spend limit that applies. A plan with none still returns one window and one pool.
- A key with the
usage:readscope.
It reads from the ledger, so it works for every customer. A customer on a plan with no allowances gets one window for the plan period and one pool.
Read it
windowshas one entry for each allowance.grantedis the credits granted in the window, or the cap for acap.percent_usedisusedovergrantedas a decimal from 0 to 1, so"0.62"is 62%.heldis active holds, counted inremainingand not inpercent_used.binding_windowis the key of the window with the least room left. Draw that one as the headline meter, because it is the one that will stop the customer first.poolsis the balance split by pool, with the next credits in each pool to expire.spendis the money value of this period’s consumption.basisiscost_basisfor prepaid plans, where credits are valued at the cost basis of the grants they came from, andchargesfor postpaid plans, where it is the total of the lines on the period’s draft invoice so far: the recurring fee is in it, and a pending outcome charge isn’t until it confirms.spend_limitslists the spend limits that apply, each with what has been spent against it.
A postpaid plan has no credits. Its windows hold one entry for each usage rate with an included_quantity, with kind: included, and its pools are empty.
Parameters
Don’t decide with it
Use the summary to draw meters, not to decide whether work may start. Summaries and lists can lag by a few seconds. check() is the authority, and it serializes against the same ledger, so it never allows work the summary would show as over.
To show customers the same meters without building them, send them to the customer view.
When it fails
Idempotency and errors lists every code.
API reference
Next steps
- Customer view shows the same meters without building them.
- Spend limits and usage windows define what the meters show.