Skip to main content
Reservations make sure expensive work is paid for before it starts. The check holds the credits or units up front, so ten parallel GPU jobs, video renders or agent runs can never spend the same balance twice, and the track settles with the real amount once you know it. For work that takes a while, costs you real money, or whose size you only know at the end, check reserves and track settles:
  1. Check reserves. Check with a request_id and reserve. Allowed, it holds the amount so no other check or track can spend it, and returns a reservation. Refused, it is a normal check’s allowed: false with a reason, and nothing is held.
  2. Run the work.
  3. Track settles. Track with the same request_id and the real amount. It charges that and lets the rest of the hold go. If the work failed, release the reservation instead.
Reserve on credits and metered features.

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:
Both amounts are 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.quantity units, or the check’s quantity when you leave it out. Other checks and tracks then see that many fewer remaining in balance, 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 returns allowed: false with limit_reached or overage_cap_reached and holds nothing.
  • Track settles with the same request_id and quantity, the real units (the reserved units when you leave it out). It returns settled: true and chargedQuantity.

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_reached or entity_cap_reached, and the reservation stays held, so you can track again for at most the held quantity.
  • Settling at nothing. quantity: 0 settles 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: 0 is 400 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 uncoveredCredits and 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 returns reservationExpired: 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 with idempotent: true; other values return 409 request_id_conflict. A repeated settling track replays its result; one with another quantity returns 409 reservation_already_settled. Tracking a released reservation’s request_id returns 409 reservation_released, and releasing a settled one returns 409 reservation_already_settled.
  • Busy customers. Reserving, settling and releasing wait their turn behind the customer’s other billing changes, as track does. 503 customer_busy means that wait passed 1.5 seconds; nothing was held or charged, so retry after Retry-After (1 second) with the same request_id.
  • Reserving checks raise when Ledger is unreachable. Unlike a plain check, which fails open, a check with reserve raises, because a reservation guards expensive work: start the work once Ledger answers. A settling track fails open and is replayed with the same request_id, like any track.
  • A reserve holds at least 1. reserve.quantity is a whole number above 0; 0 is 400 invalid_request. To end a hold without charging, settle it with quantity: 0 or release it.
  • Reserve on credits and metered features. Held and boolean features return 400 reserve_not_supported.
  • Balances. While a reservation holds credits, availableCredits everywhere is the balance after holds (a hold that crosses your low-balance threshold sends balance.low), and Get a customer also returns heldCredits. A hold larger than what’s left holds overage under the cap, which counts toward the cap until it ends.
  • Entities. Pass entityId on 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.