# Rate limits

How FineProxy limits API and MCP request rates, which headers report your budget, and how to pace, batch and back off so your integration never stalls on 429 errors.

- Canonical: https://fineproxy.org/developers/docs/rate-limits/

The FineProxy API limits how fast you can send requests. This page explains the rate-limit headers, the pace that works in practice, and how to back off when you hit `429 Too Many Requests`.

## Rate-limit headers

Every REST response carries three rate-limit headers and a request ID:

| Header | Example | Meaning |
| --- | --- | --- |
| `x-ratelimit-limit` | `600` | Requests allowed in the current window |
| `x-ratelimit-remaining` | `536` | Requests left in the current window |
| `x-ratelimit-reset` | `1795772660` | When the window resets, as a Unix timestamp in seconds |
| `x-request-id` | `0123456789abcdef0123456789abcdef` | ID of this request — include it when you contact support |

Read the headers from any response:

```bash
curl -s -D - -o /dev/null https://fineproxy.org/account_new/api/v1/customer/wallet/balance \
  -H "Authorization: Bearer $FINEPROXY_API_KEY" | grep -i '^x-'
```

## Practical limits

Besides the window budget, the API rejects short bursts. In practice, sending more than about **2 requests per second** returns:

```json
{
  "detail": "Too Many Requests"
}
```

with status `429`. Design your integration around these rules:

- Keep a steady pace of **at most 2 requests per second**.
- If several workers, scripts or AI agents use the same API key, pace them together rather than each on its own.
- Watch `x-ratelimit-remaining`; when it approaches zero, wait until `x-ratelimit-reset`.
- Treat `429` as a normal, recoverable response: back off and retry.

## Back off with jitter

When you get a `429` (or a `503`), wait before retrying and increase the delay on each attempt. Add random jitter so that parallel workers do not retry in lockstep. If the window is exhausted (`x-ratelimit-remaining: 0`), wait until `x-ratelimit-reset` instead.

```javascript
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

function retryDelayMs(res, attempt) {
  const remaining = Number(res.headers.get('x-ratelimit-remaining'));
  const reset = Number(res.headers.get('x-ratelimit-reset'));
  if (remaining === 0 && reset) {
    const untilReset = reset * 1000 - Date.now();
    if (untilReset > 0) return untilReset + Math.random() * 1000;
  }
  const base = Math.min(30_000, 1000 * 2 ** attempt); // 1 s, 2 s, 4 s ... capped at 30 s
  return base / 2 + Math.random() * (base / 2);
}

export async function fetchWithBackoff(url, options = {}, maxRetries = 5) {
  for (let attempt = 0; ; attempt++) {
    const res = await fetch(url, {
      ...options,
      headers: { Authorization: `Bearer ${process.env.FINEPROXY_API_KEY}`, ...options.headers },
    });
    if ((res.status !== 429 && res.status !== 503) || attempt >= maxRetries) return res;
    await sleep(retryDelayMs(res, attempt));
  }
}
```

```python
import os
import random
import time

import requests


def retry_delay(res, attempt):
    remaining = res.headers.get("x-ratelimit-remaining")
    reset = res.headers.get("x-ratelimit-reset")
    if remaining == "0" and reset:
        until_reset = int(reset) - time.time()
        if until_reset > 0:
            return until_reset + random.random()
    base = min(30, 2 ** attempt)  # 1 s, 2 s, 4 s ... capped at 30 s
    return base / 2 + random.random() * base / 2


def request_with_backoff(method, url, max_retries=5, **kwargs):
    headers = {"Authorization": f"Bearer {os.environ['FINEPROXY_API_KEY']}", **kwargs.pop("headers", {})}
    for attempt in range(max_retries + 1):
        res = requests.request(method, url, headers=headers, timeout=60, **kwargs)
        if res.status_code not in (429, 503) or attempt == max_retries:
            return res
        time.sleep(retry_delay(res, attempt))
```

> **Important:** Retry a `POST` that spends money only if it carries an idempotency key, and reuse the same key on every attempt. See [Idempotency & price guards](/developers/docs/idempotency/).

## Pace requests

Backoff handles occasional `429`s; a pacer prevents them. The simplest pacer enforces a minimum interval between requests from one process:

```javascript
const MIN_INTERVAL_MS = 500; // 2 requests per second
let nextSlot = 0;

export async function paced(fn) {
  const now = Date.now();
  const wait = Math.max(0, nextSlot - now);
  nextSlot = Math.max(now, nextSlot) + MIN_INTERVAL_MS;
  if (wait) await new Promise((resolve) => setTimeout(resolve, wait));
  return fn();
}

// await paced(() => fetchWithBackoff(url));
```

```python
import threading
import time

MIN_INTERVAL = 0.5  # 2 requests per second
_lock = threading.Lock()
_next_slot = 0.0


def paced(fn, *args, **kwargs):
    global _next_slot
    with _lock:
        now = time.monotonic()
        wait = max(0.0, _next_slot - now)
        _next_slot = max(now, _next_slot) + MIN_INTERVAL
    if wait:
        time.sleep(wait)
    return fn(*args, **kwargs)


# paced(request_with_backoff, "GET", url)
```

## Reduce the number of requests

- **Use large pages.** List endpoints accept `limit` up to 100 (services, catalog) or 200 (ledger). One request with `limit=200` replaces many small ones. See [Pagination](/developers/docs/conventions/#pagination).
- **Order mixes in one call.** A composite order takes several country segments at once; you do not need one order per country.
- **Swap allowlist entries atomically.** `POST .../proxy/whitelist/replace` changes an IP in one call instead of a delete plus an add.
- **Cache what rarely changes.** Proxy IPs, credentials and endpoints change only when you refresh or add IPs, or rotate credentials — read them once and reuse them.
- **Use webhooks instead of polling** for wallet and payment events. See [Webhooks](/developers/docs/api/webhooks/).
- **Poll slowly when you must.** A new datacenter order can have its IPs active within seconds; poll `GET /api/v1/customer/services/{service_id}` every few seconds, not in a tight loop.

## MCP rate limits

The MCP endpoint is rate-limited too. Bursts — for example, many `initialize` calls in a row, or several agents calling tools in parallel with the same key — return HTTP `429` with `{"detail": "Too Many Requests"}`. This is a transport-level HTTP error, not a JSON-RPC error or a tool result with `isError`.

If you build your own MCP client, apply the same backoff as for REST. If an AI client reports `429`, wait a few seconds and ask the agent to continue. See [MCP protocol details](/developers/docs/mcp/protocol/).

## Next steps

- [Errors](/developers/docs/errors/) — the full list of statuses and what to do.
- [Idempotency & price guards](/developers/docs/idempotency/) — make retries safe.
