Why use budget limiting?
- Prevent runaway costs from bugs, infinite loops, or unexpected high-volume usage
- Enforce budget allocations for teams, users, or projects
- Get alerts when usage approaches limits
- Track spending with real-time usage monitoring
Configuration Structure
How It Works
- Each request is evaluated against the first matching rule based on the
whenconditions - If the matching rule exceeds its limit →
Request is REJECTED - If the matching rule is within limits →
Request is ALLOWED
Rule Components
1. Rule ID (id)
Unique identifier for the rule. Used in logs, metrics, and API responses.
2. Rule Conditions (when)
Defines which requests the rule applies to. All conditions use AND logic.
Available Filters:
-
subjects: Filter by users, teams, or virtual accounts -
models: Filter by model names -
metadata: Filter by custom metadata fromX-TFY-METADATAheader
3. Budget Limit (limit_to + unit)
Defines the spending limit and time period.
Supported Units:
cost_per_day- Daily budget limitcost_per_week- Weekly budget limitcost_per_month- Monthly budget limit
Budget Periods:
- Daily: Resets at UTC midnight
- Weekly: Resets on Monday at UTC midnight
- Monthly: Resets on the 1st of each month at UTC midnight
4. Budget Applies Per (budget_applies_per) - Optional
Creates separate budget instances for each unique value of the specified entity. This allows you to set individual budget limits for each user, model, or other entity without creating separate rules.
How it works:
Without budget_applies_per: One budget limit applies to all matching requests- Example: All users share a single $1000 daily budget
With budget_applies_per: ['user']: A separate budget is created for each user- Example: User Alice has a 500 Dollar daily budget, User Bob has a separate 500 Dollar daily budget
With budget_applies_per: ['model']: A separate budget is created for each modelWith budget_applies_per: ['metadata.project_id']: A separate budget is created for each project ID value
user- One budget per uservirtualaccount- One budget per virtual accountmodel- One budget per modelmetadata.*- One budget per custom metadata value (replace*with your metadata key)
Example: If you set
limit_to: 500 and budget_applies_per: ['user']:- User Alice has a $500 daily budget
- User Bob has a separate $500 daily budget
- Each user’s usage is tracked independently
Budget Alerts
Budget alerts notify you when usage crosses specified thresholds, helping you stay informed and take action before limits are exceeded.Alert Configuration
Alert Thresholds
Select from the available percentage thresholds at which alerts should be triggered.- Available thresholds:
75,90,95,100 - One-time per period: Each threshold triggers once per budget period


Notification Channels
Choose how you want to receive budget alerts: Email Notifications:Alert Behavior
- Automatic checking: Alerts are checked every 20 minutes
- Period-based: Each threshold alert is sent once per budget period
- Reset on new period: When a new period starts (day/week/month), alerts reset and can be sent again
Viewing Budget Usage
You can monitor budget usage directly on the budget configuration page. Each rule card displays:- Current usage amount and percentage
- Budget limit and remaining budget
- Period start time (when the current budget period began)
budget_applies_per, you can see usage breakdown for each rule.

Examples
Basic Budget Rules
Basic Budget Rules
Simple budget rules for specific users, teams, or virtual accounts.
Per-Entity Budgets
Per-Entity Budgets
Automatically create separate budgets for each user, model, or metadata value.
When using
budget_applies_per: ['metadata.project_id'], include X-TFY-METADATA: {"project_id": "proj-123"} in requests.Budgets with Alerts
Budgets with Alerts
Configure notifications when budget usage crosses thresholds.
Complex Scenarios
Complex Scenarios
Advanced configurations combining multiple filters and features.