Examples
Fetch Live Streams
Use the Helix client with client-credential tokens to fetch live stream data, with typed responses and troubleshooting hints.
Environment
TWITCH_CLIENT_ID, TWITCH_CLIENT_SECRET
Get started
- Install dependencies with
bun install. - Export
TWITCH_CLIENT_IDandTWITCH_CLIENT_SECRET(or add them to.env). - Run
bun run examples/FETCH_STREAMS.tsto request the first page of live streams from the Helix API. - Review the console output for the raw API payload or any authentication troubleshooting tips.
What you can do
- Swap the
firstquery parameter to page through more results. - Add filters like
game_idoruser_loginfor targeted lookups. - Reuse the authenticated
HelixClientinstance for subsequent API calls in your app. - Hook the data into analytics, overlays, or moderation workflows.
Extend it further
- Combine with the authorization code example to act on behalf of a broadcaster.
- Cache stream responses using your preferred store to avoid rate-limit pressure.
- Trigger EventSub subscriptions for channels returned by the query.
Resources
Authorization Code Flow
Guide users through the standard Twitch OAuth 2.0 authorization code flow — print a consent URL, exchange the code for tokens, and refresh them later.
Chat Command Bot
Create a resilient chat bot that joins a channel, listens for commands, and responds with live data fetched from Helix.