# Budgets and Costs

`ai-gateway-metering-v2`

The **Budgets and Costs** policy records what an app uses and enforces its
budgets. It meters three things—spend, tokens, and requests—each with
independent daily and monthly periods, and each with an optional warning
threshold that notifies without blocking.

When a limit is exceeded, the policy either routes the request to the model
selection's `quotaFallback` if [Fallback Model](./fallback-model.mdx) supplied
one, or rejects it with `429`.

An app's own limits aren't the only ones that apply. The policy also checks the
parent team's and the gateway's limits, which are enforced centrally rather than
from this policy's options—so a request can be blocked by a limit that isn't
visible in the app's chain.

Place Budgets and Costs after [Model Filtering](./model-filtering.mdx) and
[Fallback Model](./fallback-model.mdx), so an exceeded budget can activate the
quota fallback.

:::caution{title="Budgets fail open by default"}

`throwOnFailure` defaults to `false`, so if the metering service is unavailable
the request proceeds unmetered—no limit is checked, even for an app that's
already over budget. Set it to `true` to reject the request instead.

:::

:::note

Each limit period carries an `enabled` flag next to its number, and so does each
warning threshold. A period enforces nothing until `enabled` is `true` _and_
`limit` is set. Watch for this when editing options directly, such as in
`config/policies.json` or a [policy template](../policy-templates.mdx).

:::

For the portal workflow and the gateway and team levels see
[Usage Limits](../usage-limits.mdx); for every option see the
[generated reference](/policies/ai-gateway-metering-v2-inbound).
