Go SDK
The official STAT-API client for Go. A typed wrapper over the REST surface, SIM engines, and DFS optimizers — construct Client and every request and response is statically typed. Version v0.3.1.
Install
go get github.com/stat-api/stat-api/go@latestQuickstart
Construct Client 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 main
import (
"context"
"encoding/json"
"fmt"
statapi "github.com/stat-api/stat-api/go"
"log"
)
func main() {
client, err := statapi.New()
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
// List a few teams
teamsPage, err := client.NBA.Teams.List(ctx, &statapi.NBATeamsListParams{Limit: statapi.Int(3)})
if err != nil {
log.Fatal(err)
}
teams := teamsPage.Rows
// Print what came back
teamsJSON, err := json.MarshalIndent(teams, "", " ")
if err != nil {
log.Fatal(err)
}
fmt.Println(string(teamsJSON))
}Client method reference
- client.<League>.<Table>.List(ctx, ¶ms)
- client.<League>.<Table>.Get(ctx, id)
- for row, err := range client.<League>.<Table>.All(ctx, ¶ms)
- client.NFL.Weeks(ctx, &statapi.NFLWeeksParams{...})
- client.Sim.NFL.Run(ctx, &statapi.NFLSimPublicRunRequest{...})
- client.NBA.Weeks(ctx, &statapi.NBAWeeksParams{...})
- client.Sim.NBA.Run(ctx, &statapi.NBASimPublicRunRequest{...})
- client.DFS.Slates.OptimizerLineups(ctx, slateID, &statapi.OptimizerLineupsRequest{...})
- client.DFS.Slates.OptimizerLineupsCSV(ctx, slateID, &statapi.OptimizerLineupsRequest{...})
- client.DFS.Slates.SimLineups(ctx, slateID, &statapi.SimLineupsRequest{...}, &statapi.SimRequestOptions{Wait: true})
- client.DFS.Contests.BuildLineups(ctx, contestID, &statapi.SimLineupsRequest{...}, &statapi.SimRequestOptions{Wait: true})
- client.DFS.Slates.SimLineupsCSV(ctx, slateID, &statapi.SimLineupsRequest{...}, opts)
- client.DFS.Slates.SimLineupsStart(ctx, slateID, &statapi.SimLineupsRequest{...})
- client.DFS.Slates.SimJob(ctx, slateID, jobID)
- client.DFS.Slates.SimSelectPool(ctx, slateID, &statapi.PortfolioSelectRequest{...})
- client.DFS.Slates.SimLateSwap(ctx, slateID, &statapi.LateSwapRequest{...}, 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 main
import (
"context"
"fmt"
statapi "github.com/stat-api/stat-api/go"
"log"
"sort"
)
func main() {
client, err := statapi.New()
if err != nil {
log.Fatal(err)
}
// Find the free game
ctx := context.Background()
weeks, err := client.NFL.Weeks(ctx, &statapi.NFLWeeksParams{Season: statapi.Int(2026)})
if err != nil {
log.Fatal(err)
}
gameID := weeks.FreeGameID
fmt.Printf("Season %d | free game %d | %d games\n", weeks.Season, gameID, len(weeks.Games))
// Run the game 5,000 times
run, err := client.Sim.NFL.Run(ctx, &statapi.NFLSimPublicRunRequest{
GameID: gameID,
NDraws: statapi.Int(5000),
Seed: statapi.Int64(42),
Include: &statapi.NFLSimInclude{
Summary: statapi.Bool(true),
Distributions: statapi.Bool(false),
Scorebox: statapi.Bool(false),
Pbp: statapi.Bool(false),
},
})
if err != nil {
log.Fatal(err)
}
summary := run.Output.Summary
if summary == nil {
log.Fatal("the run returned no summary")
}
fmt.Printf("Simulated total %.2f (SD %.2f) | home win %.1f%% | home cover %.1f%% | over %.1f%%\n",
summary.SimTotalMean, summary.SimTotalSd, summary.HomeWinProb*100, summary.HomeCoverProb*100, summary.OverProb*100)
checks := "failed"
if summary.ConservationOk {
checks = "passed"
}
fmt.Printf("Box-score checks: %s\n", checks)
// Rank the players
players := summary.Players
sort.Slice(players, func(i, j int) bool { return players[i].RecYdMean > players[j].RecYdMean })
fmt.Println("Top 5 players by mean receiving yards:")
for _, p := range players[:5] {
fmt.Printf(" Player %d (%s/%s) | mean %.1f | median %.1f | 90th percentile %.1f\n",
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.
client.DFS.Slates.OptimizerLineupsCSV(ctx, slateID, &statapi.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 All(). 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.