API Directory › ⚽ Sports › MLB Stats API
No authHTTPS

MLB Stats API

Official MLB statistics — teams, players, games and standings.

Category
Auth
No auth needed
HTTPS
Yes
CORS
Unknown
Open MLB Stats API docs ↗

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

https://statsapi.mlb.com/api/v1

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
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"
Python (a game's line score)
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.detailedStateGame id, time and state
(schedule) ….teams.home.team.name / teams.home.scoreMatchup and score
(standings) records[].teamRecords[].wins / losses / divisionRankStandings rows
(boxscore) teams.home.playersPer-player batting/pitching lines keyed by IDxxxxxx
(people) people[].fullName / primaryPosition / currentTeamPlayer bio

Common errors

404Bad 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.

🛠️ Handy LarzOS tools

Free tools to help you work with this API.

JSON Formatter

Related Sports APIs

← Back

More Sports APIs · All 196 APIs