Skip to content

Guides

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 October 10, 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.

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": "401908007",
      "pitch_number": 1,
      "inning": 1,
      "balls": 0,
      "strikes": 0,
      "pitch_type": "FF",
      "velocity": 98,
      "px": 107,
      "py": 201,
      "result": "ball"
    },
    {
      "game_id": "401908007",
      "pitch_number": 2,
      "inning": 1,
      "balls": 1,
      "strikes": 0,
      "pitch_type": "FF",
      "velocity": 97,
      "px": 114,
      "py": 186,
      "result": "strike-looking"
    },
    "...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.

More guides

Start with 500 free credits

No card. REST or MCP.