Guide

TikTok LIVE WebSocket API

Connect to any TikTok LIVE stream via WebSocket. Receive real-time chat messages, gifts, viewer counts, battles, and engagement data with sub-50ms latency. Works with any programming language.

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 direct protocol connections to TikTok's broadcast infrastructure (which break frequently), TikTool's WebSocket API is a stable, production-grade relay 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_KEY

WebSocket Connection Parameters

ParameterRequiredDescription
uniqueIdTikTok username (without @) of the streamer
apiKeyYour TikTool API key
jwtKeyJWT-based auth (alternative to apiKey for tokenized browser clients)

Event Types

Every WebSocket message is a JSON object with event and data fields. Here are the events you'll receive:

chat

New chat message from a viewer. Includes user info, message text, and badges.

gift

Virtual gift sent by a viewer. Includes gift name, diamond value, and repeat count.

like

A viewer liked the stream. Includes total like count.

member

A viewer joined the stream. Fires when users enter the live room.

social

Follow / share / favourite. The data.action field tells you which (follow, share, favourite).

roomUserSeq

Viewer count update. Includes current viewerCount and topViewers.

subscribe

A viewer subscribed to the streamer.

battle

LinkMic battle event. Includes battle status, scores, duration, and participants.

battleArmies

Battle armies update. Team scores and participant rankings.

linkMic

LinkMic guest layout update. Includes slot/guest user IDs for multi-host streams.

roomPin

A chat message was pinned by the streamer.

liveIntro

Stream introduction update. Includes stream title and description.

emoteChat

Custom emote sent in chat. Includes emote ID and image URL.

envelope

Treasure chest / red-envelope event in the stream.

question

Viewer-submitted Q&A question.

rankUpdate

Per-region rank refresh for the streamer.

barrage

Top-of-screen barrage/announcement message.

superFan

A viewer became a Super Fan or levelled up. Includes the new level.

superFanJoin

A Super Fan joined the room.

superFanBox

Super Fan box / reward event.

control

Stream lifecycle control (pause, end, etc.).

Connection Limits by Tier

TierConnectionsPrice
Sandbox (free)15Sandbox Tier
Pro50from $15/week
Ultra250from $45/week
Agency250 + Firehosefrom $119/week

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()

Frequently Asked Questions

How do I connect to a TikTok live stream via WebSocket?

What programming languages work with TikTok LIVE WebSocket?

Is the TikTok LIVE WebSocket API free?

How is this different from open-source live stream libraries?

What is the latency of the WebSocket connection?