Rate limits
Limits on an API key
Section titled “Limits on an API key”You can give any API key a Requests per minute and a Tokens per minute limit when you create it on the API Key page. API keys covers how. These limits help, for example, when you don’t want one application to use up what another application on the same account needs.
We can also set per-key and per-account limits for the whole service. When both apply, the stricter limit is used. A key’s own limit can’t go above ours.
Tokens are counted when the request is accepted, as the estimated input plus the output cap (max_tokens). A request that stops early still counts its full output cap. If you keep hitting the token limit, lower max_tokens.
A refused request isn’t counted, so retrying after a refusal doesn’t keep the one-minute window full.
Concurrent requests per key
Section titled “Concurrent requests per key”A key can also have a Requests at once limit: how many of its requests may run at the same time. Through the API, set concurrent_requests when you create the key (see Account and keys). It helps when you serve customers of your own with one key each: one customer’s big batch doesn’t take all the capacity the others need.
A request counts from when it starts running until its answer is complete, including a stream until it ends or the connection drops. A request over the limit is refused with 429 key_concurrency_limit_exceeded and Retry-After: 1. GET /v1/key shows the limit (rate_limit.concurrent_requests) and how many of the key’s requests are running (rate_limit.requests_in_flight).
This limit sits under the account’s and the routes’ limits, so a request still under its key’s limit can get concurrency_limit_exceeded or all_routes_saturated.
When a limit is exceeded
Section titled “When a limit is exceeded”The request is refused with 429 rate_limit_exceeded and a Retry-After header with the number of seconds until there’s room again:
HTTP/1.1 429 Too Many RequestsRetry-After: 12
{"error": {"message": "too many requests; this key or account is over its per-minute limit", "type": "api_error", "code": "rate_limit_exceeded", "param": null}}Wait for Retry-After, then send the request again.
Concurrent image, audio and video requests
Section titled “Concurrent image, audio and video requests”Image, speech, transcription and video models are limited by how many requests run at the same time, not per minute. Each account may run this many at once, by its tier on the API Key page:
| Tier | Image and audio requests | Videos being made |
|---|---|---|
| 1 | 4 | 2 |
| 2 | 8 | 4 |
| 3 | 16 | 8 |
| 4 | 32 | 16 |
On top of that, one account may hold at most a quarter of a single model’s capacity (at least one request), so one busy account can’t take every slot from everyone else.
An image or audio request over either limit is refused with 429 concurrency_limit_exceeded and Retry-After: 1. Send it again when one of your own requests finishes.
A video over the limit isn’t refused. It’s accepted with our own id and status: "queued", its cost is held, and it starts as soon as one of your videos finishes. A video that waits more than an hour fails with error.code queue_timeout, and its hold is released. An account may have twice its video limit waiting; past that the next one is refused with 429 video_queue_full.
Limits per IP address
Section titled “Limits per IP address”Two more limits apply per IP address rather than per key:
- Requests with a wrong or missing API key are limited per minute. Going over gets
429 too_many_requestswithRetry-After. Requests with a valid key don’t count toward this one. GET /v1/models, which can be read without a key, has its own per-minute limit.
Provider limits
Section titled “Provider limits”Each provider limits requests to its models too. When one route is being limited, we try another route for the same model, as long as no part of the answer has reached you yet. You only get an error when no route can take the request:
code |
What it means |
|---|---|
all_routes_saturated |
Every route for this model is busy. Try again after 1 second (Retry-After: 1). |
vendor_daily_limit_reached |
The vendor’s daily request limit for this model is used up. Retry-After carries the time until it resets. |
rate_limited |
The provider is limiting requests to this model. Try again after 5 seconds (Retry-After: 5), and wait longer if it’s refused again. |
We don’t send remaining-quota headers such as x-ratelimit-remaining. Other errors are on Error codes.