Developer Guide

TikTok LIVE API for Node.js

Build TikTok LIVE assistants, overlays, and dashboards in JavaScript. npm install, connect in 3 lines, receive real-time events. Free SDK, open-source, MIT license.

Why Node.js?

Node.js is the most popular runtime for TikTok LIVE integrations. The official @tiktool/live SDK is written in TypeScript, published on npm, and includes full type definitions out of the box. You get:

  • Type safety - full TypeScript definitions for every event and method
  • Auto-reconnection - the SDK handles dropped connections automatically
  • Event-driven - familiar .on('event', handler) pattern
  • Works everywhere - Node.js 18+, Bun, Deno

Install the SDK

npm install @tiktool/live

Or with other package managers:

# Yarn
yarn add @tiktool/live

# pnpm
pnpm add @tiktool/live

# Bun
bun add @tiktool/live

Quick Start: 3 Lines to Live Data

Create app.mjs and paste:

import { TikTokLive } from '@tiktool/live'

const client = new TikTokLive({
  uniqueId: 'tv_asahi_news',   // TikTok username (without @)
  apiKey: process.env.TIKTOOL_API_KEY
})

client.on('chat', (event) => {
  console.log(`${event.user.nickname}: ${event.comment}`)
})

await client.connect()

Run it:

TIKTOOL_API_KEY=your_api_key node app.mjs

You'll see chat messages flowing in your terminal within seconds.

Common Events

The SDK emits structured events for every interaction on the stream:

import { TikTokLive } from '@tiktool/live'

const client = new TikTokLive({
  uniqueId: 'target_username',
  apiKey: process.env.TIKTOOL_API_KEY
})

// Chat messages
client.on('chat', (event) => {
  console.log(`[CHAT] ${event.user.nickname}: ${event.comment}`)
})

// Virtual gifts (Rose, Universe, etc.)
client.on('gift', (event) => {
  console.log(`[GIFT] ${event.user.nickname} sent ${event.giftName} x${event.repeatCount} (${event.diamondCount * event.repeatCount} diamonds)`)
})

// Follows and shares arrive as one 'social' event with an action field
client.on('social', (event) => {
  if (event.action === 'follow') console.log(`[FOLLOW] ${event.user.nickname} just followed!`)
  else if (event.action === 'share') console.log(`[SHARE] ${event.user.nickname} shared the stream`)
})

// Likes
client.on('like', (event) => {
  console.log(`[LIKE] ${event.user.nickname} liked (total: ${event.totalLikes})`)
})

// Viewer count changes
client.on('roomUserSeq', (event) => {
  console.log(`[VIEWERS] ${event.viewerCount} watching`)
})

// Member joins (someone enters the stream)
client.on('member', (event) => {
  console.log(`[JOIN] ${event.user.nickname} joined the stream`)
})

await client.connect()
console.log('Connected and listening!')

Expected Output

Connected and listening!
[VIEWERS] 3412 watching
[CHAT] viewer_1: Hello everyone!
[FOLLOW] new_fan just followed!
[GIFT] whale_user sent Universe x1 (34000 diamonds)
[LIKE] cool_viewer liked (total: 12847)
[CHAT] fan_123: Love this stream!
[JOIN] curious_viewer joined the stream
[SHARE] supporter_1 shared the stream

TypeScript Support

The SDK is written in TypeScript. Types are included automatically - no @types package needed:

import { TikTokLive } from '@tiktool/live'
import type { ChatEvent, GiftEvent } from '@tiktool/live'

const client = new TikTokLive({
  uniqueId: 'target_username',
  apiKey: process.env.TIKTOOL_API_KEY
})

client.on('chat', (event: ChatEvent) => {
  // event.comment, event.user.nickname, event.user.id - all typed
  console.log(event.user.nickname, event.comment)
})

client.on('gift', (event: GiftEvent) => {
  // event.giftName, event.diamondCount, event.repeatCount - all typed
  if (event.diamondCount >= 100) {
    console.log(`Big gift from ${event.user.nickname}!`)
  }
})

await client.connect()

Raw WebSocket (No SDK)

Prefer to use the raw WebSocket directly? It works with any language or framework:

import WebSocket from 'ws'  // npm install ws

const ws = new WebSocket(
  'wss://api.tik.tools?uniqueId=tv_asahi_news&apiKey=YOUR_API_KEY'
)

ws.on('message', (raw) => {
  const msg = JSON.parse(raw.toString())

  switch (msg.event) {
    case 'chat':
      console.log(`${msg.data.user.nickname}: ${msg.data.comment}`)
      break
    case 'gift':
      console.log(`Gift: ${msg.data.giftName} (${msg.data.diamondCount} diamonds)`)
      break
    case 'roomUserSeq':
      console.log(`Viewers: ${msg.data.viewerCount}`)
      break
  }
})

ws.on('open', () => console.log('Connected!'))

FAQ

Does TikTok have an official Node.js API?

No. TikTok does not offer a public API for LIVE stream data. The TikTools API is a managed third-party service that provides reliable real-time access to chat, gifts, viewers, and other LIVE events. The @tiktool/live npm package is the official SDK for this API.

Is it free?

The SDK is free to install. API access starts with a 7-day Sandbox evaluation: 5,000 requests/day and 15 concurrent WebSocket connections, evaluation only, no credit card required. After 7 days a paid plan is required. Sign up here.

Can I use it with Express, Fastify, or Next.js?

Yes. The SDK works in any Node.js environment. Use it in Express route handlers, Fastify plugins, Next.js API routes, or standalone scripts.

Does it work with Bun and Deno?

Yes. The SDK is compatible with Bun and Deno. Install via bun add @tiktool/live or import from npm in Deno.