Where do I get MLB pitch-by-pitch data for a model?
Every pitch a pitcher threw, with count, type, velocity, location and result, loaded into pandas with a swinging-strike label ready for a classifier.
Code verified November 18, 2026. One call to get_pitches, 10 credits.
The call
pitcher_id comes from search_players. Page with offset to get the whole season.
import requests
import pandas as pd
API_KEY = "YOUR_API_KEY"
resp = requests.post(
"https://mcp.fastballapi.com/v1/get_pitches",
headers={"x-api-key": API_KEY},
json={
"pitcher_id": "42409",
"season": 2026,
"limit": 500,
},
timeout=60,
)
resp.raise_for_status()
data = resp.json()["data"]
pitches = pd.DataFrame(data["pitches"])
pitches["whiff"] = (pitches["result"] == "strike-swinging").astype(int)
features = pitches[["balls", "strikes", "pitch_type", "velocity", "px", "py", "whiff"]]
print(features.head())
print(features.groupby("pitch_type")[["velocity", "whiff"]].mean().round(3))
Replace YOUR_API_KEY with a key from your dashboard. Python needs requests and pandas (pip install requests pandas). JavaScript runs on Node 18 or newer, or in the browser.
Or use the official client: pip install fastballapi
What comes back
The data object of the response, trimmed to the first rows. Every field is real output from the run above.
{
"pitches": [
{
"game_id": "401908030",
"pitch_number": 1,
"inning": 1,
"balls": 0,
"strikes": 0,
"pitch_type": "FF",
"velocity": 97,
"px": 145,
"py": 176,
"result": "strike-looking"
},
{
"game_id": "401908030",
"pitch_number": 2,
"inning": 1,
"balls": 0,
"strikes": 1,
"pitch_type": "SI",
"velocity": 97,
"px": 153,
"py": 162,
"result": "strike-swinging"
},
"...498 more"
],
"count": 500,
"next_offset": 500
}What to do next
- get_pitch_mix (5 credits). The same arsenal already rolled up: usage, velocity and whiff rate per pitch type.
- get_plate_appearances (10 credits). Plate-appearance outcomes with base-out state and run value, to label pitches by what the at-bat became.
The data this uses
Every row above comes from MLB pitch-by-pitch data. MLB pitch-by-pitch since 2015 (about 98% of games to 2017, all from 2018): pitch type, velocity, location and the count, with the plate appearance. REST or MCP.
More guides
Rather ask Claude? 16 free Claude skills call these endpoints for you.
Start with 500 free credits every month
No card. REST or MCP.