What is a Limit?
A limit caps usage over a time period. When the limit is reached, subsequent requests are blocked until the period resets.
| Component | Description | Example |
|---|
| Meter | What to measure | A meter that sums tokens |
| Limit Value | Maximum allowed | 100000 |
| Period | Time window | hour, day, week, month, all_time |
| Customer | Who it applies to | cust_123 |
How Limits Work
Limits are linked to meters. When you check a limit, Limitry:
- Finds the meter associated with the limit
- Calculates the meter’s current value for the customer
- Compares against the limit value
Creating Limits
First, create a meter, then create a limit that references it:
# 1. Create a meter to sum tokens
meter = client.meters.create(
name="Total Tokens",
event_type="llm.completion",
aggregation="sum",
value_key="tokens"
)
# 2. Create a limit using that meter
limit = client.limits.create(
name="Daily token limit",
meter_id=meter.id,
limit_value=100000,
period="day",
customer_id="cust_123"
)
Periods
| Period | Resets |
|---|
hour | Every hour on the hour (UTC) |
day | Midnight in customer’s timezone |
week | Monday midnight in customer’s timezone |
month | Same day of month as customer’s billingCycleStart |
annual | Same month/day as customer’s billingCycleStart |
all_time | Never resets (lifetime limit) |
For month and annual periods, the reset date is anchored to the customer’s billingCycleStart. For example, if a customer’s billing started on March 15, their monthly period runs from the 15th to the 14th of the following month.
Lifetime Limits
Use all_time for limits that should never reset:
# Limit total agents a customer can create
limit = client.limits.create(
name="Max agents",
meter_id=agent_count_meter.id,
limit_value=10,
period="all_time",
customer_id="cust_123"
)
Dimension Filters
Apply limits to specific subsets of events by filtering on dimensions:
# Limit only GPT-4 usage
limit = client.limits.create(
name="GPT-4 daily limit",
meter_id=token_meter.id,
limit_value=50000,
period="day",
customer_id="cust_123",
dimension_filters={"model": "gpt-4"}
)
Alert Thresholds
Get notified when limits reach certain levels:
limit = client.limits.create(
name="Daily token limit",
meter_id=meter.id,
limit_value=100000,
period="day",
customer_id="cust_123",
alert_thresholds=[80, 100] # Alert at 80% and 100%
)
Checking Limits
Check if a customer is within their limits:
result = client.limits.check(customer_id="cust_123")
if result.allowed:
print("Request allowed!")
else:
print("Limit exceeded")
for limit in result.limits:
print(f"{limit.name}: {limit.used}/{limit.limit} ({limit.remaining} remaining)")
Check Response
The check response includes details about all matching limits:
{
"allowed": true,
"limits": [
{
"id": "lmt_abc123",
"name": "Daily token limit",
"meterId": "mtr_xyz789",
"period": "day",
"limit": 100000,
"used": 45000,
"remaining": 55000,
"exceeded": false,
"reset": 1704153600
}
]
}
| Field | Description |
|---|
limit | The maximum allowed value |
used | Current usage in this period |
remaining | How much is left (limit - used) |
exceeded | Whether usage exceeds the limit |
reset | Unix timestamp when the period resets (null for all_time) |