STAT-API
← DFS Cookbook

Apply mutual-exclusion, membership pool, and capped atomic player groups

`player_groups` supports three distinct idioms in one solve: at-most-one mutex (`min_players: 0, max_players: 1`), membership pools (`min_players` / `max_players`), and exposure-capped atomic groups (`max_exposure_pct` with `min_players` and `max_players` omitted). Combine cleanly with `exclude_teams` and `exclude_games`.

What it is
Builds 10 NFL lineups on slate `1126128` excluding team `LV` and game `43547` while enforcing an RB mutex, a 1-to-2 core WR pool, and a 40%-capped atomic QB+WR group.
When to use it
Use this when modeling complex roster dependencies across multiple players plus game-level or team-level fades.
What you get back
Portfolio breadth, caller-excluded count, realized player exposures, and top stacked lineups honoring every group and exclusion rule.

1.Optimize 10 lineups with 3 group idioms and exclusions

Exclude `LV` and game `43547`, enforce an RB mutex (`min_players: 0, max_players: 1`), require 1–2 WRs from a 3-player core, and cap an atomic QB+WR combo at 40%.

POST request (requires your API key in STAT_API_KEY). Run the SDK program on the right or the curl snippet below.

{
  "lineup_count": 10,
  "min_unique_players": 2,
  "exclude_teams": [
    "LV"
  ],
  "exclude_games": [
    43547
  ],
  "player_groups": [
    {
      "slate_player_ids": [
        44186556,
        44186564
      ],
      "min_players": 0,
      "max_players": 1
    },
    {
      "slate_player_ids": [
        44186570,
        44186568,
        44186574
      ],
      "min_players": 1,
      "max_players": 2
    },
    {
      "slate_player_ids": [
        44186595,
        44186568
      ],
      "max_exposure_pct": 40
    }
  ],
  "response_format": "json"
}
const groupsRes = await api.dfs.slates.optimizerLineups(1126128, { lineup_count: 10, min_unique_players: 2, exclude_teams: ["LV"], exclude_games: [43547], player_groups: [{ slate_player_ids: [44186556, 44186564], min_players: 0, max_players: 1 }, { slate_player_ids: [44186570, 44186568, 44186574], min_players: 1, max_players: 2 }, { slate_player_ids: [44186595, 44186568], max_exposure_pct: 40 }] })

Every step as one runnable file. It reads STAT_API_KEY from the environment, and is the same file that ships in the cookbook project for each SDK.

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

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

// Optimize 10 lineups with 3 group idioms and exclusions
const groupsRes = await api.dfs.slates.optimizerLineups(1126128, { lineup_count: 10, min_unique_players: 2, exclude_teams: ["LV"], exclude_games: [43547], player_groups: [{ slate_player_ids: [44186556, 44186564], min_players: 0, max_players: 1 }, { slate_player_ids: [44186570, 44186568, 44186574], min_players: 1, max_players: 2 }, { slate_player_ids: [44186595, 44186568], max_exposure_pct: 40 }] })

// Print exclusion count and realized group exposures
const p = groupsRes.portfolio
const excl = groupsRes.diagnostics.excluded?.by_caller ?? 0
const shortfalls = (p.min_exposure_shortfalls ?? []).length
console.log(`Slate ${groupsRes.slate.id} (${groupsRes.slate.league}/${groupsRes.slate.operator}) | source=${groupsRes.source.name} lineups=${p.lineup_count} unique=${p.unique_players} mean_pts=${p.mean_projected_points.toFixed(2)}`)
console.log(`Diversity pds=${p.diversity.composite_diversity_score.toFixed(2)} overlap=${p.mean_pairwise_overlap.toFixed(2)} max_overlap=${p.diversity.max_pair_overlap} eff_shannon=${p.diversity.effective_players_shannon.toFixed(2)} excluded=${excl} shortfalls=${shortfalls}`)
const sortedExps = [...p.exposures].sort((a, b) => b.lineups - a.lineups || a.slate_player_id - b.slate_player_id)
for (const e of sortedExps.slice(0, 8)) {
  console.log(`Exposure ${e.name ?? ''} (${e.team ?? ''}) | lineups=${e.lineups}/${p.lineup_count} pct=${e.exposure_pct.toFixed(2)}%`)
}
for (const l of groupsRes.lineups.slice(0, 3)) {
  console.log(`Lineup #${l.rank} | salary=${l.salary} pts=${l.projected_points.toFixed(2)} stack=${l.stack.summary}`)
}

Verified output across all 4 SDKs

TypeScript, Python, Go, and Java execute cleanly and print byte-identical output:

Slate 1126128 (nfl/draftkings) | source=STAT_API_LATEST lineups=10 unique=23 mean_pts=153.77
Diversity pds=0.54 overlap=5.29 max_overlap=7 eff_shannon=16.98 excluded=72 shortfalls=0
Exposure Justin Jefferson (MIN) | lineups=10/10 pct=100.00%
Exposure Emmett Johnson (KC) | lineups=10/10 pct=100.00%
Exposure Bijan Robinson (ATL) | lineups=8/10 pct=80.00%
Exposure Gavin Bartholomew (MIN) | lineups=8/10 pct=80.00%
Exposure CeeDee Lamb (DAL) | lineups=7/10 pct=70.00%
Exposure Colts (IND) | lineups=7/10 pct=70.00%
Exposure Drake London (ATL) | lineups=5/10 pct=50.00%
Exposure Tyler Warren (IND) | lineups=5/10 pct=50.00%
Lineup #1 | salary=50000 pts=154.90 stack=QB+1 (NO) + 1 Opp (CAR)
Lineup #2 | salary=49900 pts=154.57 stack=QB+1 (NO)
Lineup #3 | salary=50000 pts=154.18 stack=QB+1 (DAL)