Node.js library to receive live stream events (comments, gifts, etc.) in realtime from TikTok LIVE.
Node.js library to receive live stream events (comments, gifts, etc.) in realtime from TikTok LIVE.
TikTok LIVE API Client for Node.JS (Unofficial, Unaffiliated with ByteDance Ltd.)
Connect to any TikTok LIVE stream and receive real-time chat messages,
gifts, likes, follows, shares, viewer counts and battles using just a creator's username (@uniqueId).
No login, credentials or app registration are required.
TikTokLiveConnector reads TikTok's internal Webcast push service directly, which makes it the foundation for TikTok chat bots, gift trackers, OBS overlays, donation alerts, moderation tools and livestream analytics. It works for your own live chat and for any other creator's.
Tracked events include Chat Comments, Members Joining, Gifts, Viewers, Follows, Shares, Questions, Likes, Super Fans and Battles.
[!NOTE] This is not a production-ready API. It is a reverse engineering project. Use the WebSocket API for production.
[!TIP] An example project is available at https://tiktok-chat-reader.zerody.one/ - View Source
npm i tiktok-live-connector…A prebuilt image on GitHub Container Registry streams every event from a LIVE as one JSON object per line on
stdout, so you can pipe it into jq, a log shipper, or any process that reads stdin. No Node.js install needed.
docker run --rm -e SIGN_API_KEY=your-api-key ghcr.io/zerodytrash/tiktok-live-connector tv_asahi_newsEach line looks like {"event":"chat","ts":1758000000000,"data":{...}}. event is one of the
message event names (chat, gift, like, ...) or connected, disconnected, error.
ts is the receive time in milliseconds. Protobuf 64-bit integers are emitted as strings and byte fields as base64.
| Variable | Description |
|---|---|
SIGN_API_KEY |
Euler Stream API key. See Signing Configuration. |
TIKTOK_UNIQUE_ID |
Username to connect to, as an alternative to the positional argument. |
TIKTOK_EVENTS |
Comma-separated events to emit, e.g. chat,gift,like. Defaults to all message events. |
SIGN_API_URL |
Custom sign server base URL. |
The container exits with code 0 when the stream ends or it receives SIGTERM, 1 on a connection error, and
2 on a usage error. Image tags track the npm version (2.5.0, 2.5, 2, latest) and the image is built for
linux/amd64 and linux/arm64. It supports anonymous connections only; for authenticated sessions or custom
options, use the library directly.
To create a new TikTokLiveConnection object the following parameters can be specified.
TikTokLiveConnection(uniqueId, [options])
| Param Name | Required | Description |
|---|---|---|
uniqueId |
Yes | The unique username of the broadcaster. You can find this name in the URL. Example: https://www.tiktok.com/@officialgeilegisela/live becomes officialgeilegisela. The leading @ and the full URL form are also accepted. |
options |
No | Optional connection properties. Defaults are applied when a value is not specified.signApiKey (default: undefined)Euler Stream API key. When provided, it is written to the global SignConfig.apiKey before the underlying Euler client is created. Ignored when eulerApiInstance is passed.eulerApiInstance (default: undefined)Pre-built EulerStreamApiClient to use for all sign-server traffic. Takes precedence over signApiKey.session (default: undefined)Authenticated session bundle. Pass session.cookie to seed the cookie jar with sessionid and tt-target-idc, and/or session.oAuthToken to send an OAuth token to the sign server. Required when authenticateWs or useMobile is true. See Authenticated Connection.authenticateWs (default: false)Forward the session cookies or OAuth token to the sign server so the WebSocket is authenticated. Disabled by default since signing is done by a third-party service; enabling it sends your session credentials to that service. useMobile (default: false)Use the mobile WebSocket flow. Requires authenticateWs: true and session.cookie; connecting with useMobile but without authenticateWs throws a TypeError.processInitialData (default: true)Decode and emit the message batch returned in the initial sign response (recent chat history etc.). fetchRoomInfoOnConnect (default: true)Fetch room info during connect. If the streamer is not currently live the connect rejects with UserOfflineError. The fetched info is stored on connection.roomInfo and is also accessible via fetchRoomInfo().enableExtendedGiftInfo (default: false)Fetch the room gift list during connect so WebcastGiftMessage events carry an extendedGiftInfo field with name, cost, and image data.clientPresets (default: randomized)Pre-built { device, screen, location } presets. Defaults to a freshly randomized set from getRandomPresets().webClientOptions (default: {})Extra options forwarded to the underlying got HTTP client (proxy agent, timeout, etc.). Headers and search params from this object are merged with the defaults; transport-only fields are passed through. See Proxied Connection.wsClientOptions (default: {})Extra options forwarded to the underlying ws WebSocket client. See Proxied Connection.webConfigOverrides (default: {})Partial overrides for the resolved WebcastWebConfigDefaults used by the HTTP client. Use this to customize DEFAULT_HTTP_CLIENT_PARAMS, DEFAULT_HTTP_CLIENT_HEADERS, etc.wsConfigOverrides (default: {})Partial overrides for the resolved WebcastWebSocketConfigDefaults used by the WebSocket client. Use this to customize DEFAULT_WS_CLIENT_PARAMS or DEFAULT_WS_CLIENT_HEADERS. |
…| Method Name | Description |
|---|---|
connect([roomId]) |
Connects to the live stream chat. Returns a Promise<TikTokLiveConnectionState> that resolves when the WebSocket is open and the room has been entered. Pass an explicit roomId to skip room-id resolution. |
disconnect() |
Closes the WebSocket and waits for the close event before resolving. Safe to call even when not connected. |
sendMessage(content, [roomId]) |
Sends a chat message to the connected room (or to roomId if provided). Requires signApiKey and an authenticated session. See Send Messages. |
fetchRoomId([uniqueId]) |
Resolves the room id for the configured username (or for uniqueId if provided). Tries HTML scrape, then the TikTok API, then Euler Stream as a fallback. |
fetchIsLive([uniqueId]) |
Resolves whether the user is currently live. Same fallback chain as fetchRoomId. |
waitUntilLive([seconds], [abortSignal]) |
Polls fetchIsLive every seconds seconds (minimum 30) until the streamer goes live. Reject via abortSignal to cancel. |
fetchRoomInfo([roomId]) |
Fetches room info from TikTok's webcast API. Caches the result on connection.roomInfo. Callable without an active connection. See Retrieve Room Info. |
fetchAvailableGifts() |
Fetches the room gift list. Caches on connection.availableGifts. Callable without an active connection. See Retrieve Available Gifts. |
| Property Name | Description |
|---|---|
webClient: WebcastHttpClient |
The HTTP client used to talk to TikTok's web and webcast APIs. Holds the cookie jar, the merged client params, and the merged client headers. |
apiClient: EulerStreamApiClient |
The Euler Stream API client used for sign-server traffic and other premium endpoints. Equivalent to webClient.apiClient. |
wsClient: WebcastWebSocketClient | null |
The active WebSocket client. null until the connection is established and after disconnect. |
options: TikTokLiveConnectionMutableOptions |
The subset of options retained on the instance (processInitialData, fetchRoomInfoOnConnect, enableExtendedGiftInfo, authenticateWs, useMobile). |
roomInfo: RoomInfo | null |
The room info object cached from the most recent fetchRoomInfo() call (or from connect, when fetchRoomInfoOnConnect is true). |
availableGifts: RoomGiftInfo | null |
The cached gift list. Populated when enableExtendedGiftInfo is true or after manually calling fetchAvailableGifts(). |
isConnecting: boolean |
True while connect() is in flight. |
isConnected: boolean |
True after a successful connect, until the WebSocket closes. |
clientParams: Record<string, string> |
Live URI parameters sent with every webClient request. Mutating this changes outgoing query strings. |
roomId: string |
The currently bound room id. Empty string until connect resolves or fetchRoomId() is called. |
state: TikTokLiveConnectionState |
Snapshot containing isConnected, isConnecting, roomId, roomInfo, and availableGifts. |
WebSocket URL signing is delegated to the Euler Stream sign server via the
@eulerstream/euler-api-sdk package. Configuration is held on the
mutable SignConfig singleton.
For most users, passing signApiKey to the TikTokLiveConnection constructor is enough. It writes the key to
SignConfig.apiKey before the underlying Euler client is built.
For advanced cases (custom sign-server URL, extra headers, JWT auth), mutate SignConfig directly before
constructing your first connection:
import { SignConfig } from 'tiktok-live-connector';
SignConfig.apiKey = 'your api key'; // An API key created at https://www.eulerstream.com
SignConfig.basePath = 'https://your-custom-sign-server.com';
SignConfig.baseOptions = SignConfig.baseOptions || {};
SignConfig.baseOptions.headers = {
...(SignConfig.baseOptions.headers || {}),
'X-Custom-Header': 'Custom-Header-Value'
};[!IMPORTANT]
SignConfigis read once when the underlying
No open issues yet, or sync has not completed.