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:
These events are delivered via:
- 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