The budgets client manages per-grant spending budgets. Allocate budgets when issuing grants, debit as agents consume resources, check remaining balances, and review transaction history.Access the budgets client via client.budgets.
Debit an amount from a grant’s budget. Uses atomic operations to prevent overdraft. Raises a GrantexApiError with status 402 and code INSUFFICIENT_BUDGET if the balance is insufficient.
from grantex import Grantex, DebitBudgetParamswith Grantex(api_key="gx_live_...") as client: result = client.budgets.debit(DebitBudgetParams( grant_id="grnt_01HXYZ...", amount=50, description="GPT-4 API call", )) print(f"Remaining: {result.remaining}") print(f"Transaction ID: {result.transaction_id}")
If the remaining budget is less than the debit amount, a GrantexApiError is raised with HTTP status 402 and code INSUFFICIENT_BUDGET. Debits are all-or-nothing — no partial debits.
List all transactions for a grant’s budget. Supports pagination.
from grantex import Grantexwith Grantex(api_key="gx_live_...") as client: result = client.budgets.transactions("grnt_01HXYZ...", page=1, page_size=50) print(f"Total transactions: {result.total}") for txn in result.transactions: print(f" {txn.description}: -{txn.amount} (balance: {txn.balance_after})")