401 and 403 errors.
Send the header
Every request needs this header, except/health:
- The value must start with
Bearer(capital B), then one space, then your key. bearerin lowercase, a missing space or extra spaces all fail with401.- The header is the only way to send the key. A key in the URL is ignored.
Get and manage keys
Manage keys on the API keys page in your dashboard.- Create: a new key is shown only once. Copy it into your environment variables or secrets manager straight away.
- Revoke: a revoked key stops working at once and returns
401 Invalid API key. - Several keys: you can have up to 5 active keys, for example one per app or environment. Each key has its own per-minute rate limit, and all your keys share your account’s monthly quota. See Rate limits.
Keep your key on the server
Read the key from an environment variable in server code. Never hard-code it..env to your .gitignore.
If you have a web frontend, have it call your own server route, and let only that route call TheStatsAPI. For example, a Next.js route handler:
app/api/next-fixture/route.js
Auth errors
Auth errors use the standard error envelope:
Every authenticated response, including errors after your key is accepted, also carries your rate-limit and quota headers. See Rate limits.