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
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);- No token yet: one is requested, once.
- POSTid.twitch.tv/oauth2/token200
- GET/users?login=twitchdev200
- GET/channels?broadcaster_id=141981764200
- GET/channels/followers?broadcaster_id=141981764&first=1200
- "Building the next thing" 2841907
// 250 streams: three requests, one array.const top = await twitch.streams.get({ language: "fr" }).take(250);
for (const stream of top.slice(0, 3)) { console.log(stream.user_name, stream.viewer_count);}
// Or walk every page without holding them all in memory.for await (const stream of twitch.streams.get({ language: "fr" })) { if (stream.viewer_count < 1000) break;}- GET/streams?language=fr&first=100200
- GET/streams?language=fr&first=100&after=eyJiIjp7Ik9m...200
- GET/streams?language=fr&first=100&after=eyJiIjp7IkN1...200
- 250 collected, the rest of the third page is dropped.
- nuit_blanche 18204
- atelier_pixel 9311
- LeGrandFroid 7754
const events = twitch.eventsub.websocket();
events.on( "channel.chat.message", { broadcaster_user_id: channel, user_id: bot }, async (event) => { if (event.message.text !== "!ping") return; await twitch.chat.send({ broadcaster_id: channel, message: "pong", reply_parent_message_id: event.message_id, }); },);- WebSocket open, session welcomed.
- POST/eventsub/subscriptions202
- margueritehello everyone
- kowalczyk_devis the bot awake?
- kowalczyk_dev!ping
- POST/chat/messages200
- your_botbotpong
const hooks = twitch.eventsub.webhook({ callback, secret });
hooks.on( "stream.online", { broadcaster_user_id: "141981764" }, (event) => { notify(`${event.broadcaster_user_name} is live`); },);
// Signatures are verified before your handler runs.export default { fetch: (request: Request) => hooks.handle(request),};- POST/eventsub/subscriptions202
- Twitch checks the callback: challenge answered.
- stream.onlineTwitchDev
- Signature valid, not a replay, not a duplicate.
- notify: TwitchDev is live
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.
twitch.users.getByLogin()Gets one user by login name, ornullwhen there is no such user.app or user tokentwitch.streams.get()Lists live streams, most viewers first.app or user tokentwitch.chat.send()Sends a message to a channel's chat.app or user tokentwitch.moderation.ban()Bans a user from a channel's chat.app or user tokentwitch.channels.followers()Lists the followers of a channel, most recent first.app or user tokentwitch.clips.create()Clips the last seconds of a live stream.user tokenchannel.chat.messageA user sent a message in the chat room.eventstream.onlineThe broadcaster started a stream.eventtwitch.ads.startCommercial()Starts a commercial break on a channel.app or user tokentwitch.ads.schedule()Gets the ad schedule of a channel.app or user tokentwitch.ads.snooze()Pushes the next automatic mid-roll ad back by five minutes, at the cost of one snooze.app or user tokentwitch.analytics.extensions()Lists the reports available for the extensions of the user making the call.user tokentwitch.analytics.games()Lists the reports available for the games of the user making the call.user tokentwitch.bits.leaderboard()Gets the Bits leaderboard of the channel of the user making the call, over its whole life or over a given day, week, month or year.user tokentwitch.bits.cheermotes()Lists the Cheermotes usable in every channel, plus the custom ones of a broadcaster when you name one.app or user tokentwitch.bits.customPowerUps()Lists the custom Power-ups a broadcaster created, enabled or not.user tokentwitch.bits.extensionTransactions()Lists the purchases made with Bits inside an extension.app tokentwitch.channelPoints.createReward()Adds a custom reward to a channel.user tokentwitch.channelPoints.deleteReward()Deletes a custom reward.user tokentwitch.channelPoints.rewards()Lists the custom rewards of a channel, sorted by ID.user tokentwitch.channelPoints.redemptions()Lists the redemptions of a custom reward.user tokentwitch.channelPoints.updateReward()Changes a custom reward.user tokentwitch.channelPoints.updateRedemptions()Fulfills or cancels redemptions that are still waiting in the queue, and returns them.user tokentwitch.channels.get()Gets the title, category, language and tags of one or more channels.app or user tokentwitch.channels.update()Changes the title, category, language, tags, delay or content labels of a channel.user tokentwitch.channels.editors()Lists the editors of a channel.user tokentwitch.channels.followed()Lists the channels a user follows, most recent follow first.user tokentwitch.charity.campaign()Gets the charity campaign a broadcaster is running, ornullwhen there is none.user tokentwitch.charity.donations()Lists the donations made to the campaign a broadcaster is running.user tokentwitch.chat.chatters()Lists the users connected to a channel's chat.app or user tokentwitch.chat.channelEmotes()Gets the custom emotes of a channel.app or user tokentwitch.chat.globalEmotes()Gets the emotes made by Twitch that work in every chat.app or user tokentwitch.chat.emoteSets()Gets the emotes of one or more emote sets.app or user tokentwitch.chat.channelBadges()Gets the custom chat badges of a channel, such as its subscriber and Bits badges.app or user tokentwitch.chat.globalBadges()Gets the chat badges made by Twitch that can show up in every chat.app or user tokentwitch.chat.settings()Gets the chat settings of a channel.app or user tokentwitch.chat.sharedSession()Gets the shared chat session a channel is part of, ornullwhen it is not in one.app or user tokentwitch.chat.userEmotes()Lists every emote a user can post, across all channels.user tokentwitch.chat.updateSettings()Changes the chat settings of a channel and returns the new ones.app or user tokentwitch.chat.announce()Posts a highlighted announcement in a channel's chat.app or user tokentwitch.chat.shoutout()Gives a shoutout to another broadcaster, which shows their channel with a follow button in chat.app or user tokentwitch.chat.pinnedMessage()Gets the message pinned in a channel's chat, ornullwhen nothing is pinned.app or user tokentwitch.chat.pin()Pins a message at the top of a channel's chat.app or user tokentwitch.chat.updatePin()Changes how long a pinned message stays pinned.app or user tokentwitch.chat.unpin()Removes a pinned message from the top of a channel's chat.app or user tokentwitch.chat.colors()Gets the color users have for their name in chat.app or user tokentwitch.chat.setColor()Changes the color of a user's name in chat.user tokentwitch.clips.createFromVod()Clips a passage of a video, as the broadcaster or one of the channel's editors.app or user tokentwitch.clips.get()Lists the clips of a broadcaster or of a category, most viewed first, or gets clips by ID.app or user tokentwitch.clips.downloads()Gets temporary links to the video files of clips, as the broadcaster or one of the channel's editors.app or user tokentwitch.conduits.list()Lists the conduits of your application.app tokentwitch.conduits.create()Creates a conduit with the given number of shards.app tokentwitch.conduits.update()Changes the number of shards of a conduit.app tokentwitch.conduits.delete()Deletes a conduit.app tokentwitch.conduits.shards()Lists the shards of a conduit and where each one delivers events.app tokentwitch.conduits.updateShards()Points shards at a webhook callback or a WebSocket session.app tokentwitch.contentLabels.list()Lists every content classification label, with its name and description in the language you ask for.app or user tokentwitch.entitlements.drops()Lists the Drops entitlements of your organization, in no particular order.app or user tokentwitch.entitlements.updateDrops()Sets the status of Drops entitlements, typically to"FULFILLED"once the reward was delivered in game.app or user tokentwitch.eventsub.subscribe()Creates a subscription by hand.user tokentwitch.eventsub.unsubscribe()Deletes a subscription.user tokentwitch.eventsub.subscriptions()Lists your subscriptions, oldest first.app or user tokentwitch.eventsub.websocket()Opens a WebSocket listener.extension JWTtwitch.eventsub.webhook()Creates a webhook listener, for servers reachable from the internet.extension JWTtwitch.eventsub.conduit()Opens a WebSocket that serves one shard of a conduit.extension JWTtwitch.extensions.configuration()Reads one or more configuration segments of an extension, in the order you asked for them.extension JWTtwitch.extensions.setConfiguration()Writes a configuration segment.extension JWTtwitch.extensions.setRequiredConfiguration()Sets the required configuration string of a channel, for extensions that must be configured by the broadcaster before they can be activated.extension JWTtwitch.extensions.sendPubSub()Pushes a message to the running copies of an extension.extension JWTtwitch.extensions.liveChannels()Lists the channels that are live with an extension installed or activated.app or user tokentwitch.extensions.secrets()Gets the shared secrets of an extension.extension JWTtwitch.extensions.createSecret()Creates a new shared secret.extension JWTtwitch.extensions.sendChatMessage()Posts a message in a channel's chat under the name of the extension.extension JWTtwitch.extensions.get()Gets the description of an extension, released or not.extension JWTtwitch.extensions.released()Gets the description of a released extension.app or user tokentwitch.extensions.bitsProducts()Lists the Bits products of the extension your client ID belongs to, sorted by SKU.app tokentwitch.extensions.updateBitsProduct()Creates a Bits product, or updates the one that already has this SKU.app tokentwitch.games.top()Lists the categories with the most viewers right now, most watched first.app or user tokentwitch.games.get()Gets categories by ID, by exact name, by IGDB ID, or any mix of them.app or user tokentwitch.goals.get()Lists the active goals of a broadcaster with their current progress.user tokentwitch.guestStar.settings()Gets the Guest Star settings of a channel.user tokentwitch.guestStar.updateSettings()Changes the Guest Star settings of a channel.user tokentwitch.guestStar.session()Gets the Guest Star session a channel is running, ornullwhen there is none.user tokentwitch.guestStar.createSession()Starts a Guest Star session with the broadcaster as its only member.user tokentwitch.guestStar.endSession()Ends a Guest Star session, like the host pressing "End Call".user tokentwitch.guestStar.invites()Lists the pending invitations of a session, with how far each invited user is in the waiting room.user tokentwitch.guestStar.invite()Invites a user to a session in progress.user tokentwitch.guestStar.deleteInvite()Takes back an invitation to a session.user tokentwitch.guestStar.assignSlot()Seats an invited user in a slot of the session, once they are ready to join.user tokentwitch.guestStar.updateSlot()Moves a guest to another slot.user tokentwitch.guestStar.deleteSlot()Removes a guest from their slot.user tokentwitch.guestStar.updateSlotSettings()Changes what a slot may share and how it comes out on stream.user tokentwitch.hypeTrain.status()Gets the Hype Train running on a channel, if any, along with the records of the channel.user tokentwitch.moderation.checkAutoMod()Tells whether AutoMod would let messages through in a channel, without sending them.app or user tokentwitch.moderation.manageAutoModMessage()Approves or denies a message that AutoMod is holding for review.app or user tokentwitch.moderation.autoModSettings()Gets the AutoMod levels of a channel.app or user tokentwitch.moderation.updateAutoModSettings()Replaces the AutoMod levels of a channel.app or user tokentwitch.moderation.bans()Lists the users who are banned or timed out in a channel.app or user tokentwitch.moderation.unban()Lifts the ban or the timeout of a user.app or user tokentwitch.moderation.unbanRequests()Lists the unban requests of a channel that are in a given state.user tokentwitch.moderation.resolveUnbanRequest()Approves or denies an unban request.user tokentwitch.moderation.blockedTerms()Lists the blocked terms of a channel, newest first.app or user tokentwitch.moderation.addBlockedTerm()Blocks a word or phrase in a channel's chat.app or user tokentwitch.moderation.removeBlockedTerm()Removes a term from a channel's blocked terms.app or user tokentwitch.moderation.deleteMessages()Removes one message from a channel's chat, or every message when nomessage_idis given.app or user tokentwitch.moderation.moderatedChannels()Lists the channels in which a user is a moderator.app or user tokentwitch.moderation.moderators()Lists the moderators of a channel.user tokentwitch.moderation.addModerator()Makes a user a moderator of the channel.user tokentwitch.moderation.removeModerator()Takes the moderator role away from a user.user tokentwitch.moderation.vips()Lists the VIPs of a channel.user tokentwitch.moderation.addVip()Makes a user a VIP of the channel.user tokentwitch.moderation.removeVip()Takes the VIP status away from a user.user tokentwitch.moderation.updateShieldMode()Turns Shield Mode on or off in a channel.app or user tokentwitch.moderation.shieldMode()Tells whether Shield Mode is on in a channel and who turned it on last.app or user tokentwitch.moderation.warn()Sends a warning to a chat user, who cannot chat again until they acknowledge it.app or user tokentwitch.moderation.addSuspiciousStatus()Flags a chatter as suspicious in a channel, either to keep an eye on them or to restrict their messages.app or user tokentwitch.moderation.removeSuspiciousStatus()Clears the suspicious status of a chatter in a channel.app or user tokentwitch.polls.get()Lists the polls of a channel, most recent first.user tokentwitch.polls.create()Starts a poll in a channel.user tokentwitch.polls.end()Ends a running poll before its time is up, and optionally hides it.user tokentwitch.predictions.get()Lists the predictions of a channel, most recent first.user tokentwitch.predictions.create()Starts a prediction in a channel.user tokentwitch.predictions.end()Locks, resolves or cancels a prediction.user tokentwitch.raids.start()Prepares a raid on another channel.user tokentwitch.raids.cancel()Cancels a raid that has not left yet.user tokentwitch.schedule.get()Lists the planned broadcasts of a channel.app or user tokentwitch.schedule.icalendar()Gets the schedule of a channel as iCalendar text, ready to be saved as an.icsfile.app or user tokentwitch.schedule.updateSettings()Plans or cancels the vacation of a channel.user tokentwitch.schedule.createSegment()Adds a one-time or weekly broadcast to the schedule of a channel.user tokentwitch.schedule.updateSegment()Changes or cancels a planned broadcast.user tokentwitch.schedule.deleteSegment()Removes a planned broadcast.user tokentwitch.search.categories()Finds the categories whose name contains every word of the query, in any order and whatever the case.app or user tokentwitch.search.channels()Finds channels that streamed in the last six months.app or user tokentwitch.streams.followed()Lists the live streams of the channels a user follows, most viewers first.user tokentwitch.streams.key()Gets the stream key of a channel.user tokentwitch.streams.createMarker()Marks the current position of a live stream.user tokentwitch.streams.markers()Lists the markers of a user's most recent video, or of a given video.user tokentwitch.subscriptions.get()Lists the subscribers of a channel.user tokentwitch.subscriptions.check()Gets the subscription of a user to a channel, ornullwhen the user is not subscribed.user tokentwitch.tags.all()Lists the stream tags defined by Twitch.app or user tokentwitch.tags.ofChannel()Lists the Twitch defined tags applied to a channel.app or user tokentwitch.teams.ofChannel()Lists the teams a broadcaster is a member of.app or user tokentwitch.teams.get()Gets a team and its members, by name or by ID.app or user tokentwitch.users.get()Gets users by ID, by login name, or both.app or user tokentwitch.users.getById()Gets one user by ID, ornullwhen there is no such user.app or user tokentwitch.users.me()Gets the user who owns the token the call is made with.user tokentwitch.users.update()Updates the description of the user making the call.user tokentwitch.users.authorization()Tells which scopes the given users granted to your application.app tokentwitch.users.blocks()Lists the users a broadcaster has blocked, most recent first.user tokentwitch.users.block()Blocks a user on behalf of the user making the call.user tokentwitch.users.unblock()Removes a block set by the user making the call.user tokentwitch.users.extensions()Lists the extensions installed by the user making the call.user tokentwitch.users.activeExtensions()Gets the extensions a broadcaster has active in each slot.app or user tokentwitch.users.updateExtensions()Activates, deactivates or moves the extensions of the user making the call.user tokentwitch.videos.get()Gets videos by ID, or lists the videos of a user or of a category.app or user tokentwitch.videos.delete()Deletes videos and resolves with the IDs that were deleted.user tokentwitch.whispers.send()Sends a whisper to a user.user tokenautomod.message.holdAutoMod held a message for review.eventautomod.message.hold@1AutoMod held a message for review (older payload, without the reason).eventautomod.message.updateA message waiting in the AutoMod queue was approved, denied or expired.eventautomod.message.update@1A message waiting in the AutoMod queue was approved, denied or expired (older payload, without the reason).eventautomod.settings.updateThe AutoMod settings of the channel changed.eventautomod.terms.updatePermitted or blocked terms of the channel changed.eventchannel.ad_break.beginA midroll ad break started, run by hand or scheduled by Ads Manager.eventchannel.banA viewer was banned or timed out in the channel.eventchannel.bits.useBits were used in the channel, through a cheer or a Power-up.eventchannel.channel_points_automatic_reward_redemption.addA viewer redeemed an automatic channel points reward (version 2, message split into fragments).eventchannel.channel_points_automatic_reward_redemption.add@1A viewer redeemed an automatic channel points reward (version 1, message with emote positions).eventchannel.channel_points_custom_reward_redemption.addA viewer redeemed a custom channel points reward.eventchannel.channel_points_custom_reward_redemption.updateA redemption of a custom channel points reward was fulfilled or canceled.eventchannel.channel_points_custom_reward.addThe broadcaster created a custom channel points reward.eventchannel.channel_points_custom_reward.removeA custom channel points reward was deleted.eventchannel.channel_points_custom_reward.updateA custom channel points reward was edited.eventchannel.charity_campaign.donateA viewer donated to the broadcaster's charity campaign.eventchannel.charity_campaign.progressA charity campaign moved toward its goal, or the broadcaster changed the goal.eventchannel.charity_campaign.startThe broadcaster started a charity campaign.eventchannel.charity_campaign.stopThe broadcaster stopped a charity campaign.eventchannel.chat_settings.updateThe chat settings of the channel changed (emote, follower, slow, subscriber or unique chat mode).eventchannel.chat.clearA moderator or a bot cleared every message of the chat room.eventchannel.chat.clear_user_messagesA moderator or a bot cleared every message of one user, after a ban or a timeout.eventchannel.chat.message_deleteA moderator removed one message from the chat room.eventchannel.chat.notificationSomething shown as a notice in chat happened, such as a subscription, a gift, a raid or an announcement.eventchannel.chat.user_message_holdA message of the user inuser_idwas held by AutoMod.eventchannel.chat.user_message_updateThe AutoMod status of a held message of the user inuser_idchanged.eventchannel.cheerA user cheered Bits in the channel.eventchannel.custom_power_up_redemption.addA viewer redeemed a custom Power-up.eventchannel.followSomeone followed the channel.eventchannel.goal.beginThe broadcaster started a creator goal.eventchannel.goal.endThe broadcaster ended a creator goal.eventchannel.goal.progressA creator goal moved forward or backward.eventchannel.guest_star_guest.updateA guest or a slot changed in a running Guest Star session.eventchannel.guest_star_session.beginThe host started a Guest Star session.eventchannel.guest_star_session.endA Guest Star session ended, closed by the host or by Twitch.eventchannel.guest_star_settings.updateThe host changed the Guest Star preferences of the channel.eventchannel.hype_train.beginA Hype Train started on the channel.eventchannel.hype_train.endA Hype Train ended on the channel.eventchannel.hype_train.progressA contribution moved a running Hype Train forward.eventchannel.moderateA moderator took a moderation action in the channel, warnings included.eventchannel.moderate@1A moderator took a moderation action in the channel.eventchannel.moderator.addA user was made moderator of the channel.eventchannel.moderator.removeA user lost moderator status in the channel.eventchannel.poll.beginA poll started on the channel.eventchannel.poll.endA poll ended on the channel.eventchannel.poll.progressViewers voted in a running poll.eventchannel.prediction.beginA Prediction started on the channel.eventchannel.prediction.endA Prediction ended, resolved or canceled.eventchannel.prediction.lockBetting closed on a Prediction.eventchannel.prediction.progressViewers bet on a running Prediction.eventchannel.raidA broadcaster raided another channel.eventchannel.shared_chat.beginThe channel became active in a shared chat session.eventchannel.shared_chat.endThe channel left a shared chat session, or the session ended.eventchannel.shared_chat.updateThe shared chat session the channel is in changed, for example its participants.eventchannel.shield_mode.beginShield Mode was turned on in the channel.eventchannel.shield_mode.endShield Mode was turned off in the channel.eventchannel.shoutout.createThe broadcaster sent a Shoutout to another channel.eventchannel.shoutout.receiveThe broadcaster received a Shoutout from another channel.eventchannel.subscribeA user subscribed to the channel.eventchannel.subscription.endA subscription to the channel ended.eventchannel.subscription.giftA viewer gifted one or more subscriptions in the channel.eventchannel.subscription.messageA subscriber shared a resubscription message in chat.eventchannel.suspicious_user.messageA user flagged as suspicious sent a chat message.eventchannel.suspicious_user.updateA moderator changed the treatment applied to a suspicious user.eventchannel.unbanA viewer was unbanned in the channel.eventchannel.unban_request.createA banned user created an unban request.eventchannel.unban_request.resolveAn unban request was approved, denied or canceled.eventchannel.updateThe broadcaster changed the title, category, language or content classification labels of the channel.eventchannel.vip.addA user was made VIP of the channel.eventchannel.vip.removeA user lost VIP status in the channel.eventchannel.warning.acknowledgeA user acknowledged a warning they received in the channel.eventchannel.warning.sendA warning was sent to a user in the channel.eventconduit.shard.disabledEventSub disabled a conduit shard because the state of its transport changed.eventdrop.entitlement.grantViewers were granted Drop entitlements.eventextension.bits_transaction.createA Bits transaction was made in an extension.eventstream.offlineThe broadcaster stopped streaming.eventuser.authorization.grantA user authorized the application.eventuser.authorization.revokeThe application lost a user's authorization.eventuser.updateA user changed their account (name, description, email...).eventuser.whisper.messageThe user received a whisper.event
155 methods and 83 event typesBrowse the groups
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_idandsender_iddefault to whoever is acting.Cursors and page sizes
awaita list for one page,for awaitit 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.
Three ways to receive events
The same on() on all three. Pick by where your code runs.
Where to go next
- 01Quick startInstall, create an application on Twitch, make your first call.
- 02Acting as a userSend chat messages, moderate, run polls: how user tokens are chosen for you.
- 03EventsChat messages, follows, subscriptions, streams going live, as they happen.
- 04RecipesComplete programs to copy: a chat bot, go-live alerts, moderation tools.
- 05ReferenceEvery method, every event type, every scope, every error.
- 06Coming from version 1What changed, and the new name of each old method.
twitch.api is an independent open source project. It is not affiliated with or endorsed by Twitch Interactive, Inc.