# Rate limits and how to retry a 429

> The LocalPipe API accepts 1,000 requests per rolling minute. What a 429 looks like, why you must retry it, and a throttling pattern to copy.
>
> Part of the LocalPipe API reference: https://www.localpipe.io/docs/rate-limits (full reference in one file: https://www.localpipe.io/localpipe-api-docs.md, categories CSV: https://www.localpipe.io/localpipe-business-categories.csv)

## Rate Limits

> ### ⚠️ CRITICAL: Cap your client at **1000 req/min**, then retry every 429
>
> The `/enrich` and `/maps-search` endpoints enforce a per-minute throughput limit. There is **no separate concurrent-request cap** — you can burst as many parallel submissions as you like as long as your rolling 60-second total stays under the limit.

### The limit

| Limit | Default | When you hit it | 429 `error` field | `Retry-After` |
|---|---|---|---|---|
| **Per-minute throughput** | 1000 requests / rolling minute | Sustained traffic above 1000/min | `rate_limit_minute` | **60 s** |

### What a 429 looks like

```json
{
  "error": "rate_limit_minute",
  "status": 429,
  "message": "Exceeded 1000 requests/minute",
  "retry_after": 60,
  "limits": { "per_minute": { "used": 1000, "limit": 1000 } }
}
```

### What you MUST do

1. **Cap throughput at ≤ 1000 req/min** (≈ 1 request every 60 ms). Do not rely on the server to slow you down.
2. **Retry every 429.** A 429 means **your call was not accepted** — if you don't retry, that record is silently lost. It never enters the queue, never triggers a webhook, and never appears in your usage logs. Use the `retry_after` value in the response body (or the `Retry-After` header) and resend the same payload.

Without retry logic, a 10K-record run can lose **30–50% of records invisibly**.

### Polling endpoints are excluded

`get-job-results`, `get-job-status`, and `get-scrape-results` do **not** count against the limit. Poll as often as you like.

### Other notes

- Enrichment credits are deducted only for requested data found. Maps search consumes business exports, not enrichment credits. Usage-billing accounts pay their applicable dollar rates instead.
- **Multi-title deduplication:** If you send multiple enrichment requests for the same business with different `decision_maker_title` values and the same contact person is found, you are only charged once.

### Reference: client-side throttling + retry pattern

```javascript
// ✅ CORRECT — throttles at ~920/min, retries every 429
const MIN_INTERVAL_MS = 65;      // ~920/min, safely under the 1000 ceiling

let lastSent = 0;

async function submitWithRetry(payload, attempt = 0) {
  // Throttle: never send faster than the per-minute ceiling
  const wait = Math.max(0, MIN_INTERVAL_MS - (Date.now() - lastSent));
  if (wait) await new Promise(r => setTimeout(r, wait));
  lastSent = Date.now();

  const res = await fetch(`${API_BASE}/enrich`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json', 'x-api-key': API_KEY },
    body: JSON.stringify(payload),
  });

  if (res.status === 429) {
    if (attempt >= 8) throw new Error('Rate limited after 8 retries');
    const body = await res.json().catch(() => ({}));
    const retryAfter = body.retry_after ?? Number(res.headers.get('Retry-After')) ?? 60;
    // Add jitter so retries don't synchronize and re-collide
    const jitter = Math.random() * 500;
    const backoff = (retryAfter * 1000) + (attempt * 1000) + jitter;
    await new Promise(r => setTimeout(r, backoff));
    return submitWithRetry(payload, attempt + 1);
  }

  if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
  return res.json();
}
```

**For n8n / Zapier / Make:** Set the HTTP node's "On Error → Retry on Fail" with at least 5 retries and a 60s wait between retries. **Do not** mark the workflow successful when a node returns 429 — that record was rejected and must be resubmitted.

## Rate Limiting Structure

To ensure stability during traffic spikes, the API implements tiered rate limits:

| Limit | Default | Applies To | Behavior |
|-------|---------|------------|----------|
| Per-minute | **1000 requests** | /enrich, /maps-search | Returns **429** with `Retry-After: 60` header — **client MUST retry** |
| Daily | **Unlimited** | All endpoints | No daily cap |
| Monthly | **Unlimited** | All endpoints | No monthly cap |

> **Why this matters:** 429s short-circuit before the request reaches the queue. They are **not logged in your usage analytics**. If your client doesn't retry, those records are lost — no job created, no webhook fired, no error visible in the dashboard.

**Polling endpoints are excluded from all rate limits:** get-job-results, get-job-status, and get-scrape-results do not count against your quota.

**Custom limits:** High-volume users can request increased per-minute limits by contacting support.
