STAT-API

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@latest

Quickstart

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

Tables & auto-paging
  • client.<League>.<Table>.List(ctx, &params)
  • client.<League>.<Table>.Get(ctx, id)
  • for row, err := range client.<League>.<Table>.All(ctx, &params)
NFL Play-by-Play SIM (beta)
  • client.NFL.Weeks(ctx, &statapi.NFLWeeksParams{...})
  • client.Sim.NFL.Run(ctx, &statapi.NFLSimPublicRunRequest{...})
NBA Possession SIM (beta)
  • client.NBA.Weeks(ctx, &statapi.NBAWeeksParams{...})
  • client.Sim.NBA.Run(ctx, &statapi.NBASimPublicRunRequest{...})
DFS Fast Optimizer & Late Swap (mode="fast")
  • client.DFS.Slates.OptimizerLineups(ctx, slateID, &statapi.OptimizerLineupsRequest{...})
  • client.DFS.Slates.OptimizerLineupsCSV(ctx, slateID, &statapi.OptimizerLineupsRequest{...})
DFS SIM Lineups, Scenarios, Pool Re-Select & Async Jobs
  • 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.

Run your first NFL game simulationOpen full recipe & verified output →
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/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. 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.