# Budget

How limits at organization, team and agent level are reserved in one transaction, so agents running in parallel cannot overspend a shared limit.

<ShortProductTruth>**Parallel agents, one limit.** Every allowed payment reserves its amount at organization, team and agent level in one transaction, so two purchases that each fit alone cannot both pass when together they do not.</ShortProductTruth>


## The problem it removes [#the-problem-it-removes]

A per-purchase cap does not stop ten agents from each spending up to it at the same moment. A budget checked without a lock lets them all through. Abazi Budget reserves before anything is signed, at every level at once, and releases or commits the reservation once the outcome is known.

## Who uses it [#who-uses-it]

| Who | How |
| --- | --- |
| Owners and finance | Set limits for the organization, each team and each agent, and watch reserved and committed amounts. |
| Approvers | See how much budget is left when they decide a purchase. |
| Agents | Read their own remaining budget with `get_spending_status`. |

## How it works [#how-it-works]

1. **Read.** During the policy decision, the engine reads the three budgets without locking them, and denies early if one is already short.
2. **Reserve.** On ALLOW, Abazi locks the organization, team and agent rows in that order, checks each level and adds the amount to reserved on all three, in one database transaction. The reservation is held.
3. **Commit or release.** When the payment settles, held becomes committed. On denial, failure, expiry or cancellation it is released.
4. **Refund.** A settled refund lowers committed at all three levels.

What is left at each level is the limit minus committed minus reserved, never below zero. When committed plus reserved reaches 80 percent of a limit, an alert is sent once.

A payment whose outcome is unknown keeps its reservation held until reconciliation settles it, so the money cannot be spent twice. See [Budgets and reservations](/docs/concepts/budgets-and-reservations).

## Limits in the example mandate [#limits-in-the-example-mandate]

| Level | Example limit |
| --- | --- |
| Organization | <Limit name="orgBudget" /> |
| Each team | <Limit name="teamBudget" /> |
| Each agent | <Limit name="agentBudget" /> |

## Screens [#screens]

<Screenshot id="console-budgets" />

## Boundaries [#boundaries]

| Case | What happens |
| --- | --- |
| Any level is short | DENY with <ReasonCode code="BUDGET_EXCEEDED" />; the trace names the level and what was left. |
| Two purchases race for the last of a budget | One gets the reservation, the other gets <ReasonCode code="BUDGET_EXCEEDED" />. |
| A team limit above the organization, or an agent limit above its team | Refused. |
| A limit lowered below what is already used | Allowed. What is left becomes zero; nothing is clawed back. |

An approval never raises a budget. A purchase that a person approves still needs room at every level.

## API [#api]

The Budgets operations in the API reference, each with its parameters, responses and code samples:

<ApiOperationList ids={['getBudgetTree', 'setBudget', 'updateBudget']} />

## Next steps [#next-steps]

<Cards>
  <Card title="Budgets and reservations" href="/docs/concepts/budgets-and-reservations" description="Follow a reservation from held to committed or released." />
  <Card title="Mandate" href="/docs/products/mandate" description="Combine budgets with per-purchase caps and thresholds." />
  <Card title="Ledger" href="/docs/products/ledger" description="See how committed spend becomes balanced ledger entries." />
</Cards>

