Skip to main content

Connection URL

wss://api.tik.tools?uniqueId=TIKTOK_USERNAME&apiKey=YOUR_API_KEY

Query Parameters

ParameterTypeRequiredDescription
uniqueIdstringYesTikTok username (without @)
apiKeystringYes*Your API key (*or use jwtKey)
jwtKeystringYes*JWT token for frontend auth (*or use apiKey)

Connection Example

import WebSocket from 'ws';

const ws = new WebSocket('wss://api.tik.tools?uniqueId=streamer&apiKey=YOUR_KEY');

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

ws.on('message', (raw) => {
  const { event, data } = JSON.parse(raw);
  switch (event) {
    case 'roomInfo': console.log('Room:', data.roomId); break;
    case 'chat':     console.log(data.user.uniqueId + ':', data.comment); break;
    case 'gift':     console.log(data.user.uniqueId, 'sent', data.giftName); break;
    case 'like':     console.log(data.user.uniqueId, 'liked ×' + data.likeCount); break;
    case 'member':   console.log(data.user.uniqueId, 'joined'); break;
  }
});

ws.on('close', (code, reason) => console.log('Closed:', code, reason.toString()));

Message Format

Every WebSocket message is a JSON object with:
{
  "event": "chat",
  "data": {
    "type": "chat",
    "user": {
      "uniqueId": "viewer123",
      "nickname": "Cool Viewer",
      "userId": "6892636847263982593",
      "profilePictureUrl": "https://..."
    },
    "comment": "Hello streamer!"
  }
}

First Event: roomInfo

The first event you receive after connecting is always roomInfo with the room metadata:
{
  "event": "roomInfo",
  "roomId": "71234567890",
  "uniqueId": "streamer",
  "roomInfo": {
    "title": "Stream Title",
    "user_count": 1234,
    "like_count": 5678,
    "owner": { "nickname": "Streamer", "uniqueId": "streamer" }
  }
}

Connection Limits

TierMax ConnectionsMax Duration
Sandbox15 minutes
Basic530 minutes
Pro50Unlimited
Ultra500Unlimited

Reconnection

If the WebSocket disconnects, implement exponential backoff:
let reconnectDelay = 1000;

function connect() {
  const ws = new WebSocket('wss://api.tik.tools?uniqueId=streamer&apiKey=KEY');

  ws.on('open', () => {
    reconnectDelay = 1000; // Reset on successful connection
  });

  ws.on('close', (code) => {
    if (code !== 4003) { // Don't reconnect on auth errors
      setTimeout(connect, reconnectDelay);
      reconnectDelay = Math.min(reconnectDelay * 2, 30000);
    }
  });
}
See Close Codes for all possible close reasons.