dunkapi
v0.2.0
Published
JavaScript and TypeScript client for the DunkAPI NBA data API: stats, play-by-play, odds and player props. No dependencies.
Maintainers
Readme
dunkapi
NBA data and odds API. JavaScript and TypeScript client for the DunkAPI NBA 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 DUNKAPI_API_KEY to your key (free at https://dunkapi.com/signup) and run this. get_standings costs 2 credits.
import json, os, urllib.request
req = urllib.request.Request(
"https://mcp.dunkapi.com/v1/get_standings",
data=json.dumps({"season": 2026}).encode(),
headers={"x-api-key": os.environ["DUNKAPI_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.dunkapi.com/v1/, JSON in, {"data": ...} out, with X-Credits-Used and X-Credits-Remaining headers.
DunkAPI at a glance
- NBA data and odds API: NBA player props by sportsbook since 2023, plus play-by-play, shot locations and odds. REST and MCP.
- 31 tools (30 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.dunkapi.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.dunkapi.com/v1/ with your key in an
x-api-keyheader and the arguments as a JSON body. - Python:
pip install dunkapi. JavaScript:npm install dunkapi - Play-by-play: Since 2003-04. Play-by-play for NBA games since 2003-04, with the location of every shot in it.
- Sportsbook lines: 4 to 12 books.
- Leagues: NBA, WNBA, college. The WNBA since 2006 and Division I men's (from 2013-14) and women's (from 2014-15) college basketball, on the same tools.
| Credits | Tools | | --- | --- | | 1 | get_data_status, list_teams, search_players | | 2 | list_games, get_schedule, get_standings, get_injuries, get_ratings | | 5 | get_season_projections, get_projected_field, get_player_impact, get_game, get_player, get_player_games, get_leaders, get_team_stats, get_odds, get_line_at_time, get_rest_and_travel, get_game_probabilities | | 10 | get_plays, get_shot_chart, get_line_movement, 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_prop_backtest |
- get_odds: 5 credits a call, 10 for its bulk form (a whole day, card or league).
- 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 dunkapiGet a free key (500 credits every month, no card) at https://dunkapi.com/signup?utm_source=npm&utm_medium=readme&utm_campaign=dunkapi-js and set DUNKAPI_API_KEY.
import { Client } from "dunkapi"
const client = new Client() // reads DUNKAPI_API_KEY, or new Client({ apiKey: "..." })
const data = await client.getPlayerProps({"game_id":"401810726","market":"player_points","bookmaker":"draftkings"})
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/dunkapi/, no requests
await client.loadSeason("plays", 2025, { refresh: true }) // pull againSeasons are named by the year they end: 2025 is 2024-25.
| Dataset | Tool | What a row is | Requests for a typical season | Credits for a typical season |
| --- | --- | --- | --- | --- |
| games | listGames | one row per game with scores | 7 | 14 |
| plays | getPlays | every play with shot locations, one request per played game | 1,407 | 14,014 |
| odds | getOdds | one row per game and sportsbook, one request per played game | 1,407 | 7,014 |
| props | getPlayerProps | every sportsbook prop line, one request per played game | 1,407 | 14,014 |
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("plays", 2025, { estimate: true }))
// { dataset: "plays", 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/dunkapi/(cacheDirorDUNKAPI_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 |
| --- | --- | --- |
| listTeams | List teams | 1 |
| listGames | List games | 2 |
| getSchedule | Schedule | 2 |
| getGame | Game | 5 |
| getStandings | Standings | 2 |
| getInjuries | Injuries | 2 |
| searchPlayers | Search players | 1 |
| getPlayer | Player | 5 |
| getPlayerGames | Player games | 5 |
| getLeaders | Leaders | 5 |
| getTeamStats | Team stats | 5 |
| getPlays | Plays | 10 |
| getShotChart | Shot chart | 10 |
| getOdds | Odds | 5 |
| getLineMovement | Line movement | 10 |
| getRatings | Ratings | 2 |
| 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 |
| getPropProjections | Prop projections | 25 |
| getSeasonProjections | Season projections | 5 |
| getProjectedField | Projected field | 5 |
| getPlayerImpact | Player impact | 5 |
| getAltLines | Alt lines | 10 |
| getDataStatus | Data status | 1 |
Full reference with response shapes: https://dunkapi.com/docs?utm_source=npm&utm_medium=readme&utm_campaign=dunkapi-js. The same data is available as a hosted MCP server for Claude, ChatGPT and Cursor: https://dunkapi.com/mcp. A Python client is on PyPI: pip install dunkapi.
MIT licensed.
