Skip to main content

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 bdg claim — 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 code INSUFFICIENT_BUDGET.

Handling Insufficient Budget

Checking Balance

Transaction History

Budget JWT Claim

When a grant has a budget allocation, the issued grant token includes a bdg claim with the current remaining balance at the time of token issuance:
Service providers can use this claim to enforce budget limits without making additional API calls.

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)
Example event payload:

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

Last modified on March 1, 2026