DEV Community

TikTool
TikTool

Posted on

Connect to Any TikTok LIVE Stream in 5 Minutes — Real-time Events with Node.js

Want to build something on top of TikTok LIVE? Track gifts, monitor chat, count viewers, trigger alerts? Here's how to connect to any live stream and receive every event in real-time — in 5 minutes, zero reverse engineering.

I just tested this on a live stream 10 minutes ago. It works.

Install

npm install tiktok-live-api
Enter fullscreen mode Exit fullscreen mode

Get a Free API Key

Go to tik.tools, sign up (no credit card), copy your API key.

Connect to a Live Stream

// demo.mjs — run with: node demo.mjs
import { TikTokLive } from 'tiktok-live-api';

const client = new TikTokLive('gbnews', {
  apiKey: 'YOUR_API_KEY'
});

client.on('chat', (e) => {
  console.log(`💬 ${e.user.uniqueId}: ${e.comment}`);
});

client.on('gift', (e) => {
  console.log(`🎁 ${e.user.uniqueId} sent ${e.giftName} (${e.diamondCount} 💎)`);
});

client.on('like', (e) => {
  console.log(`❤️ ${e.user.uniqueId} liked × ${e.likeCount}`);
});

client.on('member', (e) => {
  console.log(`👋 ${e.user.uniqueId} joined`);
});

client.on('roomUserSeq', (e) => {
  console.log(`👀 ${e.viewerCount} viewers watching`);
});

client.on('connected', () => console.log('✅ Connected!'));

client.connect();
Enter fullscreen mode Exit fullscreen mode

Replace gbnews with any TikTok username that's currently live. That's it — you'll see every event in your terminal.

What This Actually Outputs

I just ran this on a live Greek stream. Real output:

✅ Connected!
💬 andrianniwww: Έχω όρεξη να τα χαλάω
💬 _tzotzo._: Analogws, min fame kaneno 10-20k
💬 damasiotis: Telione nistazo
👀 16 viewers watching
Enter fullscreen mode Exit fullscreen mode

Every chat message, gift, like, follow, viewer join — all in real-time via WebSocket.

Build a Gift Tracker

Now let's make it useful. This tracks every gift, maintains a running diamond total, and shows a live leaderboard:

// gift-tracker.mjs
import { TikTokLive } from 'tiktok-live-api';

const client = new TikTokLive('USERNAME_HERE', {
  apiKey: 'YOUR_API_KEY'
});

const leaderboard = new Map();
let totalDiamonds = 0;

client.on('gift', (e) => {
  const user = e.user.uniqueId;
  const diamonds = e.diamondCount || 0;

  totalDiamonds += diamonds;
  leaderboard.set(user, (leaderboard.get(user) || 0) + diamonds);

  console.log(`🎁 ${user} sent ${e.giftName} (${diamonds} 💎)`);
  console.log(`   Stream total: ${totalDiamonds} 💎`);

  // Show top 5
  const top = [...leaderboard.entries()]
    .sort(([,a], [,b]) => b - a)
    .slice(0, 5);
  console.log('\n🏆 Leaderboard:');
  top.forEach(([name, d], i) => {
    console.log(`  ${i + 1}. @${name}${d} 💎`);
  });
  console.log();
});

client.on('connected', () => console.log('✅ Tracking gifts...'));
client.connect();
Enter fullscreen mode Exit fullscreen mode

Available Events

Event What you get
chat e.user.uniqueId, e.comment
gift e.user.uniqueId, e.giftName, e.diamondCount
like e.user.uniqueId, e.likeCount
follow e.user.uniqueId
member e.user.uniqueId (viewer joined)
roomUserSeq e.viewerCount
battle Battle scores and teams
connected Connection confirmed

All events are fully typed in TypeScript — your IDE autocompletes every field.

What Can You Build With This?

  • OBS stream overlays — forward events to a browser source via local WebSocket
  • Discord webhooks — alert your server about big gifts or milestones
  • Analytics dashboards — track engagement trends across streams
  • AI live captions — real-time speech-to-text with translation (unique to this SDK)
  • Automated moderation — flag certain chat patterns

Also Available

  • Python: pip install tiktok-live-api (PyPI)
  • Any language: Raw WebSocket: wss://api.tik.tools?uniqueId=USERNAME&apiKey=KEY
  • Docs: tik.tools/docs

Free Sandbox tier: 50 requests/day, 1 WebSocket connection — enough to build and test.

Top comments (0)