---
title: "Authentication"
description: "Authenticate to the Betwatch Racing API with an API key in the X-API-Key header."
---

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

# Authentication

Every request carries an API key in the `X-API-Key` header. There is nothing to negotiate, no token to refresh, and no handshake — a key works from a one-line script.

```bash
curl 'https://api-beta.betwatch.com/v2/events?limit=5' \
  --header 'X-API-Key: YOUR_API_KEY'
```

## Getting a key

1. **Create an account**

   Sign in at [Account → API](https://beta.betwatch.com/account/api). Any signed-in account can mint a key.
2. **Generate a key**

   Choose **Generate API key**. The full value is shown once — copy it and store it somewhere safe. We cannot show it again.
3. **Send it on every request**

   Set the `X-API-Key` header. That is the whole integration.

> **Treat a key like a password**
>
> A key is displayed only at creation. If you lose one, or it leaks, revoke it at **Account → API** and generate another. Never commit a key to source control.

## Keys never travel in the URL

The header is the only way to authenticate. A request with a credential-shaped query parameter — `apikey`, `api_key`, `key`, `token`, `access_token` — is refused with `401` and [`authentication_required`](/docs/api/errors#authentication_required), even if the header is also present.

That is deliberate rather than pedantic. By the time a URL reaches us, it has been through your logs, your proxy, our edge, and our access logs, and a key in the path is now in all of them. Refusing the request is the only response that gets the key rotated instead of quietly leaked.

> **Streaming from a browser**
>
> Browser `EventSource` cannot set request headers, so it cannot authenticate to this API. Stream from your server — where your key belongs anyway — and relay to the browser over your own connection. Any HTTP client that sets headers works: `fetch` with a `ReadableStream`, `curl -N`, `httpx`, `requests` with `stream=True`, or an SSE library that accepts headers.

## Scopes

A key's plan grants scopes, and the API tells you when one is missing rather than pretending the data does not exist.

| Scope | Grants | Without it |
|---|---|---|
| `rest` | Every `/v2` read | `403` [`scope_required`](/docs/api/errors#scope_required) |
| `stream` | `GET /v2/stream` | `403` [`scope_required`](/docs/api/errors#scope_required) |

`stream` always includes `rest`: a stream client must be able to bootstrap over REST after a `resync` or an expired cursor.

REST-only plans can read and page through snapshots without streaming access. If the plan has no replay window, snapshot cursors last 15 minutes; they do not grant access to `/v2/stream`.

## What your plan can see

Beyond scopes, your plan defines the data in view: which sports, which countries, and how far back history goes. Races outside that scope are not in your responses at all — not as empty rows, not as partial records.

If your plan grants no sports or countries, reads fail with `403` [`entitlement_empty`](/docs/api/errors#entitlement_empty) rather than returning an empty page. An empty page would be indistinguishable from a quiet Tuesday, and would send you debugging your filters instead of your subscription.

## Revoking and rotating

Revoke a key at [Account → API](https://beta.betwatch.com/account/api); it stops working immediately. To rotate without downtime, generate the new key, deploy it, then revoke the old one — keys are independent, so both work during the overlap.

Source: https://beta.betwatch.com/docs/api/authentication/index.mdx
