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

# Rate Limits

> Understand how rate limits work on the First Answer API and how to handle them gracefully.

## How It Works

The First Answer API enforces rate limits **per project** on a **per-minute** sliding window. All API keys within the same project share the same rate limit counter.

The rate limit for your project is determined by your plan.

## Rate Limit Headers

Every API response includes headers to help you track your usage:

| Header                  | Description                                                             |
| ----------------------- | ----------------------------------------------------------------------- |
| `X-RateLimit-Limit`     | Maximum requests allowed per minute                                     |
| `X-RateLimit-Remaining` | Requests remaining in the current window                                |
| `Retry-After`           | Seconds to wait before making another request (only on `429` responses) |

## Exceeding the Limit

When you exceed your rate limit, the API returns a `429 Too Many Requests` response:

```json 429 theme={null}
{
  "error": {
    "code": "RATE_LIMIT_EXCEEDED",
    "message": "Rate limit exceeded.",
    "retry_after_seconds": 23
  }
}
```

The `retry_after_seconds` field tells you exactly how many seconds to wait before retrying.

## Handling Rate Limits

### Retry with Backoff

The simplest approach is to respect the `retry_after_seconds` value:

<CodeGroup>
  ```python Python theme={null}
  import time
  import requests

  API_KEY = "YOUR_API_KEY"
  BASE_URL = "https://api.firstanswer.ai/v1"

  def api_request(endpoint):
      response = requests.get(
          f"{BASE_URL}{endpoint}",
          headers={"api-key": API_KEY},
      )

      if response.status_code == 429:
          retry_after = response.json()["error"]["retry_after_seconds"]
          print(f"Rate limited. Retrying in {retry_after}s...")
          time.sleep(retry_after)
          return api_request(endpoint)

      return response.json()
  ```

  ```javascript JavaScript theme={null}
  const API_KEY = "YOUR_API_KEY";
  const BASE_URL = "https://api.firstanswer.ai/v1";

  async function apiRequest(endpoint) {
    const response = await fetch(`${BASE_URL}${endpoint}`, {
      headers: { "api-key": API_KEY },
    });

    if (response.status === 429) {
      const { error } = await response.json();
      const retryAfter = error.retry_after_seconds;
      console.log(`Rate limited. Retrying in ${retryAfter}s...`);
      await new Promise((r) => setTimeout(r, retryAfter * 1000));
      return apiRequest(endpoint);
    }

    return response.json();
  }
  ```
</CodeGroup>

### Spread Requests Over Time

If you need to make many requests, spread them evenly within your rate limit window instead of sending them in bursts:

```python theme={null}
import time
import requests

API_KEY = "YOUR_API_KEY"
BASE_URL = "https://api.firstanswer.ai/v1"
RATE_LIMIT = 10  # requests per minute
DELAY = 60 / RATE_LIMIT  # 6 seconds between requests

endpoints = [
    "/brands/",
    "/monitored-prompts/",
    "/cited-sources/",
    "/monitored-competitors/",
    "/dashboard/",
]

for endpoint in endpoints:
    response = requests.get(
        f"{BASE_URL}{endpoint}",
        headers={"api-key": API_KEY},
    )
    print(f"{endpoint}: {response.status_code}")
    time.sleep(DELAY)
```

## Best Practices

<CardGroup cols={2}>
  <Card title="Cache responses" icon="database">
    Store API responses locally and reuse them when the data hasn't changed. Most monitoring data updates on a daily or weekly basis.
  </Card>

  <Card title="Use pagination wisely" icon="list">
    Each page returns up to 100 items by default. Use the `page` and `per_page` parameters to control page size and iterate through results efficiently.
  </Card>

  <Card title="Request only what you need" icon="filter">
    Target specific endpoints and resources rather than fetching everything on every sync.
  </Card>

  <Card title="Monitor your usage" icon="chart-line">
    Track `429` responses in your application logs to identify when you're approaching your limits.
  </Card>
</CardGroup>

## Need Higher Limits?

If your integration requires a higher rate limit, [contact our team](mailto:support@firstanswer.ai) to discuss Enterprise plans with custom limits.
