Odds API tutorial: live odds in five minutes
Odds API tutorial: get a key, check the connection, find events, pull odds and go real-time with copy-paste examples in cURL, Node.js and Python.
Get an API key
Create a free account and copy the key it shows you. The free Sandbox's 50 credits work on the API (pre-game odds, events, scores, player props and best lines at 20 requests a minute; futures and line history start on Edge), and Edge, Sharp or Syndicate add credits and features. Sandbox keys look like
pa_test_…, paid plans'pa_live_….Store it as an environment variableexport PRECISEAPI_KEY="pa_live_your_key_here"Check the connection
/v1/statusis free. It confirms your key works and shows the health of every source. For an uptime monitor that shouldn't hold a key, use/v1/health: no key, no credits, never any prices, up to 60 checks a minute per IP address.curl "https://api.preciseapi.com/v1/status" \ -H "Authorization: Bearer $PRECISEAPI_KEY"Find events
List upcoming and live NBA games. Each event has a stable id you can reuse across every other endpoint.
curl "https://api.preciseapi.com/v1/events?league=nba&limit=5" \ -H "Authorization: Bearer $PRECISEAPI_KEY"Pull odds
Fetch moneylines and spreads from Pinnacle and DraftKings for every NBA game in one call.
curl "https://api.preciseapi.com/v1/odds?league=nba&markets=moneyline,spread&books=pinnacle,draftkings" \ -H "Authorization: Bearer $PRECISEAPI_KEY"Response (trimmed){ "data": [ { "id": "evt_1iazqk4srnb", "league": "nba", "sport": "basketball", "competition": "National Basketball Association", "start_time": "2026-10-14T23:50:00.000Z", "start_time_tbd": false, "start_time_disputed": false, "status": "scheduled", "home": { "id": "nba_phx", "name": "Phoenix Suns", "abbr": "PHX" }, "away": { "id": "nba_sas", "name": "San Antonio Spurs", "abbr": "SAS" }, "score": null, "clock": null, "score_status": null, "state_updated_at": null, "state_sources": null, "alternate_ids": [], "bookmakers": [ { "id": "draftkings", "name": "DraftKings", "type": "sportsbook", "updated_at": "2026-10-14T23:33:15.863Z", "markets": [ { "id": "mkt_14r1od1l1vw", "key": "moneyline", "period": "full_game", "outcomes": [ { "id": "sel_2d3ja0zugwd", "name": "Phoenix Suns", "side": "home", "price": -230 }, { "id": "sel_1pojklgy6cc", "name": "San Antonio Spurs", "side": "away", "price": 180 } ], "suspended": false, "updated_at": "2026-10-14T23:33:15.863Z" }, { "id": "mkt_14ivq762bz0", "key": "spread", "period": "full_game", "line": -4.5, "outcomes": [ { "id": "sel_1d92w0erhd2", "name": "Phoenix Suns", "side": "home", "point": -4.5, "price": -115 }, { "id": "sel_1lhzilnwepp", "name": "San Antonio Spurs", "side": "away", "point": 4.5, "price": -105 } ], "suspended": false, "updated_at": "2026-10-14T23:33:15.863Z" } ] }, { "id": "pinnacle", "name": "Pinnacle", "type": "sportsbook", "updated_at": "2026-10-14T23:33:15.863Z", "markets": [ { "id": "mkt_1dougx7qnw5", "key": "moneyline", "period": "full_game", "outcomes": [ { "id": "sel_2d3ja0zugwd", "name": "Phoenix Suns", "side": "home", "price": -202 }, { "id": "sel_1pojklgy6cc", "name": "San Antonio Spurs", "side": "away", "price": 179 } ], "suspended": false, "updated_at": "2026-10-14T23:33:15.863Z" }, { "id": "mkt_19gvfk2ks6p", "key": "spread", "period": "full_game", "line": -4.5, "outcomes": [ { "id": "sel_1d92w0erhd2", "name": "Phoenix Suns", "side": "home", "point": -4.5, "price": -108 }, { "id": "sel_1lhzilnwepp", "name": "San Antonio Spurs", "side": "away", "point": 4.5, "price": -102 } ], "suspended": false, "updated_at": "2026-10-14T23:33:15.863Z" } ] } ] } ], "meta": { "request_id": "req_QJtExNJuHQdvMnUJL4xz", "count": 1, "markets": [ "moneyline", "spread" ], "periods": [ "full_game" ], "format": "american", "credits_used": 2, "credits_remaining": null, "unlimited": true, "generated_at": "2026-10-14T23:33:43.564Z" } }Go real-time
Replace polling with the WebSocket stream: one connection, a snapshot, then only what changes.
stream.mjsimport WebSocket from 'ws'; // npm i ws const ws = new WebSocket('wss://api.preciseapi.com/v1/stream', { headers: { Authorization: `Bearer ${process.env.PRECISEAPI_KEY}` }, }); let lastSeq = 0; ws.on('open', () => { ws.send(JSON.stringify({"type":"subscribe","leagues":["nba"],"markets":["moneyline","spread","total"]})); }); ws.on('message', (raw) => { const msg = JSON.parse(raw); // Heartbeats repeat the latest seq; every other message advances it by one. const expected = msg.type === 'heartbeat' ? lastSeq : lastSeq + 1; if (msg.seq && lastSeq !== 0 && msg.seq !== expected) { ws.send(JSON.stringify({ type: 'resync' })); // gap detected } if (msg.seq) lastSeq = msg.seq; if (msg.type === 'snapshot') console.log('events:', msg.data.length); if (msg.type === 'delta') { for (const { event_id, book, market } of msg.changes) { console.log(event_id, book, market.key, market.outcomes.map((o) => o.price)); } } });
X-Credits-Remaining. Reference endpoints such as /v1/leagues and /v1/sportsbooks are free — cache their output and spend credits on odds.Previous: Introduction · Next: Authentication