Fix

Sports API pagination and timeouts: retry safely

Short answer: page through results by following next_offset until it is null, and send a stable x-request-id on every call. A retry with the same id, tool and arguments inside two minutes is not charged again. Back off on 429 and 5xx, and re-pull a date range in small windows.

What goes wrong

A season of play-by-play, shots or game logs does not fit in one response, so every large endpoint pages. The failures come from five habits:

  1. Stopping on a short page. Some pages are short for a reason that is not the end of the data. The only signal for the end is next_offset being null.
  2. Retrying with a fresh id. A timeout does not tell you whether the server ran the call. If it did, a retry without a stable id pays twice.
  3. Hammering after a 429. Retrying instantly makes the limit worse and burns time.
  4. Silent filters. A parameter name the server does not know is ignored, not rejected. A range pull with the wrong parameter names returns the wrong rows with HTTP 200.
  5. Restarting from page one. A crash at page 40 of 50 should not cost 40 pages again.

How paging works

Endpoints that return many rows take limit and offset. A response includes a next_offset number when more rows remain, and null when you have the last page. We checked three cases on December 6, 2026:

EndpointDefault / max pageResult of the check
get_shot_map1,000 / 2,000 shotsA team's season came back as three pages of 2,000, 2,000 and 356 shots, with next_offset 2000, 4000, null
get_player_game_log100 / 200 gameslimit 10 returned 82 games over nine pages, next_offset null on the ninth
get_games100 / 500 gamesNo offset. Use date windows and keep limit above what a window can hold

Pages are chronological, so a page boundary does not reorder rows. Each page is billed at the endpoint's price: 10 credits for a shot-map page and 5 for a game-log page. A smaller limit makes more calls and costs more in total, so use the largest page you can handle.

Some endpoints continue by date instead of offset. get_player_props returns next_from_date, and you pass it back as from_date.

Retries and idempotency

Send the header x-request-id (or x-idempotency-key) on each call. The server builds a dedupe key from your account, the request id, the tool and a hash of the arguments, bucketed into two-minute windows. A repeat call inside the window returns data again but is charged 0 credits. We verified it with two identical calls to get_player_game_log: the first returned x-credits-used: 5 and the second returned x-credits-used: 0.

Three consequences:

A paging helper with retries

This helper retries 429 and 5xx responses and network timeouts with exponential backoff, keeps the request id stable per page, and asserts that no row appears twice. Set PUCKAPI_API_KEY first. The run below cost 45 credits.

import json, os, time, uuid, urllib.error, urllib.request

BASE = "https://mcp.puckapi.com/v1"
KEY = os.environ["PUCKAPI_API_KEY"]


def call(tool, body, request_id, retries=5):
    """POST one tool call. The same request_id on a retry is not charged twice."""
    for attempt in range(retries):
        req = urllib.request.Request(
            f"{BASE}/{tool}",
            data=json.dumps(body).encode(),
            headers={"Content-Type": "application/json", "x-api-key": KEY, "x-request-id": request_id},
        )
        try:
            with urllib.request.urlopen(req, timeout=30) as resp:
                return json.load(resp)["data"], resp.headers.get("x-credits-used")
        except urllib.error.HTTPError as err:
            if err.code not in (429, 500, 502, 503, 504) or attempt == retries - 1:
                raise
        except (TimeoutError, urllib.error.URLError):
            if attempt == retries - 1:
                raise
        time.sleep(min(2 ** attempt, 30))  # 1, 2, 4, 8, 16 seconds


def pull_all(tool, body, key, run_id):
    """Follow next_offset to the end. Request ids are stable per page, so a retried page is free."""
    rows, offset, page_no = [], 0, 0
    while offset is not None:
        page, used = call(tool, {**body, "offset": offset}, f"{run_id}-{tool}-{page_no}")
        rows += page[key]
        print(f"page {page_no}: offset {offset}, {len(page[key])} rows, credits {used}")
        offset, page_no = page.get("next_offset"), page_no + 1
    return rows


run_id = f"demo-{uuid.uuid4().hex[:8]}"
games = pull_all("get_player_game_log", {"player_id": 8478402, "season": "20252026", "limit": 10}, "games", run_id)
print(len(games), "games; first", games[0]["gameDate"], "last", games[-1]["gameDate"])
ids = [g["gameId"] for g in games]
assert len(ids) == len(set(ids)), "duplicate rows across pages"
print("no duplicates across pages")

The run printed nine pages, 82 games from 2025-10-08 to 2026-04-16, and passed the duplicate check. The same behavior shows in plain curl. Run this twice within two minutes and compare the x-credits-used header:

curl -s -D - -o /dev/null -X POST https://mcp.puckapi.com/v1/get_player_game_log \
  -H "Content-Type: application/json" -H "x-api-key: $KEY" -H "x-request-id: my-job-0001" \
  -d '{"player_id": 8478402, "season": "20252026", "limit": 2}' | grep -i x-credits

Rate limits

The server allows 60 requests a minute per account, falling to 10 a minute when the credit balance is low. Over the limit you get HTTP 429 and a JSON body saying the rate limit was exceeded. There is no Retry-After header, so the backoff above is your schedule. If you run parallel workers, share one limiter across them. Five parallel sessions on one key tripped the limit for us on December 2.

Re-pulling a date range

When a job fails halfway, resume from a checkpoint instead of starting over:

  1. Pull in small windows, such as one week per call, so a failed window is cheap to repeat.
  2. Write each finished window to disk with its parameters before starting the next.
  3. On restart, skip windows that are on disk and repeat only the missing ones.
  4. Check the parameter names against the docs. get_games takes date_from and date_to. In our test, from_date and to_date were silently ignored and the call returned games from April 2027 with HTTP 200. Always assert that the dates in the response fall inside the range you asked for.
  5. Treat a window whose row count equals limit as possibly truncated, and split it.

Rows overwritten by a source correction are replaced in place, and no revision history is kept. A re-pull of an old range can therefore differ from the first pull. Store the pull date with each batch.

When not to use this

Get a free key

Checked against the live API on 2026-12-06. Questions: hello@sportsdatahq.com.