NBA WebSocket API
Subscribe once and NBA score changes, game starts, plays and finals are pushed to your app as they happen, instead of polling a REST endpoint every few seconds.
Data is aggregated from public sources and is typically 20-30 seconds behind live play (about 1 second after our source). There is no SLA.
AvailableEvery monitored league streams over the same connection; filter to NBA in the subscribe message.
Endpoint
- GET/api/v1/websocket/auth
- Each delivered message counts toward your monthly quota.
- The server pings every 2 minutes to keep connections open behind proxies.
Connect and subscribe to NBA
JavaScript (Node 22+ or a browser)
const auth = await fetch("https://www.realtimesportsapi.com/api/websocket/auth", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.RSA_API_KEY}` }
});
const { data } = await auth.json(); // { url, token, expiresIn: 3600 }
const ws = new WebSocket(`${data.url}?token=${data.token}`);
ws.onopen = () => {
for (const event of ["event_score_change", "event_play", "event_final"]) {
ws.send(JSON.stringify({ type: "subscribe", event, filters: { sport: "basketball", league: "nba" } }));
}
};
ws.onmessage = (msg) => console.log(JSON.parse(msg.data));Python
import os, json, requests, websocket # pip install websocket-client
auth = requests.post(
"https://www.realtimesportsapi.com/api/websocket/auth",
headers={"Authorization": f"Bearer {os.environ['RSA_API_KEY']}"},
timeout=10,
).json()["data"]
ws = websocket.create_connection(f"{auth['url']}?token={auth['token']}")
for event in ["event_score_change", "event_play", "event_final"]:
ws.send(json.dumps({"type": "subscribe", "event": event,
"filters": {"sport": "basketball", "league": "nba"}}))
while True:
print(json.loads(ws.recv()))Message types: event_score_change, event_live, event_status_change, event_play, event_final and event_odds_change. Tokens last an hour; reconnect with a fresh token. Each delivered message counts toward your plan's WebSocket allowance.
Rate limits and pricing
| Plan | Price | Calls | Rate | WebSocket | Webhooks |
|---|---|---|---|---|---|
| Free | $0 | 125/mo (1,000 first 30 days) | 1/s | 500 msgs/mo | No |
| Starter | $29/mo ($290/yr) | 10,000/mo | 5/s | Shares monthly pool | Shares monthly pool |
| Growth | $49/mo ($490/yr) | 25,000/mo | 10/s | Shares monthly pool | Shares monthly pool |
| Pro | $99/mo ($990/yr) | 50,000/mo | 20/s | 100,000 msgs/mo | 25,000/mo |
| Business | $179/mo ($1,790/yr) | 150,000/mo | 40/s | 300,000 msgs/mo | 75,000/mo |
| Scale | $299/mo ($2,990/yr) | 500,000/mo | 100/s | 500,000 msgs/mo | 100,000/mo |
Every successful REST call counts as one call. Over the limit you get HTTP 429 with a Retry-After header. No SLA. Full pricing.
FAQ
- Is there a free NBA WebSocket API?
- WebSocket is on every paid plan from $29/month (on Starter, REST calls, WebSocket messages and webhook deliveries share 10,000 a month). The free key has a 500-message monthly preview on 1 connection, enough to see it working.
- How fast are NBA updates over WebSocket?
- Each event goes out about a second after our source sees it, which is typically 20-30 seconds behind live play. Fine for apps, alerts and scoreboards; not for in-play betting.
- Can I filter to one team?
- Subscriptions filter by sport and league; filter to your teams in your message handler using the team ids in each message.