Credit holds
Spending credits never blocks: once a balance is empty, further usage becomes overage. When you’d rather stop at zero, place a credit hold before the work runs. A hold reserves credits on your customer’s balance, fails if the balance can’t cover it, and is settled by the usage event for that work. It works like a card authorisation: check and reserve first, then charge what the work actually cost.
Use a credit hold to:
- Stop work your customer can’t pay for, by refusing it when the hold fails with
insufficient_credits. - Run work concurrently without overspending, because two holds can never claim the same credits.
- Charge what the work actually cost, not your estimate, by settling the hold with the usage event.
How a hold works
- Before the work runs, your code places a hold for the most the work could cost. Paid checks the balance and reserves the credits in one step, or fails and reserves nothing.
- While the hold is active, its credits count as
heldon the balance and aren’t available to anything else. - When the work is done, you send its usage event naming the hold. The event’s actual cost is spent, and the rest of the reservation is freed.
- If the work doesn’t run, you release the hold, or it expires on its own.
A hold writes nothing to the ledger, because nothing has been spent. Only the event’s spend does.
Holds are placed by your code as work starts, so there are no dashboard steps for them.
Place a hold
Litware’s support agent charges 150 credits per resolved ticket. Before it starts on a ticket for Northwind Traders, it reserves the cost of one resolution. These endpoints are in the credits=v1 beta; send Paid-Beta: credits=v1. Create a credit hold with an Idempotency-Key, so a retry never reserves twice:
Paid checks the balance and reserves the credits in one atomic step, so two concurrent holds can never both claim the same credits. If the available balance can’t cover amount, the request fails with insufficient_credits and nothing is reserved: don’t run the work.
A hold can reserve only what’s available: credits left on the grants that count, less every other active hold. Overage never counts towards a hold, so a hold that would need overage fails, even when the credit currency’s conversion would bill it. Before a customer’s first grant, nothing is available and every hold fails.
Settle it with the event
When the work is done, name the hold in creditHold on the usage event for it:
The event captures the hold as soon as it’s accepted: its status becomes captured, with capturedBy set to the event’s evt_ ID, so it can no longer expire or be released. Its credits stay reserved until the event’s actual cost is spent in the usual spend order, and whatever’s left of the reservation is freed in that same step. There’s no separate capture call.
An event names at most one hold, and a hold is settled by one event. An event naming a hold that has already expired, been released or been captured is still accepted and its usage recorded, with a resource_not_active warning on creditHold, so a timing race never loses usage. Its spend posts as if it named no hold. A duplicate event, with the same dedupeKey, settles nothing again. A creditHold that doesn’t exist, or belongs to another customer or credit currency, fails the event with a 400.
Release or let it expire
- If the work doesn’t run, release the hold to free its credits straight away. Releasing a hold that isn’t active fails with
status_conflict. - A hold that’s neither captured nor released expires at
expiresAt, and its credits are free from that moment.
List credit holds by customer, creditCurrency, seat, status or correlationId to find the holds for a run.
How it bills
Northwind has 400 support_credits available when three tickets arrive at once:
Only the resolved ticket spent credits, and nothing went into overage, so nothing is invoiced in money. The ledger shows a single spend entry of -150.
Change a hold
A hold’s amount, customer and credit currency can’t change once credits are reserved against them. To change the amount, release the hold and place a new one.