# Authentication

Every request carries a key in the Authorization header. Here is how to send, scope and rotate one.

## Sending the key

Send the key as a bearer token. Requests without one get `401` with the code `missing_key`.

```shell
curl https://api.warraq.dev/v1/collections \
  -H "Authorization: Bearer wq_live_3f9a7c21"
```

```js
const res = await fetch('https://api.warraq.dev/v1/collections', {
  headers: { Authorization: `Bearer ${process.env.WARRAQ_KEY}` }
});
const body = await res.json();
```

```python
import os, requests

res = requests.get(
    "https://api.warraq.dev/v1/collections",
    headers={"Authorization": f"Bearer {os.environ['WARRAQ_KEY']}"},
)
body = res.json()
```

## Scopes

- `read` lists and fetches records.
- `write` adds scans and edits records.
- `admin` manages keys and webhooks.

## Rotating a key

Create the new key first, deploy it, then revoke the old one. Both work in the meantime, so nothing fails while you switch.
