Skip to navigation

Credit balances and ledger

A customer’s credit balance says how many credits they have left in a credit currency. The credit ledger is the history behind it: every grant, spend, expiry, void, refill and overage, each with the balance after it. Use the balance to show your customer what’s left, and the ledger to explain how it got there. The ledger is append-only, so its entries always add up to the balance.

Use balances and the ledger to:

  • Show what’s left in your product, with a customer’s credit balance.
  • Find customers about to run out, across your whole account, with the available[lte] and percentAvailable[lte] filters.
  • Explain a balance to your customer, entry by entry, with credit transactions.
  • Reconcile credits against the grants, events and orders behind them.

How balances and the ledger fit together

  1. Every change is a ledger entry. A grant adds credits, a spend or an expiry takes them away, and each entry records the balance after it.
  2. The balance is computed from the entries, per customer and credit currency: available is granted minus used minus held.
  3. Holds and overage sit beside the ledger. A credit hold reserves credits without writing an entry, and overage is billed in money rather than taken from the balance.

Credit amounts are in the credit currency, as exact decimal strings with up to 15 decimal places. A balance doesn’t stay a whole number once a fractional spend arrives, so don’t assume balances are integers.

Credit balances

Brightrail’s app shows each user how many Adatum credits their company has left:

List credit balances for a customer and credit currency. A balance has no ID of its own, so the list is how you read one. These endpoints are in the credits=v1 beta; send Paid-Beta: credits=v1.

?customer=cus_3Vb9Rk
&creditCurrency=adatum_credits
FieldMeaning
grantedCredits granted on grants in effect.
usedCredits spent from those grants.
heldCredits reserved by active credit holds: not spent, but not spendable either.
availableCredits left to spend or hold: granted - used - held. Never negative.
percentAvailableavailable ÷ granted × 100. "0" when nothing has been granted, and null for unlimited grants.
pendingUsage held for a first grant, when the credit currency’s unfundedUsage is pending.
overageCredits spent past the balance and not yet invoiced, billed in money at the credit currency’s conversion.
nextExpiryThe next credits to be forfeited, and when. Rollover counts; refills don’t.
asOfWhen the balance was calculated.

In the response, available is 1,200 - 200.25 - 0 = 999.75, and percentAvailable is 999.75 ÷ 1,200 × 100 = 83.3125.

Find customers running low

Leave out customer to list balances across your account. available[lte] and percentAvailable[lte] keep only the balances at or below a value, sorted by percentAvailable, lowest first:

GET /v1/credit-balances
?creditCurrency=adatum_credits
&percentAvailable[lte]=10

Customers with unlimited grants are left out, because their percentAvailable is null. To top up low balances automatically, use auto top-ups.

Child customers’ balances

With customer, set includeChildren=true to also list the balances of that customer’s child customers, one row each. Trey Research reads Northwind Traders’ balances together with those of its subsidiaries, such as Northwind UK Ltd:

GET /v1/credit-balances
?customer=cus_8HqL2xT
&includeChildren=true

Rows aren’t summed: each child keeps its own balance, and a child never spends its parent’s credits. includeChildren needs customer.

Seat balances

With holder=seat, the list returns each seat’s own balance instead of the shared ones, with seat and customerUnit set. A seat’s usage spends its own balance first, then the shared balance.

Credit transactions

Each change to a balance is a credit transaction: one entry in the ledger. List credit transactions to read them, newest first:

GET /v1/credit-transactions
?customer=cus_3Vb9Rk
&creditCurrency=adatum_credits
&occurredAt[gte]=2026-12-02T00:00:00Z
&occurredAt[lt]=2026-12-03T00:00:00Z
typeWritten when
grantCredits are granted.
spendUsage spends credits. A spend that draws on several grants writes one entry per grant, all with the same event.
expiryUnspent credits expire, including when rollover runs out.
voidA grant is voided, or a seat is freed, and its credits are forfeited.
refillA refilling grant resets, restoring what was spent in the window that ended.
overageUsage spends past the balance.
pendingUsage arrives before the first grant, and is held for it. The spend and overage entries that settle it when the first grant arrives name it in pendingEntry.

Each entry has a signed amount, the balanceAfter it, occurredAt (when the usage or grant happened) and createdAt (when it was recorded). It links to what caused it: the grant, event, meter, product, order or seat. Filter by type, grant, event, order, product, meter or an occurredAt range to trace a balance back to the usage behind it. reason carries a manual grant’s reason.

How it reconciles

Brightrail starts a trial with a 1,000-credit grant that expires on 1 January 2027, and gets 200 goodwill credits that never expire. Adatum charges 4 credits a minute. Here’s its first day of the ledger, oldest first:

TimetypeamountbalanceAfterWhy
09:00grant10001000Trial grant
11:15spend-12088030 minutes × 4
14:20spend-0.5879.50.125 minutes × 4
16:10grant2001079.5Goodwill
17:45spend-79.75999.7519.9375 minutes × 4

The grant, spend, expiry, void and refill entries always sum to the balance before holds, available + held: 1,000 - 120 - 0.5 + 200 - 79.75 = 999.75. All three spends came from the trial grant, because it’s forfeited first, so nextExpiry is 1,000 - 200.25 = 799.75 credits on 1 January.

The next day, one event costs 1,019.75 credits, 254.9375 minutes × 4. The balance covers 999.75 of it:

typeCreditsbalanceAfterFrom
spend799.75200the trial grant, forfeited first
spend2000the goodwill grant
overage1,019.75 - 999.75 = 200past the balance

The balance now shows available of 0 and overage of 20. At the credit currency’s 75¢ conversion, the overage is billed as 20 × 75¢ = 1,500¢, or $15.00. Overage entries are left out of the balance sum: those not yet invoiced add up to the balance’s overage.

Correct a balance

Ledger entries can’t be changed or deleted. To add credits, create a grant. To take them away, void the grant that holds them, which writes a void entry, and grant the right amount again if needed.