MLB Stats API
Official MLB statistics — teams, players, games and standings.
What it does
The MLB Stats API (statsapi.mlb.com) is Major League Baseball’s own public data service: schedules and scores, live game feeds pitch-by-pitch, box scores, standings, team and player data, rosters, stats splits, and historical seasons back over a century.
Base URL
Authentication
None — it is publicly reachable with no key. It is not officially documented for third-party use, and MLB’s terms restrict commercial use, so treat it as best-effort and read MLB’s copyright notice.
Code examples
curl -s "https://statsapi.mlb.com/api/v1/schedule?sportId=1&date=2026-04-01" curl -s "https://statsapi.mlb.com/api/v1/standings?leagueId=103,104&season=2025"
import requests
sched = requests.get("https://statsapi.mlb.com/api/v1/schedule",
params={"sportId": 1, "date": "2025-07-04"}, timeout=10).json()
game_pk = sched["dates"][0]["games"][0]["gamePk"]
ls = requests.get(f"https://statsapi.mlb.com/api/v1/game/{game_pk}/linescore", timeout=10).json()
print(ls["teams"]["home"]["runs"], "-", ls["teams"]["away"]["runs"])Rate limits & quotas
No published rate limit, but it is a courtesy resource — cache aggressively, don’t poll live feeds faster than every 10–15 seconds, and identify your client with a User-Agent. The live feed (/game/{gamePk}/feed/live) is large; use /feed/live/diffPatch or the linescore/boxscore endpoints for lighter polling.
Key response fields
| (schedule) dates[].games[].gamePk / gameDate / status.detailedState | Game id, time and state |
| (schedule) ….teams.home.team.name / teams.home.score | Matchup and score |
| (standings) records[].teamRecords[].wins / losses / divisionRank | Standings rows |
| (boxscore) teams.home.players | Per-player batting/pitching lines keyed by IDxxxxxx |
| (people) people[].fullName / primaryPosition / currentTeam | Player bio |
Common errors
| 404 | Bad gamePk, or a date/endpoint combination with no data. |
| (huge payloads) | The full live feed is megabytes — request only the sub-resource you need. |
| (schema depth) | Responses are deeply nested and undocumented officially — lean on community docs (e.g. the ‘MLB-StatsAPI’ wrappers). |
When to use it (and alternatives)
The definitive free source for MLB data — scoreboards, standings widgets, fantasy tools, historical analysis. Its NHL equivalent is api-web.nhle.com; for NBA, balldontlie.
FAQ
Is there official documentation?
Not really — MLB provides the endpoint but not third-party docs. Community resources (the MLB-StatsAPI Python/JS wrappers and their wikis) map out the endpoints and parameters.
Can I use it in a commercial product?
MLB’s terms restrict commercial use of its data and marks. For a hobby or internal tool it is widely used; for anything commercial, get a proper data licence.
How do I follow a game live?
Poll /game/{gamePk}/linescore or /boxscore every 10–15 seconds, or use /feed/live/diffPatch?startTimecode= to fetch only what changed since your last poll.
New to APIs?
Short guides for working with this API — and any other.