Skip to content
← Changelog
2.2.145
Feature

Cap each key per minute, day or week

Each API key can now carry its own requests-per-minute cap and daily and weekly spend caps in US dollars, set from the key's settings.

Each API key can now carry its own requests-per-minute cap and its own daily and weekly spend caps. Give an agent or a CI job a key with its own ceiling: once it reaches a cap, its next request gets a 429 with Retry-After.

A key capped at 2 requests per minute: the third call in the same minute is answered 429 with Retry-After

Where to set them

Open the key's settings in API Keys. The three caps sit in the key's Limits & routing section, beside its hourly spend limit. Leave a field empty for no limit.

FieldWhat it capsResets
Requests per minuteRequests the key may start in a minuteEach minute
Spend limit per day (USD)What the key may spend in a UTC day00:00 UTC
Spend limit per week (USD)What the key may spend in a UTC weekMonday 00:00 UTC

Through the key API the same caps are rpm_limit, spend_limit_quota_per_day and spend_limit_quota_per_week; the two spend caps are in quota, where 1,000,000 quota is US$1, and 0 means no limit.

Each key keeps its own caps when you rename it, and a rotated key keeps the caps of the key it replaces.

The key's settings read back with a requests-per-minute cap and a daily and weekly spend cap

What a client sees past a cap

The request is refused with HTTP 429, a Retry-After header in seconds, and one of two codes:

Cap reachedError codeRetry-After value
Requests per minuteapi_key_rpm_limit_exceededSeconds until the minute allows another request
Daily or weekly spendapi_key_spend_limit_exceededSeconds until 00:00 UTC, or Monday 00:00 UTC for the week
HTTP/2 429
retry-after: 59

{
  "error": {
    "code": "api_key_rpm_limit_exceeded",
    "message": "This API key has reached its limit of 2 requests per minute. Retry after 59 seconds, or raise the limit in the key's settings. (request id: 202612011113524323700023651559)",
    "type": "rate_limit_error"
  }
}

Wait the Retry-After seconds, or raise the cap in the key's settings. Every limit a key can carry, and each refusal it can get, is listed in per-key limits and error codes.