Skip to main content

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.
ComponentDescriptionExample
MeterWhat to measureA meter that sums tokens
Limit ValueMaximum allowed100000
PeriodTime windowhour, day, week, month, all_time
CustomerWho it applies tocust_123

How Limits Work

Limits are linked to meters. When you check a limit, Limitry:
  1. Finds the meter associated with the limit
  2. Calculates the meter’s current value for the customer
  3. 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

PeriodResets
hourEvery hour on the hour (UTC)
dayMidnight in customer’s timezone
weekMonday midnight in customer’s timezone
monthSame day of month as customer’s billingCycleStart
annualSame month/day as customer’s billingCycleStart
all_timeNever 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
    }
  ]
}
FieldDescription
limitThe maximum allowed value
usedCurrent usage in this period
remainingHow much is left (limit - used)
exceededWhether usage exceeds the limit
resetUnix timestamp when the period resets (null for all_time)