Skip to main content
Use this page to set up your AI coding tool so it writes code against the real API instead of guessing. It takes about five minutes.

Why this works

  • https://api.thestatsapi.com/llms.txt is the whole API reference in one Markdown file: every endpoint, parameter and response field. It’s generated from our OpenAPI spec, so it matches the live API.
  • With it, your AI uses real endpoint and parameter names instead of guessing.
  • If the AI still sends a wrong parameter, the API answers with 400 UNKNOWN_PARAMETER and suggests the right name, so the AI can fix its own mistake.

Three steps

1

Get your API key

Create an account, then make a key on the API keys page. The key is shown only once, so save it straight into a .env file in your project:
.env
Make sure .env is listed in your .gitignore.
2

Give your AI the API reference

This is the link your AI needs:
If your tool works on files in your project (Claude Code, Codex, Cursor), save a copy into the project too:
The file is about 300 KB. Web-fetch tools often summarise or cut off long pages, but a local copy can be searched in full. Re-run the curl command now and then to pick up API changes. Don’t add this file to .gitignore: Cursor hides git-ignored files from its AI.
3

Paste a starter prompt

Replace [describe your app] and paste this into your AI tool. It points the AI at the reference, keeps your key on the server and heads off the most common mistakes.
Starter prompt
Want a prompt written for your exact idea? The Build with AI prompt generator in your dashboard asks a few questions about your app, then writes a prompt for Claude Code, Cursor, Lovable or another tool. You need to be logged in.

Set up your tool

For Claude Code, Codex and Cursor, also save these project notes in your project. The AI reads them every session, so it keeps following the rules. Keep the reference file path in backticks and don’t paste the whole llms.txt into this file: it’s too big to load every time.
Project notes
  1. In your project folder, download the reference (step 2) and create .env (step 1).
  2. Save the project notes above as CLAUDE.md in the project root.
  3. Run claude and paste the starter prompt.
Optional: stop Claude Code from reading your key file. Add this to .claude/settings.json:
.claude/settings.json
v0, Replit and other app builders: paste the starter prompt and store the key in the tool’s secrets or environment variable settings. Never use a NEXT_PUBLIC_ or VITE_ variable for it: those are bundled into browser code.
Never put your API key in frontend code. The API allows requests from browsers, so an AI tool’s browser-side code will work, but anyone can then copy your key from the page. Keep the key in an environment variable or secret, and call TheStatsAPI only from your own server route. If a key leaks, create a new one on the API keys page and revoke the old one.

Get live data in your AI chat (MCP)

Our MCP server lets your AI assistant look up live football data while you work: find an ID, check today’s fixtures, or see what a response looks like. It doesn’t replace llms.txt for writing code. It uses your own API key, so its calls count against your plan. Its tools are read-only and cover competitions, standings, teams, squads, players, injuries, matches, lineups, match and player stats, shot maps, heatmaps, referees and coverage. It doesn’t include odds; use the REST API for those.
Export the key first, then add the server. If you don’t export it, the shell expands $THESTATSAPI_API_KEY to nothing and the saved header is empty.
Run claude mcp list to check it shows as connected.
Windsurf and other clients that support streamable HTTP with a custom header work with the same URL and header. ChatGPT and Claude.ai connectors can’t send an API key yet, so they’re coming soon.
MCP tool arguments are not REST parameters. For example, the find_matches tool accepts date, but the REST endpoint /football/matches only accepts date_from and date_to. When your AI writes code, it should take names from llms.txt, not from the MCP tools.

Prompt ideas

Add one of these after the starter prompt:
  • Live scores widget: “Show today’s Premier League matches with live scores. Use /football/matches with date_from and date_to set to today, and poll every 60 seconds only while a match is live.”
  • League table page: “Build a page with the current Premier League table. Get current_season_id from /football/competitions/comp_3039, then call the season’s standings endpoint.”
  • Fantasy points: “For a finished match, get /football/matches/{match_id}/player-stats and score each player with my rules: 4 points a goal, 3 an assist, 1 for playing 60 minutes or more.”
  • xG shot map: “Draw a pitch with every shot from /football/matches/{match_id}/shotmap, sized by expected_goals. Only offer it for matches where shotmap_available is true.”
  • Odds comparison: “For this weekend’s Premier League matches, show the best home, draw and away price across bookmakers from /football/matches/{match_id}/odds. Skip matches where odds_available is false.”

Tips for good results

  • Paste errors back in. A 400 UNKNOWN_PARAMETER message names the right parameter, for example: Unknown query parameter 'date' (did you mean 'date_from' or 'date_to'?). AI tools can usually fix the call from that.
  • Give it real IDs. Look them up in the ID finder in your dashboard, or let the AI use the search= endpoints. Don’t let it make IDs up.
  • Watch your quota. An agent stuck in a retry loop can use up your requests quickly, and trials get 10% of the plan’s limits. Ask for caching. See Rate limits.
  • Check coverage before you build a feature. Not every competition has xG, player stats or odds. See Coverage.

More AI resources

Next steps

Quickstart

Make your first requests by hand and see what comes back.

Finding IDs

Look up the competition, season, team and player IDs your app needs.

Errors

What each error code means and how to fix it.

API reference

Every endpoint, with a playground to try requests.