fastballapi
v0.2.0
Published
JavaScript and TypeScript client for the FastballAPI MLB data API: stats, play-by-play, odds and player props. No dependencies.
Maintainers
Readme
fastballapi
MLB data and odds API. JavaScript and TypeScript client for the FastballAPI MLB 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 FASTBALLAPI_API_KEY to your key (free at https://fastballapi.com/signup) and run this. get_standings costs 2 credits.
import json, os, urllib.request
req = urllib.request.Request(
"https://mcp.fastballapi.com/v1/get_standings",
data=json.dumps({"season": 2025}).encode(),
headers={"x-api-key": os.environ["FASTBALLAPI_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.fastballapi.com/v1/, JSON in, {"data": ...} out, with X-Credits-Used and X-Credits-Remaining headers.
FastballAPI at a glance
- MLB data and odds API: MLB since 2015 plus college: pitches, plate appearances, box scores, odds by book. REST and MCP.
- 26 tools, every one on the free plan. Each call costs 1 to 10 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.fastballapi.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.fastballapi.com/v1/ with your key in an
x-api-keyheader and the arguments as a JSON body. - Python:
pip install fastballapi. JavaScript:npm install fastballapi - Pitch-by-pitch: Since 2015. Every pitch of every final game since 2018, with type, velocity, location and count; pitch counts match the box score to within 0.05% a season. 2015 to 2017 are included too, with about 98 to 99% of each season's pitches.
- Run values: RE24. A run value on every plate appearance, from each season's own run expectancy table.
- Sportsbook lines: 4 to 13 books. Each sportsbook's moneyline, run line and total, 4 to 13 books per game from 2015 to 2023 (about 4 in 2015, 10 in 2016 and 2017, 7 to 8 in 2018 to 2020 and 12 in 2021 to 2023), and opening and closing lines from 6 to 8 books per game since July 2020.
| Credits | Tools | | --- | --- | | 1 | get_data_status, list_teams, search_players | | 2 | get_games, get_schedule, get_standings, get_injuries, get_ratings | | 5 | get_game, get_player, get_player_games, get_leaders, get_team_stats, get_pitch_mix, get_odds, get_line_at_time, get_rest_and_travel | | 10 | get_plate_appearances, get_pitches, get_spray_chart, get_line_movement, get_player_props, get_prop_history, get_prop_movement, get_market_odds, get_alt_lines |
- 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 fastballapiGet a free key (500 credits every month, no card) at https://fastballapi.com/signup?utm_source=npm&utm_medium=readme&utm_campaign=fastballapi-js and set FASTBALLAPI_API_KEY.
import { Client } from "fastballapi"
const client = new Client() // reads FASTBALLAPI_API_KEY, or new Client({ apiKey: "..." })
const data = await client.getPlayerProps({"game_id":"401815991","market":"batter_home_runs"})
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("games", 2025) // first call: pages through the API
const again = await client.loadSeason("games", 2025) // second call: read from ~/.cache/fastballapi/, no requests
await client.loadSeason("games", 2025, { refresh: true }) // pull againSeasons are calendar years.
| Dataset | Tool | What a row is | Requests for a typical season | Credits for a typical season |
| --- | --- | --- | --- | --- |
| games | getGames | one row per game with scores | 13 | 26 |
| plate_appearances | getPlateAppearances | every plate appearance with base-out state and run value, one request per played game | 2,513 | 25,026 |
| odds | getOdds | one row per game and sportsbook, one request per played game | 2,513 | 12,526 |
| props | getPlayerProps | every sportsbook prop line, one request per played game | 2,513 | 25,026 |
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("plate_appearances", 2025, { estimate: true }))
// { dataset: "plate_appearances", 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/fastballapi/(cacheDirorFASTBALLAPI_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 |
| getGames | 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 |
| getPlateAppearances | Plate appearances | 10 |
| getPitches | Pitches | 10 |
| getPitchMix | Pitch mix | 5 |
| getSprayChart | Spray 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 |
| getAltLines | Alt lines | 10 |
| getDataStatus | Data status | 1 |
Full reference with response shapes: https://fastballapi.com/docs?utm_source=npm&utm_medium=readme&utm_campaign=fastballapi-js. The same data is available as a hosted MCP server for Claude, ChatGPT and Cursor: https://fastballapi.com/mcp. A Python client is on PyPI: pip install fastballapi.
MIT licensed.
