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/clientQuickstart
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
- api.<league>.<table>.list(params?)
- api.<league>.<table>.get(id)
- for await (const row of api.<league>.<table>.iter(params?))
- api.nfl.weeks({ season })
- api.sim.nfl.run({ game_id, n_draws, seed, include, ...overrides })
- api.nba.weeks({ season })
- api.sim.nba.run({ game_id, n_draws, seed, include, ...overrides })
- api.dfs.slates.optimizerLineups(slateId, req) // defaults to mode="fast"
- api.dfs.slates.optimizerLineupsCsv(slateId, req)
- 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.
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/lineupsandPOST /dfs/contests/{contest_id}/optimizer/lineupsdefault tomode: "sim"+strategy: "optimal", returning correlatedgames[].scenarios[]and live NFL/NBAgames[].correlations(override per-game weights or add custom branches withscenarios[]). Explicit caller overrides always win over strategy defaults. CalloptimizerLineupsto run synchronousmode: "fast"MILP. - Synchronous vs. background 202 polling:
simLineupsandcontests.buildLineupspoll202 Acceptedjobs automatically viaGET /api/v1/dfs/jobs/{job_id}(respectingRetry-After), or acceptwait: trueto sendPrefer: waitfor inline completion. UsesimLineupsStart+simJobto manage non-blocking queues explicitly. - Instant pool_id re-selection: read
sim.versions.pool_idfrom any completed build and pass it tosimSelectPoolwith updatedscenarios[], diversity weights, exposure bounds, orinclude_diversity_frontier: truewithout 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.