WebSocket API

Push-based delivery for live data — same auth, same data, lower latency than polling.

Connection URL

wss://stream.sportapi.io/v1

Authentication

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_xxx
⚠️
Passing 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 patternDescription
nba.scores.liveAll live NBA scores
nba.games.{game_id}Specific NBA game updates
nfl.scores.liveAll live NFL scores
mlb.scores.liveAll live MLB scores
nhl.scores.liveAll live NHL scores
soccer.scores.liveAll live soccer scores
news.{league}News updates for league
news.breakingHigh-priority breaking news
news.injuriesAll injury news
news.transfersAll 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.