Sport Data API
Play a stream
Find what is live, choose a commentary language, and play the HLS feed in the browser with hls.js.
Goal: list the streams that are live right now and play one, in the viewer's language.
The calls
GET /v1/streams?status=live → id, title, sport, league_name, event_id, status, starts_at,
master_hls_url, renditions[], available_languages (free)
GET /v1/streams/{stream_id} → the same envelope, with the one stream as data[0] (free)Filters on /v1/streams: status (scheduled | live | ended), event_id (a spine event id, 64
lowercase hex characters), sport (for example bkfc), league (exact name, case-insensitive) and
language (a BCP-47 tag such as en, es or pt-br; returns streams that carry that language). limit
is 1 to 100 with a default of 20, and paging uses next_page_token like every other list. Streams come
back newest-registered first.
What a stream looks like
One stream is one HLS master playlist. Inside it there is one video rendition and one audio rendition per commentary language, all on the same clock. "The same fight in Spanish" is a rendition of a stream. An event can still have more than one stream when it has several feeds or providers.
Each entry in renditions has:
| Field | Meaning |
|---|---|
kind | video or audio |
language | Lowercase language tag on audio renditions. Video usually has none. |
label | Display name for a picker, for example a language name |
hls_url | The rendition's own playlist URL. Can be null. |
available_languages is the list of distinct rendition languages, in playlist order, ready to drop into a
language menu.
Step 1: list live streams (server side)
Run this on your server. It holds your API key, so it should never run in the browser.
import os
import requests
BASE_URL = "https://platform-api.altsportsleagues.ai"
HEADERS = {"Authorization": f"Bearer {os.environ['ASD_API_KEY']}"}
def live_streams(**filters):
token = None
while True:
params = {"status": "live", "limit": 100, **filters}
if token:
params["page_token"] = token
res = requests.get(f"{BASE_URL}/v1/streams", headers=HEADERS, params=params, timeout=65)
res.raise_for_status()
body = res.json()
yield from body["data"]
token = body.get("next_page_token")
if not token:
return
for stream in live_streams(language="es"):
print(f"{stream['id']} {stream['title']} [{stream['sport']} / {stream.get('league_name') or '-'}]")
print(f" master: {stream['master_hls_url']}")
print(f" languages: {', '.join(stream['available_languages']) or '(none listed)'}")
for r in stream["renditions"]:
print(f" {r['kind']:<5} {r.get('language') or '--':<6} {r.get('label') or '':<16} {r.get('hls_url')}")const BASE_URL = 'https://platform-api.altsportsleagues.ai';
const headers = { Authorization: `Bearer ${process.env.ASD_API_KEY}` };
export type Rendition = {
kind: 'video' | 'audio';
language: string | null;
label: string | null;
hls_url: string | null;
};
export type Stream = {
id: string;
title: string;
sport: string;
league_name: string | null;
event_id: string | null;
status: 'scheduled' | 'live' | 'ended';
starts_at: string | null;
master_hls_url: string | null;
renditions: Rendition[];
available_languages: string[];
};
export async function liveStreams(filters: Record<string, string> = {}): Promise<Stream[]> {
const streams: Stream[] = [];
let token: string | null | undefined;
do {
const qs = new URLSearchParams({
status: 'live',
limit: '100',
...filters,
...(token ? { page_token: token } : {}),
});
const res = await fetch(`${BASE_URL}/v1/streams?${qs}`, { headers });
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
const body = (await res.json()) as { data: Stream[]; next_page_token?: string | null };
streams.push(...body.data);
token = body.next_page_token;
} while (token);
return streams;
}
for (const s of await liveStreams({ language: 'es' })) {
console.log(`${s.id} ${s.title} [${s.sport} / ${s.league_name ?? '-'}]`);
console.log(` master: ${s.master_hls_url}`);
console.log(` languages: ${s.available_languages.join(', ') || '(none listed)'}`);
}Step 2: play it in the browser
Pass master_hls_url and the chosen language to the page. Load the master playlist with
hls.js (npm install hls.js) and switch to the audio track whose
lang matches. Safari plays HLS natively, so it gets the URL directly.
import Hls from 'hls.js';
export function playStream(video: HTMLVideoElement, masterUrl: string, language?: string): () => void {
if (Hls.isSupported()) {
const hls = new Hls();
hls.on(Hls.Events.MANIFEST_PARSED, () => {
if (language) {
// Playlist tags can be 3 letters (spa) where the catalog uses 2 (es): match both.
const alt: Record<string, string> = { en: 'eng', es: 'spa', pt: 'por', fr: 'fra', de: 'deu', ja: 'jpn' };
const wanted = [language, alt[language]].filter(Boolean) as string[];
const idx = hls.audioTracks.findIndex((t) => wanted.some((w) => (t.lang ?? '').toLowerCase().startsWith(w)));
if (idx >= 0) hls.audioTrack = idx;
}
void video.play();
});
hls.loadSource(masterUrl);
hls.attachMedia(video);
return () => hls.destroy();
}
if (video.canPlayType('application/vnd.apple.mpegurl')) {
video.src = masterUrl; // Safari: the native player offers the audio tracks itself
void video.play();
return () => video.removeAttribute('src');
}
throw new Error('This browser cannot play HLS');
}To switch language while the stream plays, set hls.audioTrack to another index. Video keeps playing on
the same clock, and only the commentary changes.
If you only need one language as audio, for a radio-style player or a second-screen app, take the matching
audio entry from renditions and load its hls_url the same way.
Watch out
- Keep your API key on the server. Fetch
/v1/streamsfrom your backend and hand only the playlist URLs to the browser. The listing is free, and this API does not meter playback. - An empty list means nothing matches. It does not mean the catalog is down. If the catalog cannot be
read you get an error (
500 internal_error, orupstream_timeoutwhen a retry makes sense), never an empty list. - Streams follow your key's sport scope. Asking for
sport=outside it returns403 forbidden_sport, and an unfiltered list only shows sports your key covers. Stream sports are not limited to the four warehouse sports. master_hls_urland renditionhls_urlcan benull. Ascheduledstream may not have a playlist yet. Check before you hand it to the player.- Page tokens are bound to the filters. Reusing a
page_tokenwith a differentstatus,event_id,sport,leagueorlanguagereturns400 invalid_request.