> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://statpad.dev/docs/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://statpad.dev/docs/_mcp/server.

# Use Statpad from a coding agent

> How to use Statpad from a coding agent such as Claude Code, Cursor or Codex. Get an API key, give it to the agent through an environment variable on your machine or server, make the first request, connect the docs MCP server and @statpad/mcp, and avoid the mistakes agents make most.

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](/docs/ai) adds the Statpad skill and a checklist for the code the agent writes.

## Get a key

[Create an account](https://app.statpad.dev/sign-up). 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](/docs/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.

**`Shell`**

```bash Shell
export STATPAD_API_KEY="sporty_..."
claude
```

**`.env`**

```bash .env
STATPAD_API_KEY=sporty_...
```

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](/docs/keys#revoke-a-key) without touching your apps.

## Make the first request

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

```bash
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)`**

```json title="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`](/docs/errors#unauthorized) means the variable is empty, or holds a key that's mistyped or revoked. A `403` with code [`forbidden`](/docs/errors#forbidden) means the key is valid but the account has no active access, so check your plan at [app.statpad.dev](https://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](/docs/quickstart).

## Connect the MCP servers

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

| Server                                                  | What it does                                                                                                                                                               | Where it runs                                       | Key               |
| ------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- | ----------------- |
| Docs MCP server, `https://statpad.dev/docs/_mcp/server` | One 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 HTTP                                   | None              |
| [`@statpad/mcp`](/docs/mcp)                             | Read-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 newer | `STATPAD_API_KEY` |

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

#### Claude Code

```bash
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.

#### Cursor

Add both servers to `~/.cursor/mcp.json` for every project, or to `.cursor/mcp.json` in one project:

**`~/.cursor/mcp.json`**

```json title="~/.cursor/mcp.json"
{
  "mcpServers": {
    "statpad-docs": { "url": "https://statpad.dev/docs/_mcp/server" },
    "statpad": {
      "command": "npx",
      "args": ["-y", "@statpad/mcp"],
      "env": { "STATPAD_API_KEY": "${env:STATPAD_API_KEY}" }
    }
  }
}
```

Cursor fills in `${env:STATPAD_API_KEY}` from its own environment, so the file holds no key. Start Cursor from a shell where the variable is set.

#### Claude Desktop

Open **Settings**, then **Developer**, then **Edit Config**, and add `@statpad/mcp` to `claude_desktop_config.json`:

**`claude_desktop_config.json`**

```json title="claude_desktop_config.json"
{
  "mcpServers": {
    "statpad": {
      "command": "npx",
      "args": ["-y", "@statpad/mcp"],
      "env": { "STATPAD_API_KEY": "sporty_..." }
    }
  }
}
```

The file holds the key in plain text, outside any repository. Restart Claude Desktop after you save it. Claude Desktop connects to remote servers as custom connectors instead: open **Connectors**, choose **Add custom connector**, enter `https://statpad.dev/docs/_mcp/server` and choose no sign-in.

#### Codex

```bash
codex mcp add statpad-docs --url https://statpad.dev/docs/_mcp/server
codex mcp add statpad --env STATPAD_API_KEY=sporty_... -- npx -y @statpad/mcp
```

An agent without MCP can read the docs directly: [`statpad.dev/docs/llms.txt`](https://statpad.dev/docs/llms.txt) lists every page, and appending `.md` to a page's URL returns its Markdown. [`statpad.dev/llms.txt`](https://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.

| Mistake                                                                             | What goes wrong                                                                                                                   | Do this instead                                                                                                                                                                                                |
| ----------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| The key is in front-end code, a prompt or a committed file                          | Anyone 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](/docs/keys#revoke-a-key) it first, then create a new key.                                                                                 |
| The code polls a game every second or two                                           | It 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](/docs/streaming#without-the-stream). |
| A reconnect starts over, or a changed play is added as a new row                    | The 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](/docs/streaming#keep-state).                                     |
| A `429` is retried at once                                                          | The 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](/docs/get-started/rate-limits).                                            |
| The code calls an endpoint or field Statpad doesn't have, such as standings or odds | A `404`, or a field that's always `null`.                                                                                         | Check the [API reference](/docs/api-reference) and [Coverage by league](/docs/coverage), or let the agent ask the docs MCP server.                                                                             |
| The code asks for games before November 2026                                        | Statpad started collecting each league then and doesn't backfill.                                                                 | Test against the recorded games on [Sample responses](/docs/replay), which need no key.                                                                                                                        |