Skip to main content
Use this page to send your API key correctly, keep it off the browser and fix 401 and 403 errors.
Fastest way: ask your AI. Follow Build with AI, and add this to your prompt: “Read my TheStatsAPI key from the THESTATSAPI_API_KEY env var and only call the API from server code, never from the browser.”

Send the header

Every request needs this header, except /health:
  • The value must start with Bearer (capital B), then one space, then your key.
  • bearer in lowercase, a missing space or extra spaces all fail with 401.
  • 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.
Add .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
Never put your key in browser code. The API allows cross-origin requests from any website, so a request from the browser will work, but anyone can then read your key from the page or the network tab. In particular:
  • Don’t use NEXT_PUBLIC_ or VITE_ variables for the key. They’re bundled into the browser code.
  • In Lovable, store the key with the Add secret form and call the API from a server function or Edge Function. Lovable commits .env, so the key must not go there.
  • Don’t commit the key or paste it into logs, screenshots or support tickets.
If a key leaks, create a new one, update your server, then revoke the old one.

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.