Overview
Grantex budget controls let you allocate a monetary budget to any grant, debit amounts on each API call, and receive real-time alerts when spending thresholds are crossed. Key features:- Per-grant budget allocation with atomic debit operations
- Race-condition safe — uses SQL
WHERE remaining_budget >= amount - Threshold alerts at 50% and 80% via event bus (
budget.threshold) - Exhaustion events when the budget hits zero (
budget.exhausted) - JWT
bdgclaim — budget balance embedded in grant tokens for downstream enforcement
Allocating a Budget
Debiting from a Budget
Each debit atomically decrements the remaining balance. If the debit exceeds the remaining budget, the API returns 402 Payment Required with codeINSUFFICIENT_BUDGET.
Handling Insufficient Budget
Checking Balance
Transaction History
Budget JWT Claim
When a grant has a budget allocation, the issued grant token includes abdg claim with the current remaining balance at the time of token issuance:
Threshold Alerts
Grantex automatically emits events when spending crosses thresholds:| Event | Trigger |
|---|---|
budget.threshold | Remaining budget drops below 50% or 20% of initial |
budget.exhausted | Remaining budget reaches zero |
- Webhooks — to all registered webhook endpoints
- SSE/WebSocket — via the real-time event stream (
GET /v1/events/stream)
Portal Dashboard
Budget allocations are visible in the developer portal under Budgets:- Summary cards showing total allocated, spent, and remaining
- Per-grant usage bars with status badges (Healthy / > 50% / > 80% / Exhausted)
- Transaction drill-down with pagination
API Reference
| Method | Path | Description |
|---|---|---|
POST | /v1/budget/allocate | Create a budget allocation for a grant |
POST | /v1/budget/debit | Debit an amount from a grant’s budget |
GET | /v1/budget/balance/:grantId | Get current budget balance |
GET | /v1/budget/transactions/:grantId | List paginated transaction history |