Search documentation

Search pages and headings

Client Library

Installation

Install the client package and check your runtime meets its two requirements.

Install

npm install @gettersethya/yt-livechat-client
pnpm add @gettersethya/yt-livechat-client
yarn add @gettersethya/yt-livechat-client
bun add @gettersethya/yt-livechat-client

The package is ESM-only and ships its own type declarations.

Requirements

A running API server

The client never contacts YouTube. It talks only to a yt-livechat server — by default http://localhost:3000. See Quickstart to run one.

fetch and setTimeout

That is the whole platform surface it uses, so it runs in browsers, Node.js 18+, Bun and Deno alike. fetch is read from globalThis and can be replaced via the fetchFn option.

Because the server sends CORS headers on every route, the client works from a browser page directly, with no proxy in between.

What the package exports

Export Kind Purpose
LiveChatApiClient class The polling client
ApiHttpError class Every failure the client raises
extractVideoId function Reduce a URL or id to an 11-character video id
ILiveChatApiClient type The client's interface
LiveChatClientOptions type Constructor options
ConnectedListener, MessageListener, ErrorListener, EndListener types Event handler signatures
FetchFn type The injectable fetch signature
MessageSchema, PartSchema, ThumbnailSchema, … schemas The shared request/response schemas

The schemas are the same definitions the server validates against — the client package owns them and the server imports them, so the contract cannot drift between the two.

Verify the install

import { extractVideoId } from '@gettersethya/yt-livechat-client'

console.log(extractVideoId('https://youtu.be/zvwJ29RFVww'))
// -> "zvwJ29RFVww"

Next