Skip to navigation

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

  1. 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.
  2. While the hold is active, its credits count as held on the balance and aren’t available to anything else.
  3. 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.
  4. 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:

{
"customer": "cus_8HqL2xT",
"creditCurrency": "support_credits",
"amount": "150",
"correlationId": "ticket_4410",
"expiresAfter": { "value": "30", "unit": "minute" }
}

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.

FieldWhat it’s for
amountThe credits to reserve: the most the work could cost, in the credit currency, up to 15 decimal places.
expiresAfterHow long the hold lasts if it isn’t settled or released, in minute or hour. 15 minutes by default, from 1 minute to 24 hours. The response gives expiresAt.
productLets grants scoped to this product count towards the hold. Without it, only unscoped grants count.
seatReserves from that seat’s balance first, then the shared balance.
correlationIdYour ID for the run, ticket or message, for finding the hold later. It isn’t used to settle the hold.

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:

POST /v1/events
{
"eventName": "ticket.resolved",
"customer": "cus_8HqL2xT",
"product": "support_agent",
"dedupeKey": "ticket_4410",
"correlationId": "ticket_4410",
"creditHold": "hold_2Nf8Qp",
"payload": { "channel": "email" }
}

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.

If the event costsThen
less than the holdthe rest of the hold is freed.
more than the holdthe extra is still spent from what’s left, and can reach overage.
nothing in this credit currencythe hold is settled with no spend.

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:

Stepheldavailable
Start0400
Hold for ticket 4410: 150150400 - 150 = 250
Hold for ticket 4411: 150150 + 150 = 300250 - 150 = 100
Hold for ticket 4412: 150fails with insufficient_credits, because 100 < 150. Litware hands the ticket to a person.100
Ticket 4410 resolved: its event spends 150 and settles its hold300 - 150 = 150400 - 150 spent - 150 held = 100
Ticket 4411 escalated: Litware releases its hold150 - 150 = 0400 - 150 spent = 250

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.