Java SDK
The official STAT-API client for Java. 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
git clone https://github.com/stat-api/stat-apiBuild from source via the monorepo using Gradle or JitPack while registry publishing completes.
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.
package com.statapi.cookbook;
import com.statapi.StatApi;
import com.statapi.nba.*;
import java.util.*;
public final class NbaHelloStatApi {
public static void main(String[] args) {
StatApi api = new StatApi(); // reads STAT_API_KEY from the environment
// List a few teams
List<NBATeam> teams = api.nba().teams().list(new NBATeamsListParams().limit(3L)).rows();
// Print what came back
System.out.println(teams);
}
}Client method reference
- api.<league>().<table>().list(params)
- api.<league>().<table>().get(id)
- for (var row : api.<league>().<table>().iterate(params))
- api.nfl().weeks(season)
- api.sim().nfl().run(new NFLSimPublicRunRequest(gameId)...)
- api.nba().weeks(season)
- api.sim().nba().run(new NBASimPublicRunRequest(gameId)...)
- api.dfs().slates().optimizerLineups(slateId, new DfsLineups.OptimizerLineupsRequest()...)
- api.dfs().slates().optimizerLineupsCsv(slateId, new DfsLineups.OptimizerLineupsRequest()...)
- api.dfs().slates().simLineups(slateId, req, new DfsLineups.SimRequestOptions().wait(true))
- api.dfs().contests().buildLineups(contestId, req, new DfsLineups.SimRequestOptions().wait(true))
- api.dfs().slates().simLineupsCsv(slateId, req, opts)
- api.dfs().slates().simLineupsStart(slateId, req)
- api.dfs().slates().simJob(slateId, jobId)
- 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.
package com.statapi.cookbook;
import com.statapi.*;
import com.statapi.nfl.*;
import java.util.*;
public final class NFLSimSummary {
public static void main(String[] args) {
StatApi api = new StatApi(); // reads STAT_API_KEY from the environment
// Find the free game
NFLWeeksResponse weeks = api.nfl().weeks(2026);
long gameId = weeks.freeGameId();
System.out.println("Season " + weeks.season() + " | free game " + gameId + " | " + weeks.games().size() + " games");
// Run the game 5,000 times
NFLSimPublicRunResponse run = api.sim().nfl().run(
new NFLSimPublicRunRequest(gameId)
.nDraws(5000)
.seed(42L)
.include(new NFLSimInclude()
.summary(true)
.distributions(false)
.scorebox(false)
.pbp(false)));
NFLSimSummarySection summary = run.output().summary();
if (summary == null) {
throw new IllegalStateException("the run returned no summary");
}
System.out.println(String.format(Locale.ROOT,
"Simulated total %.2f (SD %.2f) | home win %.1f%% | home cover %.1f%% | over %.1f%%",
summary.simTotalMean(), summary.simTotalSd(), summary.homeWinProb() * 100,
summary.homeCoverProb() * 100, summary.overProb() * 100));
System.out.println("Box-score checks: " + (summary.conservationOk() ? "passed" : "failed"));
// Rank the players
List<NFLSimPlayerSummary> players = new ArrayList<>(summary.players());
players.sort(Comparator.comparingDouble(NFLSimPlayerSummary::recYdMean).reversed());
System.out.println("Top 5 players by mean receiving yards:");
for (NFLSimPlayerSummary p : players.subList(0, 5)) {
System.out.println(String.format(Locale.ROOT,
" Player %d (%s/%s) | mean %.1f | median %.1f | 90th percentile %.1f",
p.playerId(), p.position(), p.depthRole(), p.recYdMean(), p.recYdP50(), p.recYdP90()));
}
}
}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, new DfsLineups.OptimizerLineupsRequest()...)) 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 iterate(). 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.