EN ▾

Rate Limit in LLM APIs: Retry, Backoff and Real Costs

A rate limit in LLM APIs caps how many requests you can send per minute and how many can run at once. This page shows how to read those limits, retry correctly when you hit one, and price a batch job with real token math.

Updated

Glowing cubes metered through eight lanes, with waiting cubes looping back, showing API rate limits

Key points

  • Two separate limits apply: requests per minute (rate_limited) and simultaneous requests (concurrency).
  • A full key allows 8 concurrent requests and 300 per minute; a trial key allows 2 and 60.
  • Retry on HTTP 429 with exponential backoff, honor Retry-After, and add jitter.
  • Rejected and failed requests are not charged, so a retry costs time, not tokens.

The short answer

A rate limit in LLM services is a ceiling the provider puts on your key so that one client cannot starve the others. When you cross it, the server answers with HTTP 429 instead of a completion. Your code should treat 429 as "wait, then try again", not as a fatal error.

On this API the limits are fixed and small enough to remember:

Key typeConcurrent requestsRequests per minute
Full key8300
Trial key260

The maximum request body is 8 MB. Every response carries the headers X-Request-Id, X-Balance-USD, X-RateLimit-Limit-Requests and X-RateLimit-Limit-Concurrency, so you can read your ceilings straight from the traffic instead of hard-coding them.

Three kinds of 429

Not every 429 means the same thing, and the fix differs. The API distinguishes three cases.

  • rate_limited: you sent more than your requests-per-minute allowance. Slow the pace of new requests.
  • concurrency: too many requests are in flight at the same moment. Wait for some to finish, or lower the number of parallel workers.
  • Temporary overload: the service itself is busy. The response is a 429 with a Retry-After: 5 header. Wait that long and send again.

One detail catches people out: a streamed request holds its concurrency slot until the stream ends. If you open eight streams and your client reads them slowly, or never closes one after an error, the ninth request fails with concurrency even though your per-minute count is low. Always read a stream to the end or close it.

The limit applies to the key, not to a process. If you run four worker processes with the same key, they share the 8 slots and the 300-per-minute budget, so each worker must be configured for its share.

A retry loop that behaves

The OpenAI Python SDK retries a couple of times by default. That is fine for scripts, but for batch work you want to control the schedule yourself. Turn the built-in retries off and write one explicit loop:

import random
import time

from openai import OpenAI, RateLimitError

client = OpenAI(
    base_url="https://api.hereticllm.top/v1",
    api_key="YOUR_KEY",
    max_retries=0,
)

def ask(messages, attempts=6):
    delay = 5.0
    for attempt in range(attempts):
        try:
            resp = client.chat.completions.create(
                model="uncensored",
                messages=messages,
            )
            return resp.choices[0].message.content
        except RateLimitError as e:
            if attempt == attempts - 1:
                raise
            retry_after = e.response.headers.get("retry-after")
            wait = float(retry_after) if retry_after else delay
            time.sleep(wait + random.uniform(0, 1))
            delay = min(delay * 2, 60)

print(ask([{"role": "user", "content": "Give me three names for a fantasy tavern."}]))

Three rules are baked into that loop. First, a server-provided Retry-After wins over your own guess. Second, without a hint the delay doubles from 5 seconds up to a 60 second cap, which is enough to let a one-minute window roll over. Third, a random second of jitter keeps many workers from waking at the same instant and colliding again.

Do not retry everything. A 400 means your request is malformed, and a body over 8 MB will be rejected no matter how many times you resend it. Retry only on 429 and on network timeouts.

Stop hitting the limit: cap concurrency and pace starts

Retries clean up after a mistake. A better design avoids the mistake. Two small controls on the client keep you under both limits: a semaphore for concurrency and a pacer for requests per minute.

import asyncio
import random
import time

from openai import AsyncOpenAI, RateLimitError

aclient = AsyncOpenAI(
    base_url="https://api.hereticllm.top/v1",
    api_key="YOUR_KEY",
    max_retries=0,
)

gate = asyncio.Semaphore(8)  # use 2 on a trial key


class Pacer:
    def __init__(self, per_minute):
        self.gap = 60 / per_minute
        self.next = 0.0
        self.lock = asyncio.Lock()

    async def wait(self):
        async with self.lock:
            now = time.monotonic()
            delay = max(0.0, self.next - now)
            self.next = max(now, self.next) + self.gap
        if delay:
            await asyncio.sleep(delay)


pacer = Pacer(240)  # stay under 300 per minute; use 48 on a trial key


async def one(prompt, attempts=6):
    delay = 5.0
    for attempt in range(attempts):
        await pacer.wait()
        async with gate:
            try:
                r = await aclient.chat.completions.create(
                    model="uncensored",
                    messages=[{"role": "user", "content": prompt}],
                )
                return r.choices[0].message.content
            except RateLimitError as e:
                if attempt == attempts - 1:
                    raise
                ra = e.response.headers.get("retry-after")
                wait = float(ra) if ra else delay
        delay = min(delay * 2, 60)
        await asyncio.sleep(wait + random.uniform(0, 1))


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

Note that the retry sleep happens outside the semaphore. If you sleep while holding a slot, a backing-off task blocks work that could have run.

The pace is set to 80 percent of the ceiling on purpose: 240 of 300 and 48 of 60. A margin absorbs clock differences and the requests you send from other tools, such as a quick test in a terminal.

Which limit actually binds: worked throughput math

With 300 requests per minute you can start 5 requests per second. With 8 slots, each slot must finish and free up every 8 / 5 = 1.6 seconds to reach that rate. Few chat completions are that short. A completion that streams several hundred output tokens takes much longer, so in practice concurrency binds before the per-minute count does.

Take an assumed average of 10 seconds per request. This number is only for the calculation, not a measurement of the service. Eight slots finish 8 / 10 = 0.8 requests per second, which is 48 per minute. A job of 1,000 requests then needs 1,000 x 10 / 8 = 1,250 seconds, about 21 minutes. The 300 per minute ceiling never comes into play.

The trial key is similar. With 2 slots and the same 10 seconds, you finish 12 requests per minute, well below the 60 allowed. If your real latency is lower, scale the numbers; the method is the same: slots divided by seconds per request gives your true rate, and the lower of that and the per-minute limit is what you get.

It follows that shorter outputs speed up a batch more than a clever retry policy. Set max_tokens to what the task needs when you can, and ask for compact formats.

What a batch job costs, retries included

Pricing is pay as you go from prepaid credit: $0.15 per 1M input tokens and $0.50 per 1M output tokens. There is no subscription, and credit never expires. Failed or refused requests are not charged, so a request that returns 429 and is later retried costs you the tokens of the successful attempt only.

Here is a job of 1,000 requests, each with 2,000 input tokens and 500 output tokens.

  • Input: 1,000 x 2,000 = 2,000,000 tokens, so 2 x $0.15 = $0.30.
  • Output: 1,000 x 500 = 500,000 tokens, so 0.5 x $0.50 = $0.25.
  • Total: $0.55, or $0.00055 per request.

Even if 5 percent of requests hit a 429 on the first try, the bill stays at $0.55, because the rejected attempts carry no charge. What you pay for rate limits is wall-clock time, not money.

Scale it to your plan. A $20 top-up, the smallest amount, covers 20 / 0.00055, roughly 36,000 requests of that shape. Larger top-ups add a bonus: +5% from $50, +10% from $100 and +15% from $200, so $100 becomes $110 of credit. Any whole amount from $20 to $500 works, by crypto (USDT on TRC20, USDC on Base). See the pricing page for the full table.

The trial is smaller. The $0.50 credit covers about 909 requests of the shape above (0.50 / 0.00055), but a trial key runs 2 concurrent requests at 60 per minute, so treat it as a place to test your retry code, not to run the job.

Is there a free unlimited tier?

No. There is no free unlimited tier, and anyone selling one is paying for it somewhere else. What exists here is a one-time trial: new users can claim $0.50 of credit with one click on the API key page after signing up with Google or with email and password. It is valid for 7 days, needs no card, and is limited to one per person.

That small trial is enough to prove your integration works: send some requests, trigger a 429 on purpose by raising your parallelism past 2, and watch your backoff code recover. When the real job starts, top up and move to a full key with the larger limits. The documentation lists the endpoints and the headers mentioned above.

Quick checklist before a big run

  1. Set the semaphore to your concurrency limit and the pacer to about 80 percent of the per-minute limit.
  2. Disable the SDK's own retries and use one loop you can reason about.
  3. Honor Retry-After; otherwise double the delay up to 60 seconds with jitter.
  4. Close or finish every stream so slots are released.
  5. Log X-Request-Id for any failed call so you can reference it if you contact support.
  6. Watch X-Balance-USD so a long job does not stall on an empty balance.

Questions and answers

What HTTP status does a rate limit return?

HTTP 429. The error code is rate_limited for requests per minute and concurrency for too many requests at once. A temporary overload also returns 429 with a Retry-After: 5 header.

Do rejected requests cost money?

No. Failed or refused requests are not charged, so retrying after a 429 adds time but no token cost.

How do I raise my limits?

A full key runs 8 concurrent requests and 300 per minute, against 2 and 60 on a trial key. Top up from $20 to move from the trial to a full key.

Why do I get concurrency errors with a low request count?

A streamed request occupies its slot until the stream ends. Unclosed or slowly read streams keep slots busy, so finish or close each one.

Your key is one form away

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

Get API key