> For the complete documentation index, see [llms.txt](https://docs.revenium.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.revenium.io/track-and-control-costs/cost-controls.md). Agents can also search and read this documentation through its [MCP server](https://docs.revenium.io/~gitbook/mcp).

# Guardrail Enforcement

Use enforced Guardrails to block AI requests when configured usage limits are reached.

Enforced Guardrails use Revenium's usage metering data to enforce configured AI spend and usage limits. You create a budget with **Enforce the limit** set to **Shadow** or **Live** in the Revenium app; the [Revenium SDK](https://docs.revenium.io/integrations/sdk-setup.md) running inside your application evaluates incoming AI requests against that budget and, when it is set to **Live**, blocks the request once the limit is reached.

The SDK evaluates rules locally using a cached ruleset that refreshes every 30 seconds by default (the Python SDK reads `REVENIUM_CB_POLL_INTERVAL_SECONDS` to change it; the Node and Go SDKs are fixed at 30 seconds). If Revenium is unreachable, the SDK continues using its last cached ruleset. If no ruleset has been fetched, enforcement does not run.

{% hint style="success" %}
**New to Revenium?** Guardrail enforcement requires Revenium AI metering. If you haven't configured metering yet, start with [instrumenting your code in the quickstart](https://docs.revenium.io/get-started/quickstart/5-minute-quickstart.md#instrument-your-own-code-or-api-traffic).
{% endhint %}

## How it fits with Budgets & Alerts

Enforced Guardrails work alongside notification-only Guardrails ([Set Budgets & Alerts](https://docs.revenium.io/track-and-control-costs/set-budgets-and-alerts.md)). Alerts notify you when a metric crosses a threshold, budget views show usage against configured budgets, and enforced Guardrails enforce configured limits before the AI request proceeds.

| Feature                   | When it fires                                       | What it does                                         |
| ------------------------- | --------------------------------------------------- | ---------------------------------------------------- |
| Cost & Performance Alerts | Metric crosses a threshold                          | **Notifies** via email / Slack                       |
| Budget Monitoring         | Tracking view of all threshold-based budgets        | **Visualizes** pace and risk                         |
| **Enforced Guardrails**   | Rule's hard limit is crossed on an incoming request | **Enforces** — blocks the request before the AI call |

Use these features together when you need both visibility and enforcement. For example, configure an alert at 80% of a monthly limit, use the budget view to review usage trends, and use an enforced Guardrail to enforce the limit for a customer, model, provider, or other scope.

***

## Anatomy of an enforced Guardrail <a href="#anatomy-of-a-cost-control-rule" id="anatomy-of-a-cost-control-rule"></a>

An enforced Guardrail is defined by five things:

1. **Metric**: what you're counting, such as total cost, tokens, errors, or the number of images, videos or audio files generated. A cap on images, videos or audio files stops a generation workload at a set number of images or clips.
2. **Window**: the calendar period you're counting over (a day, a week, a month, or a quarter). The count starts again when a new period begins. A new limit on total cost also counts the spend already recorded in the current period, so a limit created partway through a month starts from that month's spend to date. Limits on other metrics, except tool calls and tool cost, also include matching usage already recorded in the current period. So do limits filtered or grouped by department. A limit on tool calls or tool cost counts only while it is on. It counts from when you create it or last change its filters or period. It can cover a tool, an agent or a product, but not one person.
3. **Hard limit**: the threshold that trips enforcement.
4. **Action**: what the SDK does when the limit is crossed. New rules use **Block** (the only action selectable in the UI today). `THROTTLE` is a legacy action retained for historical rules and event-log rendering only. `WARN_ONLY` is set when an administrator uses **Switch to warn-only until a date** in [Check Limits](https://docs.revenium.io/track-and-control-costs/check-limits.md); the rule blocks again at the date and time chosen. Older rules can also carry it.
5. **Scope**: optional filters (this budget only applies to OpenAI) and group-by (broken out per subscriber or department). Department, and Subscriber on Total Cost or with a Department filter, are the only groupings that give each value its own limit. Any other grouping, such as Model or Agent, would count every value together against one limit, so the form greys those out while **Enforce the limit** is set to **Shadow** or **Live**. Grouping by Subscriber evaluates each subscriber's usage independently against the limit instead of pooling usage across the team or API key, and each person who crosses it is announced separately (see the FAQ on notification volume below).

{% hint style="info" %}
**A rule scoped to Anthropic also covers Claude served through Azure Foundry.** If your traffic reports Foundry as its provider, a rule reading `Provider is Anthropic` still counts it, because that spend is Claude usage on an Azure bill. `Provider is not Anthropic` excludes it for the same reason. Scope a rule to Foundry itself to count Foundry traffic on its own.
{% endhint %}

{% hint style="warning" %}
**Total Cost and unpriced models:** Total Cost enforcement requires the model's pricing to be configured in your pricing tier. If a model lacks pricing data, events for that model contribute $0 to the rule and won't trip the threshold. Use Token Count if you need enforcement regardless of pricing coverage.
{% endhint %}

Enforced Guardrails also support these options:

* **Enforce the limit** has three choices. **Off** never blocks anyone; saving with Off makes the budget an alert that only notifies. **Shadow** blocks nobody and records the requests it would have blocked as simulated events, so you can test the limit first. When the limit counts AI usage, **Live** blocks requests through the Revenium SDK, and prompts and tool calls in Sidekick. It does so once the limit is reached, until the period resets. A limit on tool calls or tool cost never blocks an AI call.
* **Warning threshold** — a soft threshold below the hard limit that fires a warning notification without blocking.

When a budget's **Enforce the limit** is set to **Shadow** or **Live**, you can set its **Early warning** to a percentage of the limit between 1 and 99, with up to two decimal places. Revenium shows the early warning as a spend amount together with its percentage of the limit, so you can see the figure at which your team is warned.

***

## Creating your first enforced Guardrail <a href="#creating-your-first-cost-control-rule" id="creating-your-first-cost-control-rule"></a>

Find **Guardrails** under **Spend Management** in the left nav, or search "guardrails" in the Revenium app.

1. **Open Guardrails** — find it under **Spend Management** in the left nav, or search. You'll see the list of existing rules for your team.
2. **Click New budget or alert** and set **Enforce the limit** to **Shadow** or **Live**. The form walks you through the required pieces.
3. **Name the rule and pick a metric** — give it a descriptive name (this appears in notifications and the enforcement event log) and pick the cumulative metric you want to cap.
4. **Choose a window and limit** — daily / weekly / monthly / quarterly. Windows are calendar-aligned in UTC. Set the hard limit; optionally set a warning threshold below it.
5. **Note the action** — new rules use **Block**. The Guardrail form does not surface an action selector today; the rule is created with `action: BLOCK`.
6. **Start with Shadow.** Set **Enforce the limit** to **Shadow** for the first evaluation period so you can preview what would happen before switching to **Live**.
7. **Scope it (optional)** — add filters or a Group by dimension to narrow the rule (e.g. only OpenAI, broken out per subscriber).
8. **Attach notification channels (optional)** — Slack + webhook channels configured under **Settings → Alert Channels** can receive alerts when the rule fires.
9. **Save.** New and changed budgets take about 2 minutes to take effect. Until then the budget shows its mode (**Shadow** or **Live**) and **No reading yet**, which is normal. Because **Enforce the limit** is set to **Shadow**, requests are not blocked, but simulated events appear in the enforcement event log after the budget is evaluated.

***

## Check limits

Open **Check limits** from **AI by Employee**. Administrators and Read Only users can also search for it. It shows whether a person or department's AI calls are blocked and which Guardrails on AI calls apply. Members cannot open Check limits. Department Admins can check people in their departments. Administrators and Read Only users can check people and departments.

From **Check limits**, an administrator can switch an eligible blocking rule to warn only until a chosen date. Blocking resumes by itself at that time.

***

## Reviewing a rule

Open a rule to review it across these tabs:

* **Overview** — the rule's configuration, status and recent activity.
* **People** — each person's usage against the limit. This tab appears when the rule is grouped per person. A rule grouped per department shows **Departments** instead, while an ungrouped rule has no roster tab.
* **Events** — the rule's enforcement history, including warning crossings, live blocks and shadow simulations.

Select a person on **People** to open their details. On a rule that gives each person their own limit, **Give this person their own limit** moves that person onto a personal rule with the same window, behaviour, department and other filters. On a per-person rule scoped to a department, what the person has already spent this window counts toward the new limit at once, so the dialog asks for a limit above that spend and warns when the early warning would fire straight away. Open the personal rule's own details and select **Remove personal limit** to put the person back on the group rule. A rule where a department shares one limit, or that already covers only this person, explains why the action is not offered.

The tab labels include counts when Revenium can load them, and each tab has its own URL so you can share a link to the same view.

Use **Showing** on the rule's page to choose the date range that every tab reads. It opens on the rule's current period, so a weekly or monthly rule shows its week or month to date rather than only the most recent day. You can also choose a recent window or a **Custom range** of whole UTC days. The roster on the **People** and **Departments** tabs always reflects the current period.

***

## Shadow mode vs enforce

When **Enforce the limit** is set to **Shadow**, the budget matches traffic, aggregates usage, sends configured notifications, and records simulated events, but does not block requests.

Shadow lets you review matching behavior before the budget goes **Live**. It lets you:

* See how much traffic a rule would have blocked over a real evaluation window.
* Catch filter mismatches before they affect customers.
* Validate threshold tuning — if a rule would have fired 50 times in the first hour, your threshold is too low.
* Tune notification noise — test the alerting flow without blocking.

### Promoting to enforce

After you confirm the budget matches the intended traffic and threshold, set **Enforce the limit** to **Live**. Once the limit is reached, a budget on AI usage blocks requests until the period resets. A limit on tool calls or tool cost never blocks an AI call.

You can do this from the UI by editing the budget, choosing **Live** and confirming **Switch to live**.

{% hint style="success" %}
**Best practice:** run a new budget in Shadow for at least one full window (a monthly budget for a full month, a daily budget for a full day) before choosing Live. This gives you a more complete view of usage over the budget's evaluation period.
{% endhint %}

***

## Enforcement actions

When a **Live** budget reaches its limit, the SDK executes the budget's action. Budgets support only **Block** today:

| Action | What happens                                                                                                                                                                                   |
| ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Block  | The SDK raises a cost-limit exception **before** the AI provider call. The provider never sees the request. Customer code catches the exception and surfaces a graceful error to the end user. |

### What your app can read about a rule

A blocked call raises an error that identifies the rule that blocked it: `BudgetExceededError` in the Python SDK and `CostLimitExceeded` in the Node.js SDK. When the SDK has them, the error also carries the rule's limit (`threshold`) and the amount used so far (`current_value` in Python, `currentValue` in Node.js).

To read a rule's figures before any call is blocked, use [Get enforcement rules](https://revenium.readme.io/reference/get_enforcement_rules) (`GET /v2/api/ai/enforcement-rules/{teamId}`). For each rule it returns the limit (`threshold`), the amount used so far in the current period (`currentValue`) and the share of the limit used (`percentUsed`, where 1 is the whole limit). For a rule that is not grouped, your app can work out what is left from the limit and the amount used. For a rule grouped by person or department, the limit applies to each group on its own and the rule's amount used adds the groups together, so read each group's own `currentValue` and `breached` in its `groupBreakdown` entry instead.

### Legacy actions (historical)

`THROTTLE` is retained in the API and event-log rendering for rules created before the action selector was removed from the UI. It is **not selectable** when creating a new rule today. `WARN_ONLY` on a rule means either a legacy rule or a rule an administrator switched to warn only until a date from [Check Limits](https://docs.revenium.io/track-and-control-costs/check-limits.md).

### Fail-open by default

If the SDK can't reach Revenium (network issue, Revenium outage, expired API key), **enforcement fails open**. The SDK logs the failure and continues using its last cached ruleset. If no ruleset has been fetched, enforcement does not run.

{% hint style="warning" %}
**Stop enforcement for a rule.** Disable the rule in the UI. SDKs pick up the change on the next ruleset refresh. Re-enable the rule when you want enforcement to resume.
{% endhint %}

***

## SDK setup and configuration

To enforce Guardrails in your own application, install the Revenium SDK. Use the SDK documentation for language-specific environment variables, exception fields, code examples, and troubleshooting:

| SDK         | Where to find it                                                    | What it covers                             |
| ----------- | ------------------------------------------------------------------- | ------------------------------------------ |
| **Python**  | See [SDK Setup](https://docs.revenium.io/integrations/sdk-setup.md) | Python SDK setup and supported providers.  |
| **Node.js** | See [SDK Setup](https://docs.revenium.io/integrations/sdk-setup.md) | Node.js SDK setup and supported providers. |
| **Go**      | See [SDK Setup](https://docs.revenium.io/integrations/sdk-setup.md) | Go SDK setup and supported providers.      |

Each SDK README also links back here for the conceptual walkthrough.

{% hint style="info" %}
Check each SDK README and changelog for current Guardrail enforcement support by language and provider.
{% endhint %}

### Claude Code sessions

[Revenium Sidekick](https://docs.revenium.io/track-and-control-costs/analyze-ai-tooling-spend/revenium-sidekick.md) applies your team's Guardrails in Claude Code as developers work, without the SDK. Once the budget is spent, it stops further work in that developer's session. By default each machine reuses Revenium's budget answer for up to 5 minutes, so work can continue for up to 5 minutes after a budget is used up; your administrator can shorten that time. Setup is available from your Revenium customer success manager. If you are evaluating Revenium, [talk to sales](https://docs.revenium.io/plans-and-contact/talk-to-sales.md).

***

## Reading the enforcement event log

Every matching transaction that reaches a budget's warning level or limit writes an immutable event to the **Events** tab. Each row shows when it happened, who or what the budget counted, the level, the budget mode, the accumulated value, a masked API-key hint and the triggering request when one was recorded.

Select a row to open the event drawer. It shows the event's **When**, **Level**, **Mode**, **Metric**, **Value**, **API key** and **Request**, plus the **Provider** and **Model** when recorded. For a budget grouped by person, it also identifies the person and links to their other events on the budget. You can copy a recorded request ID or follow the available link to the related data in Logs.

Use the controls above the table to narrow the history:

* **Search the whole event text** searches across the event, including the budget name and API-key hint.
* **Affected** narrows the list to one person, department, model or other object tracked separately by the budget.
* **Level** offers **All levels**, **Limit reached** and **Warning level reached**.
* **Budget mode** offers **All budget modes**, **Live** and **Shadow**.
* **Showing**, the date range for the budget's page, sets the period the events cover.

Use **Shadow** while tuning a new budget to see which requests would have been blocked without blocking them.

***

## Reviewing enforcement across every budget

The **History** tab in **Guardrails** lists enforcement events from all of your team's budgets in one place. Use it when the question is about a person, a department or a period rather than one budget.

Use the controls above the list to narrow it:

* **Level** offers **All levels**, **Limit reached** and **Warning level reached**.
* **Budget** narrows the list to one budget, or shows **All budgets**.
* **Date range** sets the period the list covers.
* **Search** searches the whole event text.
* **Affected** narrows the list to one person, department or other object a budget tracks.
* **Budget mode** offers **All budget modes**, **Live** and **Shadow**.

***

## The Enforcing count

The **Enforcing** card above the Guardrails list counts only budgets set to block, and its caption reads **Only budgets that block requests**. It also counts a **Live** limit on tool calls or tool cost, which never blocks an AI call. Notification-only budgets, legacy warn-only and throttle budgets, and budgets set to **Shadow** do not add to that count.

***

## What a budget's status means

The **At risk** and **Limit reached** counts include **Shadow** budgets by their spend, even though Shadow does not block requests.

New and changed budgets take about 2 minutes to take effect. During that time a budget shows its mode and **No reading yet**: nothing is wrong and there is nothing to do.

| Status                                     | What it means                                                                                                                                                                | What to do                                                                                                                                                                                                                                                     | What happens next                                                 |
| ------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
| **Live**                                   | A budget on AI usage blocks matching requests once usage reaches the limit, until the period resets. A budget that only notifies sends its alerts instead and blocks no one. | Nothing.                                                                                                                                                                                                                                                       | It keeps enforcing.                                               |
| **Shadow**                                 | The budget blocks no one. Each request it would have blocked is recorded as a simulated event.                                                                               | Switch it to **Live** when you are ready to block.                                                                                                                                                                                                             | It keeps recording simulated events.                              |
| **Off**                                    | The budget is switched off, so it is not checked.                                                                                                                            | Switch it on from the Guardrails list.                                                                                                                                                                                                                         | Nothing is checked until it is on.                                |
| **No reading yet**                         | The budget has no spend reading yet. New and changed budgets take about 2 minutes to take effect.                                                                            | Reload the page after that to see its spend.                                                                                                                                                                                                                   | Spend shows once AI traffic matches the budget.                   |
| **Not enforced** (budget not taken effect) | The budget blocks no one and sends no alerts (a Shadow budget records no simulated events). It should have taken effect within about 2 minutes of its last change.           | Reload the page. If it still shows this, an administrator should check that the budget's department still exists (if it has one), or contact support with the budget's name and when it first showed this. Members are asked to tell their team administrator. | It takes effect on its own once the cause is fixed.               |
| **Not enforced** (department budgets off)  | Department budgets are not available on your account right now, so this budget is not checked and sends no alerts.                                                           | Contact support to turn them back on, or an administrator can switch the budget off from the Guardrails list.                                                                                                                                                  | It stays this way until support turns department budgets back on. |
| **Spend not shown to you**                 | A budget an administrator set above you. Its spend is not shown to you, but enforcement holds it and it is enforced as set.                                                  | Nothing. Ask your team administrator if you need its standing.                                                                                                                                                                                                 | It keeps enforcing.                                               |
| **Unknown**                                | Spend could not be read just now, so the budget's standing cannot be shown. Its settings are unchanged.                                                                      | Reload the page to try again.                                                                                                                                                                                                                                  | It shows the budget's standing once a read succeeds.              |

The Guardrails list counts **Not enforced** budgets apart from **Unknown** ones in the cards above it.

***

## Rules that cannot be evaluated

A rule saved with a limit of zero has nothing to measure against, because every request is at or over it from the moment the rule exists. Rather than report that rule as breached on day one and count it toward your breached total, the list, the detail view and the header show it as **invalid**: a configuration to correct rather than a limit that was reached. Give the rule a limit above zero and it evaluates normally.

***

## Disabling vs deleting a rule

* **Disable** — the rule is retained for history but skipped at evaluation time. Re-enable any time. Use this to pause a rule temporarily.
* **Delete** — soft-delete. Removed from evaluation but the event history persists for audit. You cannot un-delete; create a new rule if you need the semantic back.

***

## FAQ

<details>

<summary>How quickly does a new rule start enforcing?</summary>

The SDK polls the compiled-rules endpoint every 30 seconds by default (the Python SDK reads `REVENIUM_CB_POLL_INTERVAL_SECONDS` to change it; the Node and Go SDKs are fixed at 30 seconds). Allow up to one full poll interval for a new rule to reach every running instance of your application. First-time rule creation may take slightly longer because the server's rule compiler must produce the compiled payload — typical end-to-end time is under two minutes.

</details>

<details>

<summary>What happens if my application can't reach Revenium?</summary>

The SDK fails open. It logs the failure and continues using its last cached ruleset. If it has never successfully fetched a ruleset, enforcement does not run.

</details>

<details>

<summary>Does enforcement add latency to my AI calls?</summary>

The SDK's enforcement check is an in-memory comparison against the cached ruleset. Rule-cache refresh happens in a background task and does not block the request path.

</details>

<details>

<summary>Can I have multiple rules on the same metric?</summary>

Yes. Rules are evaluated independently — every matching rule runs. If two rules would both block the request, the first to fail wins. Use the warning threshold on a blocking rule to get notified before the hard limit is hit, or apply both a global and a per-group cap. For notification-only flows on the same metric, see [Set Budgets & Alerts](https://docs.revenium.io/track-and-control-costs/set-budgets-and-alerts.md).

</details>

<details>

<summary>How many notifications does one rule send?</summary>

One per crossing per period, on each notification channel attached to the rule.

Slack and email notices identify the Daily, Weekly, Monthly or Quarterly period and the dates it covers in UTC.

A rule with **no Group by** announces the first crossing in the window and then stays quiet until the window resets, however many requests keep hitting the limit.

A rule **grouped by Subscriber** announces every person who crosses the limit, once each, with the person named in the message. A hundred developers over a daily cap produce a hundred messages that day. The same person crossing again in the same period is announced once. Other Group by dimensions behave the same way, one announcement per group that crosses.

A warning threshold and the hard limit are tracked separately, so one person crossing both in the same period is announced twice: once as a warning, once as a breach.

</details>

<details>

<summary>How do I cap spend across all my customers, not per-customer?</summary>

Create a rule with **no filters** and **no group by**. It aggregates all your team's AI spend for the window against a single limit. Pair it with a per-customer rule (filter by organization) if you want both a fleet cap and a per-customer cap.

</details>

<details>

<summary>How do I stop enforcement for a rule?</summary>

Disable the rule from the **Guardrails** page. SDKs pick up the change on the next ruleset refresh.

Re-enable the rule when you want enforcement to resume.

</details>

***

## See also

{% hint style="info" %}
**Notification channels** for Guardrails (Slack, webhook) are configured in the Revenium app under **Settings → Alert Channels**. Once configured there, they appear in the channel picker on the Guardrail form.
{% endhint %}

* [Set Budgets & Alerts](https://docs.revenium.io/track-and-control-costs/set-budgets-and-alerts.md) — adjacent feature: alerts and budget tracking for notification-only flows.
* [SDK Setup](https://docs.revenium.io/integrations/sdk-setup.md) — install the Revenium SDK that evaluates enforced Guardrails.
* [Check Limits](https://docs.revenium.io/track-and-control-costs/check-limits.md): see whether a person or department's AI calls are blocked right now, which rule blocks them, and the available ways to unblock them.

## Spend readings and people not checked

A Guardrail can show when spend was last read. Use **Refresh** to load the latest reading.

On a budget’s **People** tab, **Not checked** counts people who left the budget’s department, and deleted departments. Their earlier spend still counts toward the budget, but the limit is not applied to them.

Open a Guardrail’s change history to see who set it and what changed.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.revenium.io/track-and-control-costs/cost-controls.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
