guides
A sports odds table on your website: server-rendered HTML from /v1/best
To show sports odds on your website, render the table on your server: read the best price per side from GET /v1/best, keep it in memory for a short time and send your visitors plain HTML. The key never reaches the browser, the API is read once per refresh however many people load the page, and search engines see the prices in the HTML. The script below does this in 95 lines of Node with no packages. We ran it on November 25, 2026, 19:38 UTC: it served 9 NBA games with the best moneyline, spread and total across 9 sportsbooks.
What do I need to put odds on my website?
- A PricedOdds API key, kept on your server as
PRICEDODDS_API_KEY. In code you publish, use the placeholder$PRICEDODDS_API_KEY. - Node 22 or later. We ran the script on Node 24.22.1 without installing anything.
- A place to run it: the same server as your site, or a small service that your pages call.
Our Terms of Service allow showing the data to your users: "You may use the data inside your own applications, models, research, alerts and content, including displaying it to your end users with attribution to PricedOdds where reasonable." They do not allow passing on the feed itself: no "resale, sublicensing, redistribution or re-publication of the raw data feed or substantial parts of it, including through another API, data feed, dataset or WebSocket" without written consent. The data is for informational purposes, so the table says that and links to PricedOdds in its footer.
Why render the table on the server?
- The key stays secret. A key in browser JavaScript is public: anyone can read it in the page source and use your plan. On the server, the browser only gets HTML.
- One API read for many visitors. The page is cached for 30 seconds. In our run, 12 requests at the same moment caused one API read between them, because they all waited on the same refresh.
- Search engines can read it. The prices are in the HTML when the page arrives, so a crawler does not need to run JavaScript to see them.
- It still works when a refresh fails. If the API cannot be reached, the server keeps the last good table instead of an error page.
How does the script work?
- At start,
GET /v1/books, which needs no key, gives each book's name and type. The script keeps the books of typesportsbookthat are not markedreference_only; setBOOKSto a comma list of ids to choose your own. - On a refresh,
GET /v1/eventsgives the team names and start times for the next seven days, andGET /v1/bestwithmarket=moneyline@game,spread@game,total@gameandbooksgives, for the whole league, the best price of each side among those books. Both follow thenextcursor. - It groups the rows by game, escapes every text it puts in the HTML and builds one table row per game: both teams, the start time in Eastern time, and for each market the line, the best American price and the book that has it.
- The HTTP server answers
/with that page andCache-Control: public, max-age=30, so a CDN in front of it can cache it as well.
GET /v1/best compares the books on your plan. On a plan with two books, the table shows the better of those two; the books of each plan are on the pricing page.
What is the code?
// odds-table-server.mjs: a server-rendered odds table for your website. It reads the best price per side
// from GET /v1/best, keeps it in memory for 30 seconds and serves plain HTML. Node 22 or later, no packages.
// Usage: PRICEDODDS_API_KEY=... node odds-table-server.mjs then open http://localhost:3000/
import { createServer } from "node:http";
const BASE = "https://api.pricedodds.com/v1";
const LEAGUE = process.env.LEAGUE ?? "nba";
const PORT = Number(process.env.PORT ?? 3000);
const TTL = 30_000; // one API read per 30 seconds, however many visitors you have
const MARKETS = "moneyline@game,spread@game,total@game";
const headers = { Authorization: `Bearer ${process.env.PRICEDODDS_API_KEY}` };
let requests = 0;
async function get(path, auth = true) {
requests++;
const res = await fetch(BASE + path, auth ? { headers } : {});
if (!res.ok) throw new Error(`HTTP ${res.status} on ${path}`);
return res.json();
}
async function all(path) { // follows the next cursor
const rows = [];
let cursor = "";
do {
const body = await get(path + (cursor ? `&cursor=${encodeURIComponent(cursor)}` : ""));
rows.push(...body.data);
cursor = body.next;
} while (cursor);
return rows;
}
// Book names and types need no key. Keep licensed US sportsbooks only, unless BOOKS lists the ids you want.
const bookList = (await get("/books", false)).data;
const NAME = Object.fromEntries(bookList.map(b => [b.id, b.name]));
const BOOKS = process.env.BOOKS ?? bookList.filter(b => b.type === "sportsbook" && !b.reference_only).map(b => b.id).join(",");
const esc = s => String(s).replace(/[&<>"']/g, c => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
const am = a => (a > 0 ? "+" : "") + a;
const timeET = iso => new Date(iso).toLocaleString("en-US", { timeZone: "America/New_York", weekday: "short", hour: "numeric", minute: "2-digit" });
async function load() {
const now = Date.now();
const from = new Date(now - 12 * 3600e3).toISOString(), to = new Date(now + 7 * 86400e3).toISOString();
const events = new Map((await all(`/events?league=${LEAGUE}&from=${from}&to=${to}`)).map(e => [e.id, e]));
const best = await all(`/best?league=${LEAGUE}&market=${MARKETS}&books=${BOOKS}`);
const games = new Map();
for (const row of best) {
const e = events.get(row.event_id);
if (!e || e.status === "final") continue;
const g = games.get(row.event_id) ?? { e, m: {} };
for (const s of row.selections) (g.m[row.market] ??= {})[s.side] = s;
games.set(row.event_id, g);
}
return [...games.values()].sort((a, b) => a.e.startsAt.localeCompare(b.e.startsAt));
}
const cell = s => s ? `${s.line == null ? "" : (s.side === "over" ? "O " : s.side === "under" ? "U " : s.line > 0 ? "+" : "") + s.line + " "}<b>${am(s.best.american)}</b> <small>${esc(NAME[s.best.book] ?? s.best.book)}</small>` : "–";
function render(games, at) {
const rows = games.map(({ e, m }) => `<tr><td>${esc(e.away.name)}<br>${esc(e.home.name)}<br><small>${e.status === "live" ? "Live" : esc(timeET(e.startsAt)) + " ET"}</small></td>` +
`<td>${cell(m.moneyline?.away)}<br>${cell(m.moneyline?.home)}</td><td>${cell(m.spread?.away)}<br>${cell(m.spread?.home)}</td>` +
`<td>${cell(m.total?.over)}<br>${cell(m.total?.under)}</td></tr>`).join("\n");
return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>${esc(LEAGUE.toUpperCase())} odds: best price per side</title></head><body>
<table><caption>${esc(LEAGUE.toUpperCase())}: best price per side across ${BOOKS.split(",").length} sportsbooks</caption>
<thead><tr><th>Game</th><th>Moneyline</th><th>Spread</th><th>Total</th></tr></thead>
<tbody>
${rows || '<tr><td colspan="4">No games with prices right now.</td></tr>'}
</tbody></table>
<p><small>Updated ${esc(new Date(at).toISOString().slice(11, 16))} UTC. Odds data from <a href="https://pricedodds.com">PricedOdds</a>, for information only. Prices change; check them at the book.</small></p>
</body></html>`;
}
let cache = { html: "", at: 0, games: 0 };
let pending = null;
async function page() {
if (Date.now() - cache.at < TTL) return cache;
pending ??= load().then(games => {
console.log(`refreshed: ${games.length} games, ${requests} API requests so far`);
return (cache = { html: render(games, Date.now()), at: Date.now(), games: games.length });
})
.catch(err => { console.error("refresh failed:", err.message); if (!cache.html) throw err; return cache; }) // keep the last good table
.finally(() => { pending = null; });
return pending;
}
createServer(async (req, res) => {
if (req.url !== "/") { res.writeHead(404).end(); return; }
try {
const { html, at } = await page();
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "public, max-age=30", "Last-Modified": new Date(at).toUTCString() });
res.end(html);
} catch {
res.writeHead(503, { "Content-Type": "text/plain" }).end("Odds are not available right now.");
}
}).listen(PORT, () => console.log(`odds table on http://localhost:${PORT}/ (${LEAGUE}, books: ${BOOKS})`));Run it with PRICEDODDS_API_KEY=$PRICEDODDS_API_KEY node odds-table-server.mjs and open http://localhost:3000/. Set LEAGUE to any league id from the coverage page and PORT to another port. The table has no styles, so it takes the CSS of your site.
What did a real run return?
We started the server on November 25, 2026, 19:38 UTC with LEAGUE=nba and sent it requests from a small test script. Its log:
node v24.22.1
odds table on http://localhost:3000/ (nba, books: draftkings,fanduel,betmgm,fanatics,caesars,bet365,hardrock,betrivers,circa)
GET / first: HTTP 200, 9 games in the table, 3982 bytes
GET / again: HTTP 200, 9 games, same page: true
12 requests at once: 12 x HTTP 200, API refreshes so far: 1
after 31 s: HTTP 200, 9 games, API refreshes: 2
refreshed: 9 games, 4 API requests so far
refreshed: 9 games, 7 API requests so far
headers: Cache-Control: public, max-age=30
html check: clean (no empty values)The first request read the API and returned a page of 3,982 bytes with 9 games. The next one came from memory, without an API call, and returned the same page. Twelve requests at once all got HTTP 200 without a second API read. After 31 seconds the cache had expired, so the next request read the API again. The book list cost 1 request at start and each refresh cost 3 requests (events and best prices, with their pages), so the server reads the API at most twice a minute whatever the traffic. These are prices of one moment, shown as an example and not as current prices.
The first row of the HTML it served:
<tr><td>Miami Heat<br>Philadelphia 76ers<br><small>Wed 5:00 PM ET</small></td><td><b>+101</b> <small>DraftKings</small><br><b>-115</b> <small>Circa Sports</small></td><td>+1.5 <b>-110</b> <small>BetMGM</small><br>-1.5 <b>-105</b> <small>Hard Rock Bet</small></td><td>O 237.5 <b>-105</b> <small>Fanatics Sportsbook</small><br>U 237.5 <b>-104</b> <small>FanDuel</small></td></tr>That is Miami Heat at Philadelphia 76ers, Wed 5:00 PM ET: the best moneyline on Miami Heat was +101 at DraftKings and on Philadelphia 76ers -115 at Circa Sports, among the 9 sportsbooks.
How do I add it to an existing site?
Three common ways, from the least to the most work: put the page in an iframe; have your server fetch http://localhost:3000/ and insert the table into your own template; or move the load and render functions into the route handler of your framework and keep the same 30-second cache. We ran the script as a standalone Node server; we did not test it inside another framework. For prices that change while the page is open, a table that reloads every 30 seconds is enough for most sites; for live updates, use the WebSocket on your server, as in the JavaScript WebSocket tutorial, and push the changes to the page yourself.
What are the limits of this odds table?
The best price of a side is only useful while the book still offers it, so the footer tells readers to check the price at the book. The table shows one line per market, the one in GET /v1/best; alternate lines and player props are not in it. In our run every game in the table was still to start; we did not check how a game in play looks in it. The script keeps no history: each refresh replaces the table. Keep the attribution and the informational note, and do not offer the data as a feed of your own; see the Terms. Nothing here is betting advice.
If you want the same rows as a spreadsheet, convert a saved /v1/best response to CSV.
FAQ
Can I show odds from the API on my website?
Yes. The Terms allow displaying the data to your end users with attribution to PricedOdds where reasonable. They do not allow republishing the raw feed, for example as another API or dataset, without written consent.
Can I call the API from the browser with my key?
Not with your key. The key would be visible to every visitor. Call the API from your server and send the browser only the HTML or the data the page needs.
How often should the table refresh?
The script uses 30 seconds, which in our run meant at most two API reads a minute, 3 requests each. A longer cache means fewer requests and older prices; the limit of each plan is on the pricing page.
Where do I start?
Copy the script, set your key and open the page on your own machine before you put it on your site. The fields are in the docs, the leagues are on the coverage page and more runnable examples are on the developers page. Every plan starts with a 3-day free trial with a $1 card verification that is refunded immediately. The plan you pick at signup is charged from day 4 unless you cancel before the trial ends. See pricing or create an account.