Budgets & Cost Control
LangGuard computes the token cost of every trace and lets you enforce budgets with policies — flagging or blocking activity that exceeds a per-trace, per-token, or cumulative spend limit.
How cost is tracked
Cost is derived from token usage and your model pricing. Set per-model input and output rates on the Cost Estimates settings page; every trace's cost is then computed from the tokens it consumed. Costs roll up across the Trace Explorer, Monitoring, and the AI Registry.
Enforcing a budget
The built-in Budget Overrun Detection policy turns spend into a guardrail. Configure it with:
| Parameter | Default | Enforces |
|---|---|---|
budget_usd | (required) | The total budget to measure against |
budget_threshold_percent | 80 | Flag when cumulative spend crosses this % of budget |
max_cost_per_trace | 1.00 | Per-trace cost ceiling |
max_tokens_per_trace | (disabled) | Per-trace token ceiling |
avg_cost_per_trace | (disabled) | Anomaly baseline — a trace 5× this is flagged |
Like any policy, it can run in permissive mode (record violations) or enforce mode (block) — see Policy modes.
Time-windowed (rolling) budgets
For "spend per hour/day" style limits, a custom policy can read rolling-window
spend from the policy input — for example input.traces.total_cost_usd, or
input.traces.windows["60"] and input.traces.windows["1440"] for the last hour
and last day. LangGuard aggregates the windows your Rego references. See
Creating Policies for the input schema and patterns.
Per-trace token limits
To cap tokens on a single call regardless of cost, use a token-threshold policy
(the max_tokens_per_trace pattern in Creating Policies).
Next steps
- Cost Estimates — set per-model pricing
- Built-in Policies — the Budget Overrun policy
- Creating Policies — author custom budget rules