STAT-API

TypeScript SDK

The official STAT-API client for TypeScript. A typed wrapper over the REST surface, SIM engines, and DFS optimizers — construct StatApi and every request and response is statically typed. Version v0.3.1.

Install

npm install @stat-api/client

Quickstart

Construct StatApi with STAT_API_KEY set, list rows, and print them.

// Hello, NBA
// Generated from schema/api/examples/hello-stat-api.yml — do not edit.

import { StatApi } from '@stat-api/client'

const api = new StatApi() // reads STAT_API_KEY from the environment

// List a few teams
const teams = (await api.nba.teams.list({ limit: 3 })).teams

// Print what came back
console.log(JSON.stringify(teams, null, 2))

Client method reference

Tables & auto-paging
  • api.<league>.<table>.list(params?)
  • api.<league>.<table>.get(id)
  • for await (const row of api.<league>.<table>.iter(params?))
NFL Play-by-Play SIM (beta)
  • api.nfl.weeks({ season })
  • api.sim.nfl.run({ game_id, n_draws, seed, include, ...overrides })
NBA Possession SIM (beta)
  • api.nba.weeks({ season })
  • api.sim.nba.run({ game_id, n_draws, seed, include, ...overrides })
DFS Fast Optimizer & Late Swap (mode="fast")
  • api.dfs.slates.optimizerLineups(slateId, req) // defaults to mode="fast"
  • api.dfs.slates.optimizerLineupsCsv(slateId, req)
DFS SIM Lineups, Scenarios, Pool Re-Select & Async Jobs
  • api.dfs.slates.simLineups(slateId, req, { wait: true }) // default mode="sim" + strategy="optimal"
  • api.dfs.contests.buildLineups(contestId, req, { wait: true })
  • api.dfs.slates.simLineupsCsv(slateId, req, opts?)
  • api.dfs.slates.simLineupsStart(slateId, req)
  • api.dfs.slates.simJob(slateId, jobId) // GET /api/v1/dfs/jobs/{job_id}
  • api.dfs.slates.simSelectPool(slateId, req)
  • api.dfs.slates.simLateSwap(slateId, req, opts?)

SIM & Optimizer starter templates

Copy-pasteable runnable templates generated from the same YAML specs as the cookbook, verified to produce identical output across all 4 languages.

Run your first NFL game simulationOpen full recipe & verified output →
import { StatApi } from '@stat-api/client'

const api = new StatApi() // reads STAT_API_KEY from the environment

// Find the free game
const weeks = await api.nfl.weeks({ season: 2026 });
const gameId = weeks.free_game_id;
console.log(`Season ${weeks.season} | free game ${gameId} | ${weeks.games.length} games`);

// Run the game 5,000 times
const run = await api.sim.nfl.run({
  game_id: gameId,
  n_draws: 5000,
  seed: 42,
  include: {
    summary: true,
    distributions: false,
    scorebox: false,
    pbp: false,
  },
});
const summary = run.output.summary;
if (!summary) throw new Error('the run returned no summary');
console.log(
  `Simulated total ${summary.sim_total_mean.toFixed(2)} (SD ${summary.sim_total_sd.toFixed(2)}) | ` +
    `home win ${(summary.home_win_prob * 100).toFixed(1)}% | ` +
    `home cover ${(summary.home_cover_prob * 100).toFixed(1)}% | ` +
    `over ${(summary.over_prob * 100).toFixed(1)}%`,
);
console.log(`Box-score checks: ${summary.conservation_ok ? 'passed' : 'failed'}`);

// Rank the players
const top = [...summary.players].sort((a, b) => b.rec_yd_mean - a.rec_yd_mean).slice(0, 5);
console.log('Top 5 players by mean receiving yards:');
for (const p of top) {
  console.log(
    `  Player ${p.player_id} (${p.position}/${p.depth_role}) | mean ${p.rec_yd_mean.toFixed(1)} | ` +
      `median ${p.rec_yd_p50.toFixed(1)} | 90th percentile ${p.rec_yd_p90.toFixed(1)}`,
  );
}

Unified modes, scenarios, async 202 jobs & <50ms pool re-selection

  • Zero-param optimal SIM & execution modes: both POST /dfs/slates/{slate_id}/optimizer/lineups and POST /dfs/contests/{contest_id}/optimizer/lineups default to mode: "sim" + strategy: "optimal", returning correlated games[].scenarios[] and live NFL/NBA games[].correlations (override per-game weights or add custom branches with scenarios[]). Explicit caller overrides always win over strategy defaults. Call optimizerLineups to run synchronous mode: "fast" MILP.
  • Synchronous vs. background 202 polling: simLineups and contests.buildLineups poll 202 Accepted jobs automatically via GET /api/v1/dfs/jobs/{job_id} (respecting Retry-After), or accept wait: true to send Prefer: wait for inline completion. Use simLineupsStart + simJob to manage non-blocking queues explicitly.
  • Instant pool_id re-selection: read sim.versions.pool_id from any completed build and pass it to simSelectPool with updated scenarios[], diversity weights, exposure bounds, or include_diversity_frontier: true without re-simulating draws.
  • Direct operator CSV strings: call the CSV helper (e.g. api.dfs.slates.optimizerLineupsCsv(slateId, req)) to receive ready-to-upload rows preserving Entry IDs on late swap.

Authentication, pagination & errors

Reads STAT_API_KEY automatically (default base URL https://api.stat-api.com). Get a key on the pricing page.

Table endpoints return bounded pages with next_from_id or stream all rows via iter(). HTTP failures raise typed StatApiError subclasses (AuthenticationError 401, PlanRequiredError 402, ValidationError 400, NotFoundError 404, QuotaExceededError 429) with Quota counts from X-Quota-* headers.

Free SIM games: NFL 43418 (2026 Week 1 DEN @ KC) and NBA 6029936 (DET @ BOS); other games require a Pro or Elite plan, or the DFS add-on.