EN ▾
Get API key

OpenAI API Rate Limit: How Limits Work and What to Do

Every OpenAI-style API caps how fast you can call it. Here is how requests per minute and concurrency differ, what a 429 means, and the exact limits on this API.

Updated

Isometric gate with eight lanes letting request cubes through one at a time to show concurrency limits

Key points

  • There are two separate caps: requests per minute and requests running at the same time.
  • A full key here allows 8 concurrent requests and 300 per minute; a trial key allows 2 and 60.
  • A 429 error is a signal to slow down, not a failure; retry with a short wait and jitter.
  • A streamed request holds its concurrency slot until the stream ends.

What a rate limit actually is

An openai api rate limit is a cap on how much traffic one key can send in a given time. Providers that follow the OpenAI format all work the same way at the HTTP level: if you go over, the server answers with status 429 instead of a completion, and your code is expected to wait and try again. Exact numbers differ by provider and by account tier, so for any specific service you need to read its own documentation. Check the current limits of the vendor you use, because they change.

The limit exists to protect shared hardware. A language model runs on a fixed amount of GPU memory, and each live request takes a piece of it. Without caps, one script in a tight loop could slow everybody down. For you as a developer, the practical point is simple: design the client so that a 429 is a normal event it can handle quietly.

It helps to separate three kinds of failure that people lump together. A 429 means you are too fast, and waiting fixes it. A 401 means the key is wrong, and waiting never fixes it. A 5xx means the server had a problem, and a retry may or may not help. Treat these three differently in code: retry the first, stop on the second, and retry the third a limited number of times.

This article uses the limits of this API as the worked example, since those are the numbers we can state. The same ideas apply to any compatible endpoint.

Two limits, not one

People often mix up two different caps. They fail in different ways and need different fixes.

LimitWhat it countsFull keyTrial key
Requests per minuteHow many requests you start in a rolling minute30060
ConcurrencyHow many requests are open at the same moment82

Requests per minute is about rate. Concurrency is about overlap. You can break the second without coming near the first. Suppose each of your requests takes 20 seconds to finish, which is normal for a long answer. Ten workers sending at once use 10 slots, which is over the full-key cap of 8, even though that is only a few requests per minute.

It works in the other direction too. Very short requests, such as classification calls that return a single word, finish quickly, so concurrency stays low but the per-minute count climbs fast. A script that sends 400 tiny requests in a minute will hit the rate cap on a full key with room to spare on concurrency.

The practical ceiling

Your real throughput is the lower of two numbers. The first is 300 requests per minute, which is 5 per second. The second is the concurrency cap divided by the average request time. With 8 slots and an average request of 10 seconds, you get 8 / 10 = 0.8 requests per second, or 48 per minute. In that case concurrency is the bottleneck, and sending faster just produces errors. With an average of 1 second, the second number is 8 per second, so the 300-per-minute cap binds instead.

What the errors look like

Over a limit, this API returns HTTP 429 with an error code that tells you which limit you hit.

  • rate_limited means too many requests per minute.
  • concurrency means too many requests running at once.
  • A 429 with a Retry-After: 5 header means temporary overload on the service side. Wait that many seconds.

Every response also carries headers you can log: X-Request-Id, X-Balance-USD, X-RateLimit-Limit-Requests and X-RateLimit-Limit-Concurrency. The request ID is the one to quote if you contact support. The limit headers let a client adjust to its own key instead of hard-coding 300 or 8.

Failed or refused requests are not charged, so retrying after a 429 costs you nothing extra. You only pay for requests that complete.

Handling 429 in Python

The usual advice is exponential backoff with jitter: wait a little, then longer, and add a random amount so many workers do not retry in the same instant. If the server gives a Retry-After value, use it first. This example uses the openai Python SDK pointed at this API.

import random
import time
from openai import OpenAI, RateLimitError

client = OpenAI(
    base_url="https://api.openainsfw.top/v1",
    api_key="YOUR_KEY",
    max_retries=0,  # we handle retries ourselves
)

def ask(prompt, attempts=6):
    delay = 1.0
    for attempt in range(attempts):
        try:
            resp = client.chat.completions.create(
                model="uncensored",
                messages=[{"role": "user", "content": prompt}],
            )
            return resp.choices[0].message.content
        except RateLimitError as err:
            retry_after = err.response.headers.get("retry-after")
            wait = float(retry_after) if retry_after else delay
            wait += random.uniform(0, 0.5)
            print(f"429, waiting {wait:.1f}s (attempt {attempt + 1})")
            time.sleep(wait)
            delay = min(delay * 2, 30)
    raise RuntimeError("still rate limited after retries")

The SDK retries a couple of times on its own by default. Setting max_retries=0 here makes the behavior visible while you learn; in production you can keep the built-in retries and add your own layer only for long waits.

Keeping concurrency under the cap

Retrying works, but it is wasteful to send requests you already know will be refused. If you process a batch, bound the number of requests in flight on your side. A semaphore does this in a few lines.

import asyncio
from openai import AsyncOpenAI

client = AsyncOpenAI(base_url="https://api.openainsfw.top/v1", api_key="YOUR_KEY")
gate = asyncio.Semaphore(6)  # stay under 8, leave headroom

async def one(prompt):
    async with gate:
        r = await client.chat.completions.create(
            model="uncensored",
            messages=[{"role": "user", "content": prompt}],
            max_tokens=300,
        )
        return r.choices[0].message.content

async def main(prompts):
    return await asyncio.gather(*(one(p) for p in prompts))

Six slots instead of eight leaves room for a second script or a manual test using the same key. On a trial key, set the gate to 1 or 2.

Streaming and slots

A streamed request (stream: true) keeps its slot for as long as the stream is open. A slow reader, such as a UI that renders a word at a time or a client that forgets to close the connection, ties up capacity. Always consume the stream to the end or cancel it explicitly. If a chat bot serves many users, remember that each active reply uses one of the 8 slots, so a busy bot needs a queue in front of the API.

Planning for bots and apps

For a Discord bot, a roleplay frontend or a small app, a few design choices matter more than clever retry code.

  • Queue first. Put incoming requests in a queue and let a fixed number of workers pull from it. Users wait a moment instead of seeing an error.
  • Lower the output cap. A shorter max_tokens means each request finishes sooner and frees its slot sooner, which raises throughput without changing any limit.
  • Do not retry forever. After four to six attempts, tell the user the service is busy.
  • Use the right key for the job. A trial key is meant for testing. The 2 concurrent requests are enough for one person, not for a public bot.

The model has a 100,000-token context window and the maximum request body is 8 MB. These are separate from the rate limits, and a request that is too large fails on its own terms. Cost scales with tokens: at $0.15 per 1M input tokens and $0.50 per 1M output tokens, a job of 2M input tokens and 300,000 output tokens costs $0.30 + $0.15 = $0.45. See pricing for top-up amounts and bonuses, and the docs for the full parameter list.

Questions and answers

What are the rate limits on this API?

A full key allows 8 concurrent requests and 300 requests per minute. A trial key allows 2 concurrent requests and 60 per minute.

What is the difference between rate_limited and concurrency?

rate_limited means you sent too many requests in a minute. concurrency means too many requests were open at the same time, which often happens with long or streamed replies.

Do I pay for requests that return 429?

No. Failed or refused requests are not charged, so retrying costs nothing extra until one completes.

How long should I wait before retrying?

If the response has a Retry-After header, wait that long, which is 5 seconds for temporary overload. Otherwise start at about one second and double the wait on each attempt, with a little random jitter.

Can I get a higher limit?

The documented limits for a full key are 8 concurrent requests and 300 per minute. If your project needs more, ask through the support page.

Your key is one form away

Create an account, copy the key, change the base URL. That is the whole setup.

Get API key