How the TikTok Live WebSocket Works
TikTool provides a managed WebSocket endpoint at wss://api.tik.tools that streams real-time events from any TikTok LIVE stream. You connect with your API key and a TikTok username — the server handles all protocol negotiation, authentication, and reconnection logic.
Unlike reverse-engineered solutions that connect directly to TikTok's internal WebCast protocol (and break frequently), TikTool's WebSocket API is a stable, production-grade proxy with 99.9% uptime SLA.
Quick Start — Connect in 3 Lines
JavaScript / Node.js
import { TikTokLive } from '@tiktool/live'
const client = new TikTokLive('streamer_username', { apiKey: 'YOUR_KEY' })
client.on('chat', e => console.log(`${e.user.uniqueId}: ${e.comment}`))
client.connect()Or connect directly with native WebSocket (no SDK needed):
const ws = new WebSocket('wss://api.tik.tools?uniqueId=USERNAME&apiKey=YOUR_KEY')
ws.onmessage = (msg) => {
const event = JSON.parse(msg.data)
console.log(event.event, event.data)
}Python
import asyncio, websockets, json
async def connect():
uri = "wss://api.tik.tools?uniqueId=USERNAME&apiKey=YOUR_KEY"
async with websockets.connect(uri) as ws:
async for message in ws:
event = json.loads(message)
print(event["event"], event.get("data", {}))Any Language
Any language with WebSocket support works — Go, Rust, Java, C#, Ruby, PHP. Just connect to:
wss://api.tik.tools?uniqueId=TIKTOK_USERNAME&apiKey=YOUR_API_KEYWebSocket Connection Parameters
uniqueId✓TikTok username (without @) of the streamerapiKey✓Your TikTool API keysessionIdResume a previous session after disconnectEvent Types
Every WebSocket message is a JSON object with event and data fields. Here are the events you'll receive:
chatNew chat message from a viewer. Includes user info, message text, and badges.
giftVirtual gift sent by a viewer. Includes gift name, diamond value, and repeat count.
likeA viewer liked the stream. Includes total like count.
memberA viewer joined the stream. Fires when users enter the live room.
followA viewer followed the streamer during the live stream.
shareA viewer shared the live stream with their friends.
roomUserSeqViewer count update. Includes current viewerCount and topViewers.
subscribeA viewer subscribed to the streamer.
linkMicBattleBattle/LinkMic event. Includes battle status, scores, and participants.
linkMicArmiesBattle armies update. Team scores and participant rankings.
roomPinA chat message was pinned by the streamer.
liveIntroStream introduction update. Includes stream title and description.
emoteCustom emote sent in chat.
envelopeTreasure chest/envelope event in the stream.
Connection Limits by Tier
Error Handling & Reconnection
The WebSocket will close with standard close codes. Your client should handle reconnection:
// Auto-reconnect pattern (Node.js)
function connect() {
const ws = new WebSocket('wss://api.tik.tools?uniqueId=USERNAME&apiKey=KEY')
ws.onmessage = (msg) => {
const event = JSON.parse(msg.data)
// Process event
}
ws.onclose = (e) => {
console.log(`Disconnected (${e.code}). Reconnecting in 3s...`)
setTimeout(connect, 3000)
}
ws.onerror = (err) => {
console.error('WebSocket error:', err.message)
ws.close()
}
}
connect()