WebSocket API
Push-based delivery for live data — same auth, same data, lower latency than polling.
Connection URL
wss://stream.sportapi.io/v1Authentication
Send an auth message immediately after connecting:
{ "type": "auth", "token": "sk_live_xxxxxxxxxxxx" }Or pass via query parameter (handy for browser clients):
wss://stream.sportapi.io/v1?token=sk_live_xxxPassing the token in the URL means it can appear in proxy logs. Prefer the auth message for production server-to-server connections; use the query param only for short-lived browser sessions with a restricted key.
Subscribe to a feed
{ "type": "subscribe", "channel": "nba.scores.live" }Message format
Subscribe ack:
{ "type": "subscribed", "channel": "nba.scores.live" }Update:
{
"type": "update",
"channel": "nba.scores.live",
"data": { "game_id": "0022500412", "home": { "team": "BOS", "score": 78 } }
}Error:
{ "type": "error", "code": "unauthorized", "message": "Invalid token" }Channels reference
| Channel pattern | Description |
|---|---|
nba.scores.live | All live NBA scores |
nba.games.{game_id} | Specific NBA game updates |
nfl.scores.live | All live NFL scores |
mlb.scores.live | All live MLB scores |
nhl.scores.live | All live NHL scores |
soccer.scores.live | All live soccer scores |
news.{league} | News updates for league |
news.breaking | High-priority breaking news |
news.injuries | All injury news |
news.transfers | All transfer news |
Reconnection
Implement reconnection with exponential backoff. Resume subscriptions on reconnect — the server does not remember client state. See the reconnection guide for production-ready code.
Heartbeat
Server sends a ping every 30 seconds. Client must respond with { "type": "pong" } within 10 seconds or the connection closes. Most WebSocket client libraries handle this automatically — check yours.