> ## 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.

# Create and manage API keys

> Create secret cs_sk_ API keys in CrispStats with read, events, write or admin scopes, limit a key to one site, copy it once, and revoke or delete it.

CrispStats uses secret API keys that start with `cs_sk_` for the REST API, the MCP server and server-side events. Owners and admins create them on the workspace page, under **API keys**. A key belongs to the workspace, carries one or more scopes, covers every site or just one, and is shown in full only once, right after you create it.

## Public key or secret key

Every site has a public key, and a workspace can have any number of secret keys. They do different jobs.

| | Public key | Secret API key |
| - | - | - |
| Starts with | `cs_pk_` | `cs_sk_` |
| Belongs to | One site | The workspace, optionally limited to one site |
| Used by | The script tag (`data-site`), the setup check, the live visitor badge | The REST API, the MCP server, server-side events |
| Can do | Send browser events to its site | Whatever its scopes allow |
| Safe to publish | Yes | No. Keep it on a server or in a secret manager. |
| Where to find it | **Settings**, **Tracking code** | Shown once when you create it |

To replace a public key, see [rotate the public key](https://docs.crispstats.com/account/sites-and-settings.md#rotate-the-public-key).

## Create a key

**1. Open the workspace page**

Choose **Workspace** in the account menu, or **Team and API keys** below a site's settings tabs. Under **API keys**, select **Create key**.

**2. Name the key**

Enter what will use it, for example `Production backend`. The name is how you recognise the key in the list later.

**3. Pick the scopes**

Tick at least one scope. **Read** is selected by default. See [scopes](#scopes) for what each one allows.

**4. Choose the access**

Pick **Every site in** your workspace, or **Only** one of its sites. A key limited to one site is refused for every other site.

**5. Copy the key**

Select **Create key**. The next dialog shows the full key once. Select **Copy key**, store it in a secret manager or an environment variable, then select **I have copied it**.

> [!WARNING]
>
> CrispStats keeps only a hash of the key, so it cannot show the key again. If you lose it, revoke it and create a new one.

Keys created in the dashboard do not expire. They work until you revoke or delete them.

## Scopes

| Scope | What it allows today |
| - | - |
| `read` | Read stats and reports through the [REST API](https://docs.crispstats.com/api-reference/introduction.md) and the [MCP server](https://docs.crispstats.com/api-reference/mcp.md). |
| `events` | Send [server-side events](https://docs.crispstats.com/track/server-side-events.md) and payments to the collector at `https://in.crispstats.com/e`. |
| `write` | Send server-side events, like `events`. The dashboard describes it as changing configuration such as goals and annotations, but the REST API and the MCP server have no write endpoints yet. |
| `admin` | Everything the other scopes allow: reading through the API and the MCP server, and sending server-side events. Also reads [raw events](https://docs.crispstats.com/api-reference/raw-events.md) through the API, which no other scope can, because raw events carry user, visitor and session ids. |

Give each key only the scopes it needs. A key for a backend that records signups needs `events`. A key for a spreadsheet or an AI assistant needs `read`.

## Use the key

Send the key as a bearer token in the `Authorization` header. This lists the sites the key can read:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl "https://crispstats.com/api/v1/sites" \
  -H "Authorization: Bearer $CRISPSTATS_API_KEY"
```

This reads the headline numbers of one site. Replace `SITE_ID` with the id from the site's dashboard address, `https://crispstats.com/app/SITE_ID`:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl "https://crispstats.com/api/v1/sites/SITE_ID/stats" \
  -H "Authorization: Bearer $CRISPSTATS_API_KEY"
```

When a key cannot be used, the API answers with an error envelope that names the cause:

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "error": {
    "code": "forbidden",
    "message": "That API key does not have the read scope. Create a key with read access in your workspace settings, under API keys."
  }
}
```

| Status | Code | When |
| - | - | - |
| `401` | `unauthorized` | The `Authorization` header is not in the form `Bearer cs_sk_…`, or the key is unknown, revoked or expired. A request without the header can read only the public demo site. |
| `403` | `forbidden` | The key has neither the `read` nor the `admin` scope, or it is limited to a different site. For raw events: the key does not have the `admin` scope. |
| `404` | `not_found` | The site does not exist or belongs to another workspace. |
| `429` | `rate_limited` | The key used its daily allowance, the workspace reached its daily ceiling, or the key sent too many requests at once. |

Each key has its own daily allowance, equal to your plan's API requests a day, and it resets at midnight UTC. Every key in a workspace also counts toward a workspace ceiling of five times your plan's daily allowance. See [rate limits](https://docs.crispstats.com/api-reference/rate-limits.md) and [authentication](https://docs.crispstats.com/api-reference/authentication.md).

## Revoke or delete a key

The **API keys** list on the workspace page shows each key's name, its scopes, the first characters of the key (such as `cs_sk_1a2b3c4d…`), whether it covers all sites or one, when it was created and when it was last used. **Last used** is updated at most once a minute; a key that has never made a request shows **Never used**.

* **Revoke** stops the key after you confirm. It stays in the list, crossed out and marked **Revoked**, as a record.
* **Delete** stops the key and removes it from the list. This cannot be undone. You can delete a key that is already revoked.

The REST API and the MCP server refuse a revoked key on the next request. The collector caches key checks for up to a minute, so server-side events with a revoked key can still be accepted for about a minute.

Only owners and admins can see, create, revoke or delete keys. Members and viewers see a note that API keys are for owners and admins.

## Next steps

> [card] [API introduction](https://docs.crispstats.com/api-reference/introduction.md)
>
> Endpoints, query parameters and response shapes of REST API v1.

> [card] [Connect AI assistants](https://docs.crispstats.com/ai/connect-ai-assistants.md)
>
> Use a read key with the CrispStats MCP server.

> [card] [Server-side events](https://docs.crispstats.com/track/server-side-events.md)
>
> Send events and payments from your backend with an events key.


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