puckapi-client
v0.2.0
Published
JavaScript and TypeScript client for the PuckAPI NHL data API: stats, play-by-play, odds and player props. No dependencies.
Maintainers
Readme
puckapi-client
NHL data and odds API. JavaScript and TypeScript client for the PuckAPI NHL data API. No dependencies; Node 18+, Deno, Bun, and edge runtimes with fetch.
First call in plain Python
No package needed: standard library only. Set PUCKAPI_API_KEY to your key (free at https://puckapi.com/signup) and run this. get_standings costs 2 credits.
import json, os, urllib.request
req = urllib.request.Request(
"https://mcp.puckapi.com/v1/get_standings",
data=json.dumps({}).encode(),
headers={"x-api-key": os.environ["PUCKAPI_API_KEY"], "content-type": "application/json"},
)
with urllib.request.urlopen(req) as resp:
data = json.load(resp)["data"]
print("credits left:", resp.headers["x-credits-remaining"])
rows = next(v for v in data.values() if isinstance(v, list))
for row in rows[:5]:
print(row)Every tool works the same way: POST https://mcp.puckapi.com/v1/, JSON in, {"data": ...} out, with X-Credits-Used and X-Credits-Remaining headers.
PuckAPI at a glance
- NHL data and odds API: NHL and PWHL stats, play-by-play, expected goals and odds. REST API and MCP server. Free to start.
- 32 tools (31 on the free plan; get_prop_projections needs a paid plan). Each call costs 1 to 25 credits; the table below has every price.
- Free: 500 credits every month, no card. Plans: Starter $19/month (10,000 credits), Pro $49/month (30,000 credits), Scale $149/month (125,000 credits), Business $299/month (300,000 credits). Top-ups: 400 credits per $1, from $5.
- MCP server: https://mcp.puckapi.com/mcp?key=YOUR_API_KEY (or the key in an
x-api-keyheader; Claude and ChatGPT connect with a sign-in instead) - REST: POST https://mcp.puckapi.com/v1/ with your key in an
x-api-keyheader and the arguments as a JSON body. - Python:
pip install puckapi. JavaScript:npm install puckapi-client - Play-by-play events: 6,900,000+. Every event since 2010-11, with coordinates, strength state and the players involved where the event has them.
- Games: 22,000+. Regular season, playoffs, and preseason across supported seasons.
- Odds records: 191,000+. Moneyline, puck line and total by sportsbook for every regular-season and playoff game from 2019-20, about 16 to 18 books a game from 2020-21 to 2023-24 and 8 since.
| Credits | Tools | | --- | --- | | 1 | get_data_status, list_teams | | 2 | get_standings, get_schedule, search_players | | 5 | get_games, get_team_stats, get_player_stats, get_goalie_stats, get_skater_season_stats, get_player_game_log, get_predictions, get_playoff_projections, get_line_at_time, get_rest_and_travel, get_game_probabilities | | 10 | get_odds, get_game_detail, get_head_to_head, get_plays, get_shot_map, get_shifts, get_situation_time, get_player_props, get_prop_history, get_prop_movement, get_market_odds, get_alt_lines, get_prop_probabilities | | 25 | get_prop_projections (paid plans), get_line_movement, get_prop_backtest |
- get_player_props: 10 credits a game before it starts and 20 once it has been played (accounts opened before October 30 2026 pay 10 for every game).
- get_prop_history: 10 credits for every 25 games already played that a call covers, and at least 10 a call (accounts opened before November 1 2026 pay 10 a call).
Install
npm install puckapi-clientGet a free key (500 credits every month, no card) at https://puckapi.com/signup?utm_source=npm&utm_medium=readme&utm_campaign=puckapi-js and set PUCKAPI_API_KEY.
import { Client } from "puckapi-client"
const client = new Client() // reads PUCKAPI_API_KEY, or new Client({ apiKey: "..." })
const data = await client.getOdds({"game_id":"2026020080","snapshot_type":"closing"})
console.log(data)
console.log("credits left:", client.lastCreditsRemaining)Every method takes one object with the API's parameter names and returns the unwrapped data. client.call("tool_name", {...}) reaches any tool newer than this package. Errors are typed: AuthError (401), InsufficientCreditsError (402), NotFoundError (404), RateLimitError (429, with retryAfter), APIError otherwise. 429 and 5xx responses are retried with backoff.
Load a whole season
client.loadSeason(dataset, season) pulls every page of one dataset for a season and returns an array of row objects. Nested fields become dotted keys (home.abbrev).
const rows = await client.loadSeason("plays", 2025) // first call: pages through the API
const again = await client.loadSeason("plays", 2025) // second call: read from ~/.cache/puckapi/, no requests
await client.loadSeason("plays", 2025, { refresh: true }) // pull again2024 and 20242025 both mean the 2024-25 season.
| Dataset | Tool | What a row is | Requests for a typical season | Credits for a typical season |
| --- | --- | --- | --- | --- |
| games | getGames | one row per game; the tool has no offset, so it is read in 31-day windows | 10 | 50 |
| plays | getPlays | every play-by-play event, with coordinates and strength | 520 | 5,200 |
| odds | getOdds | closing lines for every game, billed per game returned | 3 | 14,000 |
| props | getPlayerProps | every sportsbook prop line, one request per played game | 1,410 | 14,050 |
Price a big pull first
Every request costs the tool's normal credits. Per-game datasets (plays, odds and props by game) make one request per played game, so a full season is thousands of credits. Ask first:
console.log(await client.loadSeason("odds", 2025, { estimate: true }))
// { dataset: "odds", season: ..., calls: ..., credits: ..., basis: ..., data_calls: 0 }estimate: true makes no data requests and spends nothing. Where the tool accepts estimate_only (season-wide odds, props) it asks the server for the price; it uses the games already in your cache when there are some, and typical season sizes otherwise. The numbers in the table are the same typical sizes: they are approximate, an order of magnitude and not a quote.
maxCalls(default 100) stops a pull that turns out larger than expected. It throwsLoadLimitError, which holds the rows fetched so far (err.rows), and caches nothing. Raise it deliberately for a big pull.- Extra tool arguments go in
params({ team: "BOS" },{ league: "mls" }). Do not pass the season, paging or date arguments:loadSeasonsets them. - In Node the result is cached as JSON lines under
~/.cache/puckapi/(cacheDirorPUCKAPI_CACHE_DIRmoves it,cache: falseskips it). Browsers and other runtimes withoutnode:fshave no cache. client.lastLoadreports the last load:rows,calls,creditsUsedandcached.- Per-game datasets skip games that start today or later.
Tools
| Method | What it returns | Credits |
| --- | --- | --- |
| getDataStatus | Data status | 1 |
| getStandings | Standings | 2 |
| getTeamStats | Team stats | 5 |
| listTeams | List teams | 1 |
| getGames | Games | 5 |
| getSchedule | Schedule | 2 |
| getGameDetail | Game detail | 10 |
| getHeadToHead | Head to head | 10 |
| searchPlayers | Search players | 2 |
| getPlayerStats | Player stats | 5 |
| getGoalieStats | Goalie stats | 5 |
| getSkaterSeasonStats | Skater season stats | 5 |
| getPlayerGameLog | Player game log | 5 |
| getOdds | Odds | 10 |
| getLineMovement | Line movement | 25 |
| getLineAtTime | Line at time | 5 |
| getRestAndTravel | Rest and travel | 5 |
| getPlayerProps | Player props | 10 |
| getPropHistory | Prop history | 10 |
| getPropMovement | Prop movement | 10 |
| getMarketOdds | Market odds | 10 |
| getGameProbabilities | Game probabilities | 5 |
| getPropProbabilities | Prop probabilities | 10 |
| getPropBacktest | Prop backtest | 25 |
| getPlays | Plays | 10 |
| getShotMap | Shot map | 10 |
| getShifts | Shifts | 10 |
| getSituationTime | Situation time | 10 |
| getPredictions | Predictions | 5 |
| getPlayoffProjections | Playoff projections | 5 |
| getPropProjections | Prop projections | 25 |
| getAltLines | Alt lines | 10 |
Full reference with response shapes: https://puckapi.com/docs?utm_source=npm&utm_medium=readme&utm_campaign=puckapi-js. The same data is available as a hosted MCP server for Claude, ChatGPT and Cursor: https://puckapi.com/mcp. A Python client is on PyPI: pip install puckapi.
MIT licensed.
