Skip to navigation

Use Statpad from a coding agent

Give Claude Code, Cursor or Codex a key it can use safely, check it with one request, and connect the two MCP servers.

A coding agent can write and run code that calls Statpad. It needs three things from you: a key it reads from the environment, a first request that proves the key works, and the MCP servers that let it look things up. Build with AI adds the Statpad skill and a checklist for the code the agent writes.

Get a key

Create an account. It starts on the Free plan, with no card: live data over REST for every league, 2,500 requests a month and 1 key. Sign-up creates that first key and shows it once, so copy it straight into the environment variable below. On a paid plan, open Keys and choose Create key to give the agent a key of its own, named after where it runs, such as coding-agent, so you can revoke it on its own later. API keys has the key limit for each plan.

Give the key to the agent

Put the key in the STATPAD_API_KEY environment variable, and have the agent’s code read it from there. The agent can then run requests that use the key without the key ever appearing in the conversation.

export STATPAD_API_KEY="sporty_..."
claude

Start the agent from the shell where you exported the key, or keep the key in a .env file that your code loads, such as with node --env-file=.env. Add .env to .gitignore before you write the key into it.

Three rules keep the key safe:

  • Don’t paste the key into the chat. Your prompt goes to the model provider and stays in the agent’s history. Tell the agent the key is in STATPAD_API_KEY, and ask it not to print the key or write it to a file.
  • Keep the key on a server or your own machine. Anyone who opens a web page or a mobile app can read a key inside it. The REST API sends no CORS headers, so browser code can’t call it anyway. Ask for a backend that calls Statpad and serves your users.
  • Give the agent its own key when your plan has a spare slot (Free has one key). Every key on an account shares one request rate and one monthly allowance. A separate key shows its own usage on the Keys page, and you can revoke it without touching your apps.

Make the first request

Ask the agent to run this, or run it yourself:

curl https://api.statpad.dev/v1/leagues \
-H "Authorization: Bearer $STATPAD_API_KEY"

A working key gets 200 and the leagues it can read, one object each:

GET /v1/leagues (trimmed)
{
"data": [
{
"alias": "nfl",
"id": "01a1fa5b-9010-7c20-b9ba-86a835df4a1f",
"level": "pro",
"name": "National Football League",
"period_kind": "quarter",
"regulation_periods": 4,
"sport": "football"
}
]
}

A 401 with code unauthorized means the variable is empty, or holds a key that’s mistyped or revoked. A 403 with code forbidden means the key is valid but the account has no active access, so check your plan at app.statpad.dev. Pass a league’s alias in every other path, such as /v1/nfl/games?date=2026-11-09. Then describe the program you want, and compare what the agent writes with the Quickstart.

Connect the MCP servers

Statpad has two MCP servers. Most coding agents want both.

ServerWhat it doesWhere it runsKey
Docs MCP server, https://statpad.dev/docs/_mcp/serverOne tool, searchDocs, that answers from these docs with a link to each page it used. The agent looks up fields, limits and error codes instead of guessing them.Remote, over HTTPNone
@statpad/mcpRead-only tools such as find_games, get_game and get_plays over live games. The agent checks real responses while it writes code, and answers questions about games.Your computer, over stdio, with Node.js 20 or newerSTATPAD_API_KEY

Replace sporty_... with your key where a client needs it written out.

claude mcp add --transport http statpad-docs https://statpad.dev/docs/_mcp/server
claude mcp add statpad -e STATPAD_API_KEY=sporty_... -- npx -y @statpad/mcp

By default, Claude Code keeps both in ~/.claude.json for the current project, outside the repository, with the key in plain text. Don’t add @statpad/mcp with --scope project, which writes it and the key into .mcp.json at the project root, a file meant to be committed.

An agent without MCP can read the docs directly: statpad.dev/docs/llms.txt lists every page, and appending .md to a page’s URL returns its Markdown. statpad.dev/llms.txt lists the rest of the site the same way.

Common mistakes

These are the mistakes coding agents make most with Statpad. Each one is cheap to catch in review.

MistakeWhat goes wrongDo this instead
The key is in front-end code, a prompt or a committed fileAnyone who finds it can spend your allowance and hold your stream connections.Read it from STATPAD_API_KEY on the server. If it leaked, revoke it first, then create a new key.
The code polls a game every second or twoIt uses up the request rate and the monthly allowance. Free and Developer allow 1 request a second, and 2,500 and 25,000 a month.On Pro and the trial, subscribe to the stream from the response’s seq. On Free and Developer, poll the game’s changes feed with after_seq, as in Without the stream.
A reconnect starts over, or a changed play is added as a new rowThe app misses changes, or shows a play twice after replay changes a call.Resume from the last seq applied, and replace each entity by entity_type and entity_id, keeping the highest version. See Keep state.
A 429 is retried at onceThe retries count against the rate and get 429 again.Wait Retry-After seconds after rate_limited. Never retry quota_exhausted; it lasts until the period resets. See Rate limits.
The code calls an endpoint or field Statpad doesn’t have, such as standings or oddsA 404, or a field that’s always null.Check the API reference and Coverage by league, or let the agent ask the docs MCP server.
The code asks for games before November 2026Statpad started collecting each league then and doesn’t backfill.Test against the recorded games on Sample responses, which need no key.