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.

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.
| Field | What it caps | Resets |
|---|---|---|
| Requests per minute | Requests the key may start in a minute | Each minute |
| Spend limit per day (USD) | What the key may spend in a UTC day | 00:00 UTC |
| Spend limit per week (USD) | What the key may spend in a UTC week | Monday 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.

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 reached | Error code | Retry-After value |
|---|---|---|
| Requests per minute | api_key_rpm_limit_exceeded | Seconds until the minute allows another request |
| Daily or weekly spend | api_key_spend_limit_exceeded | Seconds 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.