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

# Authentication

> Authenticate requests with X-API-Key, enforce free vs paid host routing, and test endpoints safely in demo mode.

All production cricket API requests authenticate using a secret API key passed in the `X-API-Key` HTTP header.

## Request Header

| Header | Required | Notes |
| :- | :- | :- |
| `X-API-Key` | **Yes** (unless `X-Demo-Mode: 1`) | Your API key from [dashboard.sportsxapi.com](https://dashboard.sportsxapi.com). |
| `Accept` | No | Set to `application/json` (or `text/event-stream` for live SSE streams). |

```bash theme={"system"}
curl -X GET "https://apiv2.sportsxapi.com/cricket/api/v2/match/100123/live" \
  -H "X-API-Key: sx_live_YOUR_API_KEY" \
  -H "Accept: application/json"
```

## Host-Tier Enforcement

SportSXAPI strictly separates free evaluation traffic from paid production traffic at the gateway middleware layer (`X-SportXAPI-Tier-Host`):

* **`https://api.sportsxapi.com`** accepts **Free** plan keys (capped at `3,000` requests/month) and `X-Demo-Mode: 1` requests.
* **`https://apiv2.sportsxapi.com`** accepts **Paid** plan keys (`Starter`, `Pro`, `Business`, `Ultra`, `Custom`).

Sending a key to the wrong host returns `403 Forbidden`:

```json Paid Key on Free Host (403) theme={"system"}
{
  "error": "Paid key used on free API host",
  "message": "Paid API keys must use https://apiv2.sportsxapi.com."
}
```

```json Free Key on Paid Host (403) theme={"system"}
{
  "error": "Free key used on paid API host",
  "message": "Free/demo access must use https://api.sportsxapi.com."
}
```

Sending requests through any unconfigured hostname returns `421 Misdirected Request`:

```json theme={"system"}
{
  "error": "Invalid API host",
  "message": "Use api.sportsxapi.com for free/demo access or apiv2.sportsxapi.com for paid API access."
}
```

## Interactive Demo Mode (`X-Demo-Mode: 1`)

To evaluate endpoints without an API key on `https://api.sportsxapi.com`, send `X-Demo-Mode: 1`:

* Limited to **`5` requests per endpoint** per client IP.
* Returns tracking headers `X-Demo-Used` and `X-Demo-Remaining`.
* Does not cover `/cricket/api/v2/match/{matchId}/stream` (paid plans only; returns `429`).

## Security Guidelines

> [!WARNING]
>
> Never expose your `X-API-Key` inside frontend browser JavaScript, mobile app binaries without a proxy, or public repositories.

1. **Always proxy from your backend:** Keep keys inside server environment variables such as `process.env.SPORTSXAPI_KEY`.
2. **Watch for failed auth throttles:** Sending more than `60` missing or invalid API key attempts within `60` seconds from the same IP triggers `429 Too many authentication attempts`.
3. **Expired paid plans:** When a paid subscription expires, its effective entitlement falls back to `FREE` (`api.sportsxapi.com` Free tier quota limits apply) until renewed in the [Dashboard](https://dashboard.sportsxapi.com).
4. **Rotate leaked keys immediately:** Revoke compromised keys from your dashboard or request rotation via [Contact Support](https://sportsxapi.com/contact).


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