Fetch real-time odds in Next.js server components and route handlers, with your API key kept server-side and responses cached. Normalized JSON, no SDK.
The MoneyLine odds API is a plain REST/HTTPS API, which makes it a natural fit for the Next.js App Router. Fetch odds in a server component or route handler so your API key never reaches the browser, and use Next.js fetch caching (revalidate) to control freshness and cost.
Responses are normalized to American odds under canonical event IDs, so server components can render odds directly and route handlers can return a trimmed shape to the client without per-sportsbook parsing.
Call the API in server components/route handlers; the key stays off the client.
Use Next.js fetch revalidate to tune freshness vs. request volume.
Plain fetch against REST/HTTPS — nothing to install.
Game lines and player props across every major US league.
Next.js App Router — server component with revalidate
Request
// app/odds/page.tsx (server component)
async function getOdds() {
const res = await fetch(
'https://mlapi.bet/v1/odds?league=nba&market=moneyline',
{
headers: { 'x-api-key': process.env.ML_API_KEY! },
next: { revalidate: 60 }, // cache for 60s
},
)
return res.json()
}
export default async function OddsPage() {
const { data } = await getOdds()
return (
<ul>
{data.map((g) => (
<li key={g.eventId}>{g.eventId}</li>
))}
</ul>
)
}Response
{
"success": true,
"data": [
{
"eventId": "nba-ev-311286",
"leagueId": "nba",
"bookmakers": [
{
"bookmakerId": "draftkings",
"bookmakerName": "DraftKings",
"markets": [
{ "marketType": "moneyline", "outcomes": [
{ "name": "Boston Celtics", "price": -180 },
{ "name": "Los Angeles Lakers", "price": 155 }
] }
]
}
]
}
]
}Render odds server-side for fast, indexable pages with your key hidden.
Proxy and trim the API response for your client from app/api routes.
Use revalidate to balance freshness against request volume and cost.
In a server-only env var (e.g. ML_API_KEY) read inside a server component or route handler, never a NEXT_PUBLIC_ variable.
Use the Next.js fetch option next: { revalidate: <seconds> } to cache responses; lower for live odds, higher for static views.
No. It is REST over HTTPS, so the native fetch in the App Router is all you need.
Free tier to start, one API key, normalized responses across every league and sportsbook.