Usage-based billing model (authorize then commit)
This model gates work in real time and records usage after the work completes.
Prereqs
- You completed Start here.
- You can run the authorize then commit tutorial: Tutorial: authorize then commit.
Workflow
- Authorize before work:
POST /mgt/v1/gate/authorize - Do the protected work.
- Commit after work:
POST /mgt/v1/gate/commits - If work fails, cancel (best-effort):
POST /mgt/v1/gate/cancel
What you should treat as authoritative
- Commit returns the authoritative priced result at commit time.
- Pricing behavior is "floating": it uses the current price at commit time.
What to do with hints
Common patterns:
pricing.not_configured: log and treat as "observable but not chargeable" until pricing is configured.quota.remainingorrate.limit: implement backoff, queueing, or degradation.funding.xusd_shortfallorbudget.shortfall: decide your product policy (hard stop vs soft degrade).
Verify in production
You should be able to answer these questions from logs:
- For a given business request, what
principal_idandfeature_codewere used? - Which
Idempotency-Keywas used for authorize and commit? - What hints were returned?
- What amount was computed at commit time?
Troubleshoot
402: enforcement blocked the request (funding, quota, or budget).429: rate limit.409: idempotency conflict.
Next
- Feature and meter naming: Features and meters
- Funding and balances: Funding and grants overview