- Check reserves. Check with a
request_idandreserve. Allowed, it holds the amount so no other check or track can spend it, and returns areservation. Refused, it is a normal check’sallowed: falsewith areason, and nothing is held. - Run the work.
- Track settles. Track with the same
request_idand the real amount. It charges that and lets the rest of the hold go. If the work failed, release the reservation instead.
Reserve credits
video_render is a credits feature priced by the second of video, creditCost: 2. The check reserves an estimate in seconds, and the track settles with the seconds that rendered:
quantity, in the feature’s own units, and Ledger applies creditCost. The check holds reserve.quantity × creditCost credits (reserve.quantity defaults to the check’s quantity, else 1). The track charges quantity × creditCost, or the reserved quantity when you leave quantity out, and returns settled: true.
When you price the work yourself, such as model tokens at cost or GPU time, give the feature creditCost: 1 and send the cost in credits as quantity on both calls. Prepaid dollar balance shows it.
Reserve metered units
A metered feature (500 messages a month) reserves from its own allowance, not from credits:- Check reserves
reserve.quantityunits, or the check’squantitywhen you leave it out. Other checks and tracks then see that many fewerremaininginbalance, and the credit balance doesn’t move. Past the remaining allowance, an item with an overage price holds the rest as overage under the customer’s one cap, which counts it until the hold ends. Without one, or past the cap, the check returnsallowed: falsewithlimit_reachedoroverage_cap_reachedand holds nothing. - Track settles with the same
request_idandquantity, the real units (the reserved units when you leave it out). It returnssettled: trueandchargedQuantity.
How a reservation ends
Rules
- The reservation is the gate. A reserve is decided like a track of that amount, in one transaction, after what other reservations already hold, in spend order for credits, and the allowance, then overage, for metered. Two checks reserving the last of a balance at once: one is allowed, the other refused.
- Settling up to the hold always succeeds, because the work already ran. More than the hold must fit like a track; otherwise it returns
409 insufficient_credits,limit_reached,overage_cap_reachedorentity_cap_reached, and the reservation stays held, so you can track again for at most the held quantity. - Settling at nothing.
quantity: 0settles a held reservation without charging, for work that cost nothing (a cached answer, say), and needs no release. On a track with no held reservation,quantity: 0is400 invalid_request. - Uncovered amounts. If the grants under a hold ended while it was held (a cancellation, say), the part nothing could cover is returned as
uncoveredCreditsand not charged. A metered settle past the allowance with no overage is returned the same way. - Which credits it holds: the ones that last longest (a credit pack before a plan allowance that ends with the period). Other tracks during the work still spend the credits the customer would lose soonest, and the hold outlasts a plan period.
- Expiry. A reservation that is neither settled nor released lapses after
reserve.expiresInSeconds(an hour by default, at most 7 days), counted in the customer’s time, and its amount comes back by itself. A track after that charges like one without a reservation and returnsreservationExpired: true. - Period. A settle is charged when it happens. A reservation held across a renewal is charged, and counted toward the overage cap, in the new period.
- Idempotent. The same check with the same
request_id, feature, entity and amount returns the same reservation withidempotent: true; other values return409 request_id_conflict. A repeated settling track replays its result; one with anotherquantityreturns409 reservation_already_settled. Tracking a released reservation’srequest_idreturns409 reservation_released, and releasing a settled one returns409 reservation_already_settled. - Busy customers. Reserving, settling and releasing wait their turn behind the customer’s other billing changes, as track does.
503 customer_busymeans that wait passed 1.5 seconds; nothing was held or charged, so retry afterRetry-After(1 second) with the samerequest_id. - Reserving checks raise when Ledger is unreachable. Unlike a plain check, which fails open, a check with
reserveraises, because a reservation guards expensive work: start the work once Ledger answers. A settling track fails open and is replayed with the samerequest_id, like any track. - A reserve holds at least 1.
reserve.quantityis a whole number above 0;0is400 invalid_request. To end a hold without charging, settle it withquantity: 0or release it. - Reserve on credits and metered features. Held and boolean features return
400 reserve_not_supported. - Balances. While a reservation holds credits,
availableCreditseverywhere is the balance after holds (a hold that crosses your low-balance threshold sendsbalance.low), and Get a customer also returnsheldCredits. A hold larger than what’s left holds overage under the cap, which counts toward the cap until it ends. - Entities. Pass
entityIdon both the check and the track to reserve credits for one entity: its allowance first, then the shared credits under its cap. - Permissions. Reserving needs the Credits permission at Track (which includes Check). Reading one needs Check; releasing needs Track.