Skip to content
twitch.apiv2.0

A Twitch API client for JavaScript and TypeScript

The whole Twitch API, typed.

twitch.api is a client for JavaScript and TypeScript that covers all 149 Helix endpoints and all 83 EventSub events. Tokens, rate limits, pagination and reconnects are taken care of, with no dependency.

npm i @ix-xs/twitch.api
  • Open source, MIT
  • Node 22 and later
  • No dependency
01

Call a method, get typed data

No token to fetch, no header to set, no cursor to carry around. Pick an example and run it: on the left the program, on the right what the library does for it. In the chat example, type a message and the bot answers.

const twitch = new Twitch({ clientId, clientSecret });
const user = await twitch.users.getByLogin("twitchdev");
if (!user) throw new Error("No such user");
const [channel] = await twitch.channels.get({
broadcaster_id: user.id,
});
const followers = await twitch.channels
.followers({ broadcaster_id: user.id })
.total();
console.log(channel?.title, followers);
Simulated output
  1. No token yet: one is requested, once.
  2. POSTid.twitch.tv/oauth2/token200
  3. GET/users?login=twitchdev200
  4. GET/channels?broadcaster_id=141981764200
  5. GET/channels/followers?broadcaster_id=141981764&first=1200
  6. "Building the next thing" 2841907
02

Find your endpoint

Type what you want to do. Every method and every event type is here, with the token it needs, and each one links to its parameters, its return type and an example.

155 methods and 83 event typesBrowse the groups

03

What you stop writing

  • Token plumbing

    The app token is requested when a call needs it. User tokens are refreshed before they expire, validated every hour as Twitch requires, and saved where you choose.

  • Which token goes with which call

    Each endpoint knows whether it wants the app token or a user’s, and whose. moderator_id, broadcaster_id and sender_id default to whoever is acting.

  • Cursors and page sizes

    await a list for one page, for await it for every item. Lists of more than 100 IDs are split, fetched in parallel and merged.

  • Handling 429

    The rate limit headers are followed for each token, so requests wait their turn instead of failing. What is safe to retry is retried.

  • Reconnect logic

    WebSocket, webhooks and conduits share one typed on(). Reconnects, resubscriptions, signature checks and duplicate deliveries are handled.

  • Guessing at shapes

    Every parameter, response and event is typed. Events that come in several shapes narrow when you check their discriminator.

04

Three ways to receive events

The same on() on all three. Pick by where your code runs.

WebSocketWebhooksConduits
You needNothing to hostA public HTTPS URLOne process per shard
Subscribes withA user tokenThe app tokenThe app token
Survives a restartNo, it subscribes againYesYes
Good forBots, desktop apps, a few channelsServers and serverless functionsMany channels, scaled across processes
05

Where to go next

twitch.api is an independent open source project. It is not affiliated with or endorsed by Twitch Interactive, Inc.