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

> ## Agent Instructions
> CrispStats is a hosted, privacy-first web analytics product. It has no self-hosted edition, no session replay, no heatmaps, no A/B testing, no mobile SDKs and no data import except a site's history from a Plausible export (Settings, Import and export).
> The script global is crispstats(...), site keys start with cs_pk_ and secret API keys start with cs_sk_. The script is served from https://in.crispstats.com/d.js and the REST API lives at https://crispstats.com/api/v1.
> There is no npm package to install. Integrations copy the script tag, the queue stub, crispstats.d.ts and proxy code from these docs or from Settings, Tracking code in the dashboard. A first-party proxy forwards one path of the site to https://in.crispstats.com/p/ and forwards only content-type, user-agent, accept-language, referer, origin, if-none-match and x-forwarded-for, never cookies.

# API rate limits

> CrispStats API keys get a daily request allowance from the plan plus a burst limit of 20 requests per 10 seconds. Read the X-RateLimit headers and Retry-After, and the collector's per-address and per-site limits.

Every CrispStats API key has two limits: a daily allowance set by your workspace's plan, and a burst limit of 20 requests in any 10-second window. All the keys of a workspace together also have a daily ceiling of five times the plan's allowance. Requests without a key, which can read only the demo site, get 500 a day and 10 per 10 seconds. Every response tells you where you stand in `X-RateLimit-*` headers, and a refused request returns `429 rate_limited` with a `Retry-After` header.

## Limits

| Caller | Per day | Burst |
| - | - | - |
| Key during the trial | 1,000 | 20 per 10 seconds |
| Key on the Starter plan | 10,000 | 20 per 10 seconds |
| Key on the Growth plan | 50,000 | 20 per 10 seconds |
| Key on the Scale plan | 250,000 | 20 per 10 seconds |
| No key (demo site only) | 500 | 10 per 10 seconds |

How the limits are counted:

* **Per key.** Each key has its own counters, so one key using its allowance does not use another key's.
* **A workspace ceiling.** Every key in a workspace also counts toward a workspace ceiling of five times your plan's daily allowance. On the Starter plan, for example, each key can make 10,000 requests a day and all keys together 50,000. A single key can never reach the ceiling on its own.
* **Per address without a key.** Anonymous requests are counted by a salted hash of the client address. The address itself is not stored.
* **Every request counts**, whatever the endpoint and whether it succeeds, once the key has been verified. Requests rejected for a bad key (`401`) or for a key without **Read** or **Admin** (`403`) are refused before counting, and so is an MCP batch of more than 20 requests.
* **REST and MCP share the allowance.** A key used for both the [REST API](https://docs.crispstats.com/api-reference/introduction.md) and the [MCP server](https://docs.crispstats.com/api-reference/mcp.md) spends one daily allowance. Each JSON-RPC request in a `POST` to the MCP endpoint counts once, and a batch may hold at most 20 requests; notifications are free. A batch that needs more requests than the key has left today is refused whole and costs nothing, while smaller requests still go through.
* **The day resets at midnight UTC.** The burst window is a fixed 10-second window, aligned to the clock.
* **A refused burst does not spend the day.** When the burst limit refuses a request, the daily counter is not increased.
* **The workspace ceiling counts after the key's day.** A request the workspace ceiling refuses still counts against its key's day. Both reset at the same midnight UTC, so this only shows in `X-RateLimit-Remaining`.

Plans are compared on [plans and limits](https://docs.crispstats.com/account/plans-and-limits.md). Moving to a larger plan raises the daily allowance of every key in the workspace, and the workspace ceiling with it.

## Response headers

Every API response, successful or not, carries these headers once the request has been counted. Responses to requests refused before counting (`401`, `403` for a key's scope) do not:

**X-RateLimit-Limit** `integer`

Requests allowed per day for this key, or for anonymous callers.

**X-RateLimit-Remaining** `integer`

Requests left today. Never negative.

**X-RateLimit-Reset** `integer`

When the daily allowance resets, as Unix seconds. This is the next midnight UTC.

**Retry-After** `integer`

On `429` responses only: seconds to wait before the next request will be accepted.

The headers are exposed to browsers through CORS, so `fetch` from a web page can read them.

```http theme={"theme":{"light":"github-light","dark":"github-dark"}}
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: private, no-store
X-RateLimit-Limit: 500
X-RateLimit-Remaining: 494
X-RateLimit-Reset: 1794873600
```

## When you hit a limit

A refused request returns `429` with the [error envelope](https://docs.crispstats.com/api-reference/errors.md). The message says which limit refused it:

```json Burst limit theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "error": {
    "code": "rate_limited",
    "message": "Too many requests at once. Wait 4 seconds and try again."
  }
}
```

```json Daily allowance theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "error": {
    "code": "rate_limited",
    "message": "This key has used its 10,000 requests for today. The allowance resets at midnight UTC; a larger plan raises it."
  }
}
```

```json Workspace ceiling theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "error": {
    "code": "rate_limited",
    "message": "This workspace has used its 50,000 API and MCP requests for today, across all of its keys. The allowance resets at midnight UTC; a larger plan raises it."
  }
}
```

For the burst limit, `Retry-After` is the seconds until the current 10-second window ends. For the daily allowance and the workspace ceiling, it is the seconds until midnight UTC. When the workspace ceiling refuses a request, `X-RateLimit-Remaining` is `0`; the other headers still describe the key's own day.

## Retry correctly

Wait for `Retry-After` seconds, then send the same request again. Do not retry in a tight loop: every retry inside the window is refused again.

```javascript JavaScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
async function getReport(url) {
  for (let attempt = 0; attempt < 3; attempt++) {
    const response = await fetch(url, {
      headers: { Authorization: `Bearer ${process.env.CRISPSTATS_API_KEY}` },
    });
    if (response.status !== 429) return response;
    const wait = Number(response.headers.get("Retry-After") ?? "1");
    if (wait > 60) return response; // the daily allowance is used up: do not wait for midnight
    await new Promise((resolve) => setTimeout(resolve, wait * 1000));
  }
  throw new Error("Still rate limited after 3 attempts");
}

const response = await getReport("https://crispstats.com/api/v1/sites/YOUR_SITE_ID/stats?range=7d");
console.log(response.status, response.headers.get("X-RateLimit-Remaining"));
```

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import os
import time
import requests

def get_report(url, params=None):
    headers = {"Authorization": f"Bearer {os.environ['CRISPSTATS_API_KEY']}"}
    for _ in range(3):
        response = requests.get(url, params=params, headers=headers)
        if response.status_code != 429:
            return response
        wait = int(response.headers.get("Retry-After", "1"))
        if wait > 60:
            return response  # the daily allowance is used up: do not wait for midnight
        time.sleep(wait)
    raise RuntimeError("Still rate limited after 3 attempts")

response = get_report("https://crispstats.com/api/v1/sites/YOUR_SITE_ID/stats", {"range": "7d"})
print(response.status_code, response.headers.get("X-RateLimit-Remaining"))
```

To stay under the limits:

* Send requests one after another rather than in large parallel batches. 20 requests per 10 seconds is two a second on average.
* Cache reports you show to many people. Responses are marked `private, no-store`, so CrispStats will not cache them for you.
* Ask for what you need in one call: a breakdown with `limit=100` costs the same as one with `limit=10`.
* Watch `X-RateLimit-Remaining` and slow down before it reaches zero.

## Collector limits

The collector at `in.crispstats.com` has its own limits, separate from the API's. They are counted per minute in each Cloudflare location, so traffic served from several locations gets each limit in each of them.

| Traffic | Counted by | Limit per minute |
| - | - | - |
| Browser events on `POST /e` | Visitor address | 1,200 |
| `GET /id` and `GET /check` | Visitor address | 1,200 each |
| Proxied events on `POST /p/e` and `POST /api/event` | Site and visitor address | 1,200 |
| Proxied `GET /p/id`, `GET /api/id` and `GET /p/check` | Site and visitor address | 1,200 each |
| All proxied traffic of one site | Site | 6,000 |
| Server events with a secret key | Site | 6,000 |
| AI crawler hits on `POST /bot` | Site | 6,000 |

Proxied traffic is never counted by your proxy's own address alone, so sites whose proxies share a host's outgoing addresses do not share a limit. The visitor address is the one your proxy forwards in `X-Forwarded-For`.

Over a limit, a browser event is dropped and still answered with `202`, so a page never sees an error. `GET /id` still answers, with an id that is not linked to the visit. Server events get `429` with `{ "error": "rate_limited" }`, and `GET /check` gets `429` with `{ "ok": false, "error": "rate_limited" }`. See the [collector reference](https://docs.crispstats.com/api-reference/collector.md).

## Next steps

> [card] [Plans and limits](https://docs.crispstats.com/account/plans-and-limits.md)
>
> Compare daily API allowances and other plan limits.

> [card] [Errors](https://docs.crispstats.com/api-reference/errors.md)
>
> Handle 429 and every other error code.

> [card] [Query parameters](https://docs.crispstats.com/api-reference/query-parameters.md)
>
> Pagination bounds that decide how many requests a full export takes.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.