Skip to main content
This guide reserves credits for an operation whose cost you know only after it finishes, such as an LLM call or an agent task, and then settles the reservation with the real cost. See Reserve and settle for how reservations work. The examples use the REST API and the Typescript and Python REST SDKs. Before you start:
  • A Stigg server API key.
  • A credit type currency-ai-credits and a customer customer-demo-01 with a credit grant. See Set up credits.
  • A client, if you use an SDK. Reservations need TypeScript SDK 0.1.0-beta.62 or Python SDK 0.1.0-beta.53 or later. See Availability for other languages.
1

Reserve credits

Call the entitlement check with reserveAmount, the most the operation can cost, and a reservationId that identifies the operation. Stigg checks the balance and holds the credits in one step.
When the balance covers the amount, the response grants access and includes the reservation. currentUsage now includes the 100 held credits. The response below is abbreviated.
The reservation expires after one hour by default. If the operation can take longer, pass reservationTtlSeconds (up to 86400) or reservationExpiresAt (up to 24 hours ahead).
2

Handle denied access

When the balance does not cover the amount, isGranted is false, accessDeniedReason is InsufficientCredits, and nothing is held. Block the operation or offer a top-up.
3

Run the operation and settle

Run the operation, calculate the credits it used, and release the reservation with that amount. The release endpoint settles the reservation: Stigg consumes the amount and returns the rest to the customer’s credit balance. If the operation fails, release with consumedAmount: 0.
The response returns the released reservation and the updated balance:
If a request fails, retry it with the same reservationId. Both the reservation and the release are applied once.
4

Review the ledger

In the Stigg app, go to Customers → customer-demo-01 → Credits and open the Ledger tab. The reservation appears as Credits reserved (-100), followed by Reservation released (+60). Expand the release to see the Hold returned (+100) and Usage (-40) entries, or click job-123 to show only this reservation’s events.