# Baseball Stats API
> Baseball sabermetrics as an API, computed locally and deterministically — turn raw counting numbers into the rate stats that actually rank players. The batting endpoint takes at-bats, hits, doubles, triples, home runs, walks, hit-by-pitch and sacrifice flies and returns the batting average (H/AB), on-base percentage ((H+BB+HBP)/(AB+BB+HBP+SF)), slugging percentage (total bases/AB), OPS (on-base plus slugging), isolated power (SLG−AVG) and, when strikeouts are supplied, BABIP — a classic .300/.366/.530 line comes straight out. The pitching endpoint takes innings pitched, earned runs, hits, walks, strikeouts and home runs and returns the earned run average (9·ER/IP), WHIP ((BB+H)/IP), strikeouts and walks per nine innings, the strikeout-to-walk ratio and FIP, the fielding-independent pitching estimator (13·HR + 3·(BB+HBP) − 2·K)/IP + constant. Innings pitched is a true decimal, with an exact "outs" input for the 6.1/6.2 box-score convention. Everything is computed locally and deterministically, so it is instant and private. Ideal for fantasy-baseball, sports-analytics, sabermetrics and box-score app developers, scouting and stat-line tools, and teaching material. Pure local computation — no key, no third-party service, instant. Live, nothing stored. 2 compute endpoints. This computes the stats from your numbers; for live scores, standings, teams and players use a sports-data API.

## Authentication
All requests require your oanor API key in the `x-oanor-key` header. Get one at https://www.oanor.com/developer/keys.

```bash
curl -H "x-oanor-key: oanor_live_…" "https://api.oanor.com/baseball-api/..."
```

## Pricing
- **Free** (Free) — 5,350 calls/Mo, 2 req/s
- **Starter** ($4/Mo) — 54,000 calls/Mo, 6 req/s
- **Pro** ($12/Mo) — 246,000 calls/Mo, 15 req/s
- **Mega** ($37/Mo) — 1,330,000 calls/Mo, 40 req/s

## Endpoints

### Baseball

#### `GET /v1/batting` — Batting rate stats

**Parameters:**
- `at_bats` (query, required, string) — At-bats (AB) Example: `500`
- `hits` (query, required, string) — Hits (H) Example: `150`
- `doubles` (query, optional, string) — Doubles (2B) Example: `30`
- `triples` (query, optional, string) — Triples (3B) Example: `5`
- `home_runs` (query, optional, string) — Home runs (HR) Example: `25`
- `walks` (query, optional, string) — Walks (BB) Example: `50`
- `hit_by_pitch` (query, optional, string) — Hit by pitch (HBP) Example: `5`
- `sacrifice_flies` (query, optional, string) — Sacrifice flies (SF) Example: `5`
- `strikeouts` (query, optional, string) — Strikeouts (for BABIP) Example: `100`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/baseball-api/v1/batting?at_bats=500&hits=150&doubles=30&triples=5&home_runs=25&walks=50&hit_by_pitch=5&sacrifice_flies=5&strikeouts=100"
```

**Response:**
```json
{
    "data": {
        "avg": 0.3,
        "iso": 0.23,
        "obp": 0.366,
        "ops": 0.896,
        "slg": 0.53,
        "note": "AVG = H/AB; OBP = (H+BB+HBP)/(AB+BB+HBP+SF); SLG = total bases/AB; OPS = OBP+SLG; ISO = SLG−AVG. BABIP needs strikeouts.",
        "babip": 0.329,
        "inputs": {
            "hits": 150,
            "walks": 50,
            "at_bats": 500,
            "doubles": 30,
            "triples": 5,
            "home_runs": 25,
            "strikeouts": 100,
            "hit_by_pitch": 5,
            "sacrifice_flies": 5
        },
        "singles": 90,
        "total_bases": 265
    },
    "meta": {
        "timestamp": "2026-06-05T19:50:09.638Z",
        "request_id": "db9bd112-3b9f-43aa-adee-84b776f1ec5c"
    },
    "status": "ok",
    "message": "Batting stats",
    "success": true
}
```

#### `GET /v1/pitching` — Pitching rate stats

**Parameters:**
- `innings_pitched` (query, optional, string) — Innings (true decimal) Example: `200`
- `outs` (query, optional, string) — Outs recorded (alt to innings)
- `earned_runs` (query, optional, string) — Earned runs (ER) Example: `70`
- `hits_allowed` (query, optional, string) — Hits allowed (H) Example: `180`
- `walks` (query, optional, string) — Walks (BB) Example: `50`
- `strikeouts` (query, optional, string) — Strikeouts (K) Example: `200`
- `home_runs` (query, optional, string) — Home runs (HR) Example: `20`
- `hit_by_pitch` (query, optional, string) — Hit by pitch (HBP) Example: `5`
- `fip_constant` (query, optional, string) — FIP constant (default 3.10)

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/baseball-api/v1/pitching?innings_pitched=200&earned_runs=70&hits_allowed=180&walks=50&strikeouts=200&home_runs=20&hit_by_pitch=5"
```

**Response:**
```json
{
    "data": {
        "era": 3.15,
        "fip": 3.23,
        "note": "ERA = 9·ER/IP; WHIP = (BB+H)/IP; FIP = (13·HR + 3·(BB+HBP) − 2·K)/IP + constant (~3.10). Innings is a true decimal — use 'outs' for the box-score 6.1/6.2 convention.",
        "whip": 1.15,
        "inputs": {
            "walks": 50,
            "home_runs": 20,
            "strikeouts": 200,
            "earned_runs": 70,
            "fip_constant": 3.1,
            "hit_by_pitch": 5,
            "hits_allowed": 180,
            "innings_pitched": 200
        },
        "h_per_9": 8.1,
        "k_per_9": 9,
        "bb_per_9": 2.25,
        "hr_per_9": 0.9,
        "k_bb_ratio": 4
    },
    "meta": {
        "timestamp": "2026-06-05T19:50:09.740Z",
        "request_id": "8b76bd97-c8ef-490f-87b7-06fa5b4233cb"
    },
    "status": "ok",
    "message": "Pitching stats",
    "success": true
}
```

### Meta

#### `GET /v1/meta` — Spec

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/baseball-api/v1/meta"
```

**Response:**
```json
{
    "data": {
        "notes": "Counting stats in, rate stats out. Innings pitched is a true decimal; pass 'outs' to express the 6.1/6.2 box-score convention exactly. For live scores and standings use a sports-data API.",
        "service": "baseball-api",
        "endpoints": {
            "GET /v1/meta": "This document.",
            "GET /v1/batting": "Batting rate stats from AB, H, 2B, 3B, HR, BB, HBP, SF (+K for BABIP).",
            "GET /v1/pitching": "Pitching rate stats from IP (or outs), ER, H, BB, K, HR, HBP."
        },
        "description": "Baseball sabermetrics: batting (AVG, OBP, SLG, OPS, ISO, BABIP) and pitching (ERA, WHIP, K/9, FIP) rate stats from counting numbers."
    },
    "meta": {
        "timestamp": "2026-06-05T19:50:09.851Z",
        "request_id": "3afc4caf-d350-4f82-bc0d-94964e001d76"
    },
    "status": "ok",
    "message": "Meta",
    "success": true
}
```


---
Marketplace page: https://www.oanor.com/api/baseball-api
OpenAPI spec: https://www.oanor.com/api/baseball-api/openapi.json
