> ## Documentation Index
> Fetch the complete documentation index at: https://docs.primalabs.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Rate limits

> The three limits in front of every request, and how to handle them.

Requests pass through **three independent limits**. Any one of them can return a `429`
(or, at the network edge, a `403`). Handle them the same way: back off and retry with
jitter, honoring `Retry-After` when it is present.

## 1. Per-IP (network)

A per-IP rate limit at the edge protects the platform from abuse and floods. It is coarse
and applies before authentication. Spreading legitimate traffic across a few connections
and backing off on rejection is enough to stay under it.

## 2. Per-user fair share

Each account gets a **fair share** of a model's serverless capacity, measured in requests
per minute. The share adapts to how many accounts are active on that model, so no single
account can starve the pool. Sustained bursts above your share are throttled with a `429`.

If you need a higher guaranteed share, dedicated capacity is available —
[contact us](https://primalabs.ai/book-demo).

## 3. Per-model admission

Each model has an **admission** controller with a maximum number of concurrent requests
and a bounded queue. When a model is saturated, new requests queue up to the limit and are
then rejected with a `429` (or `503` if there is no healthy capacity at that instant).
This protects latency for in-flight requests rather than accepting work a busy model
cannot serve promptly.

## Handling 429s

<CodeGroup>
  ```python Python theme={null}
  import time, random
  from openai import OpenAI, RateLimitError

  client = OpenAI(base_url="https://api.primalabs.ai/v1", api_key="YOUR_API_KEY")

  def with_retry(**kwargs):
      for attempt in range(5):
          try:
              return client.chat.completions.create(**kwargs)
          except RateLimitError:
              time.sleep(min(2 ** attempt, 30) + random.random())
      raise RuntimeError("still rate limited after retries")
  ```

  ```javascript Node theme={null}
  import OpenAI from "openai";
  const client = new OpenAI({ baseURL: "https://api.primalabs.ai/v1", apiKey: "YOUR_API_KEY" });

  async function withRetry(params) {
    for (let attempt = 0; attempt < 5; attempt++) {
      try {
        return await client.chat.completions.create(params);
      } catch (err) {
        if (err.status !== 429) throw err;
        const wait = Math.min(2 ** attempt, 30) * 1000 + Math.random() * 1000;
        await new Promise((r) => setTimeout(r, wait));
      }
    }
    throw new Error("still rate limited after retries");
  }
  ```
</CodeGroup>

<Tip>
  Exponential backoff **with jitter** is what keeps a fleet of clients from retrying in
  lockstep and re-saturating the model the instant it recovers.
</Tip>
