# Authentication

Requests are authenticated with an API key in the `X-API-Key` header.

```bash
curl https://api.fanovate.io/dashboard/api/v1/me \
  -H "X-API-Key: fnv_live_..."
```

## Who can create keys

Only the agency owner can create keys. Team members and creators cannot. Keys are managed in the
dashboard with a signed-in session, never with a key.

## Create a key

1. Open **Settings → API keys** in the dashboard. The **Log in** link in the header takes you there.
2. Choose a name and an expiry: 30, 90 (default) or 365 days. Keys always expire.
3. Confirm with your 2FA code. If 2FA is off for your account, confirm with your current password.
   A 2FA code works once.
4. Copy the key.

The key is shown once. Fanovate stores only a hash and cannot show it again. If you lose it,
revoke it and create a new one. Every new key triggers an email to the account owner.

You can hold up to 10 active keys. Creating an 11th returns `409`.

## Revoke a key

Revoke a key in the same place. Revocation takes effect immediately. Revoking an already revoked
key is not an error.

All keys of an account are revoked automatically when the password is reset or changed, the
email address changes, 2FA is turned on, off or reset, or all sessions are signed out. Create new
keys afterwards.

## Permissions

A key acts as the owner, with the owner's current permissions. If the account is suspended or
deleted, or the subscription ends, requests fail the same way they would in the dashboard.

## Errors

| Status | Meaning |
| --- | --- |
| `401` | The key is missing, malformed, unknown, expired or revoked, or the account is no longer valid. |
| `403` | The key is valid, but the operation is not available with a key, or the account lacks the right to do it. |
| `400` | Both `Authorization: Bearer` and `X-API-Key` were sent. Send only one. |

## Where not to use a key

- Never use a key in a browser or any frontend code. A request that carries `X-API-Key` and a
  browser `Origin` header is rejected. The API sends no CORS headers for key requests.
- Never put a key in the URL. Query parameters are not read as keys.
- Call the API from your server only.
