For operations where you don’t know the final cost upfront — like AI completions, batch processing, or long-running jobs — you can reserve balance before the work starts, then finalize the reservation when it’s done.
This is a three-step flow:
- Check with lock — atomically check access and hold balance
- Do work — run your operation
- Finalize — confirm the deduction, adjust it, or release the hold
Step 1: Check with lock
Pass the lock parameter to the check endpoint. This atomically checks if the customer has enough balance and reserves it in a single call.
Lock parameters
Always set an expires_at to prevent balance from being held indefinitely if your finalize call fails. If a lock expires, the held balance is automatically released back to the customer.
Step 2: Do your work
Run whatever operation you reserved balance for. The held balance is guaranteed to be available — no other concurrent request can consume it.
Step 3: Finalize the lock
When the operation completes, call balances.finalize to resolve the held balance.
Confirm the full amount
If the operation used exactly the amount you reserved, confirm the lock:
Release the hold
If the operation failed or was canceled, release the lock to return the held balance:
Adjust the final amount
If the actual usage differs from the reserved amount (common with AI tokens), pass overrideValue to adjust:
Autumn will reconcile the difference — returning the unused 257 tokens back to the customer’s balance.
Use cases
AI completions
Reserve a token budget before starting generation, then finalize with the actual token count:
Long-running jobs
Reserve credits before queuing a job, release if the job fails:
Compared to check + track
For simple operations where you know the cost upfront and the operation is fast, check with sendEvent is simpler — it deducts immediately in one call.
Use reservations when:
- The final usage amount is unknown at check time (e.g., AI token counts)
- The operation can fail after balance is deducted
- The operation takes significant time and you don’t want another request to consume the same balance