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

# Rate limits

> How many API requests a key and a workspace can make each minute, the headers that show what is left, and how to back off on a 429.

The API limits requests per minute in two ways: per API key, and per workspace across all keys together. Generation and change calls also have a tighter window.

## Limits

| Scope | All calls | Generation and change calls |
| - | - | - |
| Per key, each minute | 120 | 20 |
| Per workspace, all keys together, each minute | 300 | 40 |

**Generation and change calls** are:

* `POST .../posts/generate` and `POST .../posts/generate-batch`
* `POST .../carousels` and `POST .../carousels/{id}/changes`
* `POST .../infographics` and `POST .../infographics/{id}/edit`

Such a call counts toward the general window **and** the generation window. Job reads (`GET /jobs/{jobId}`) and job streams count toward the key and workspace general windows.

Account calls that have no workspace in the path (`/key`, `/credits`, `/carousel-templates`) count against the per-key window only.

## Headers

Calls to the API answer with these headers:

| Header | Meaning |
| - | - |
| `RateLimit-Limit` | The size of the window that is closest to running out. |
| `RateLimit-Remaining` | Calls left in that window. |
| `RateLimit-Reset` | Seconds until it resets. |
| `Retry-After` | On a `429` only: seconds to wait before you retry. |

When more than one window applies, the headers show the one with fewer calls left. For example, a generation call right after you started shows `RateLimit-Limit: 20`, the generation window.

```http
HTTP/1.1 200 OK
RateLimit-Limit: 120
RateLimit-Remaining: 119
RateLimit-Reset: 60
X-Request-Id: req_fn2x5hKvjNmFUdZH
```

## When you hit a limit

The API answers `429` with code `rate_limited` and a `Retry-After` header:

```http
HTTP/1.1 429 Too Many Requests
RateLimit-Limit: 120
RateLimit-Remaining: 0
RateLimit-Reset: 10
Retry-After: 10
```

```json
{
  "error": {
    "code": "rate_limited",
    "message": "Too many requests. Try again soon.",
    "details": { "retryAfterSeconds": 10, "scope": "api_apiKey" }
  }
}
```

Wait `Retry-After` seconds, then retry. For calls that spend credits, retry with the **same** `Idempotency-Key`. A call refused with `429` did not run and was not charged. Spread large batches over time instead of sending them at once.

```javascript
async function withBackoff(doFetch, tries = 5) {
  for (let attempt = 1; ; attempt++) {
    const res = await doFetch();
    if (res.status !== 429 || attempt >= tries) return res;
    const wait = Number(res.headers.get("Retry-After")) || 2 ** attempt;
    await new Promise((r) => setTimeout(r, wait * 1000));
  }
}
```

## The limiter fails closed

If PostChamp cannot reach its rate-limit store, it refuses the call with `429 rate_limited` and a `Retry-After` of 60 seconds ("This is busy right now. Try again in a minute.") instead of letting it through. Retry after the delay.

## Open streams

A key can hold a limited number of open job streams at a time. Past it the stream request answers `429 rate_limited` with `Retry-After: 5`. Close a stream you no longer need. See [Jobs and streaming](/api/jobs-and-streaming.md).

## Other limits are separate

These are not request limits, and they have their own errors:

* **Credits.** A call without enough credits answers `402 insufficient_credits`. Nothing is charged.
* **Plan and daily caps.** Daily caps on images and carousels, and a plan without API access, answer `403 plan_limit`.
* **One carousel at a time.** A second carousel while one is being drawn answers `409 carousel_in_progress`.

See [Errors](/api/errors.md) and [Plans and credits](/plans-and-credits.md).

> [card] [Idempotency](/api/idempotency.md)
>
> Retry safely after a 429.

> [card] [Errors](/api/errors.md)
>
> All codes.
