Skip to main content
This guide shows how to charge credits for usage of a metered feature, such as AI tokens, using the check, act, track pattern. Your application reports usage of the feature, and Stigg converts it into credits using a consumption mapping. The examples use the Node.js SDK. The same operations are available in every backend SDK and in the REST API.
1

Estimate the credit cost

Ask Stigg how many credits the usage would consume, without reporting it. The response includes, per credit currency, the estimated cost, the current balance, the balance after the estimate, and whether the usage would overdraft the balance.
estimateUsageCost has a much lower rate limit (3,000 requests per minute) than getCreditEntitlement, which is served from the SDK’s local cache. Take this into account in high-volume flows.
2

Check the credit entitlement (optional)

The estimate already tells you whether the customer has enough credits, so this step isn’t required. To check against the balance directly, pass the estimated cost as requestedUsage. hasAccess is true only when the remaining balance covers it.
3

Perform the operation

Run the operation in your application.
4

Report usage of the metered feature

Report usage against the feature, not the credit currency. Stigg applies the consumption mapping and deducts the matching amount of credits. For credit-backed features, the response includes a credit object with the credits this call deducted and the updated total consumption.