Tutorial

TikTok LIVE API Python Guide

Connect to any TikTok LIVE stream from Python using TikTool Live's WebSocket API. Receive real-time chat messages, gifts, viewer counts, and more - production-ready, fully managed.

Why Use TikTool Live for Python?

The MIT-licensed TikTokLive Python client connects directly to TikTok's broadcast protocol and delegates signing to a managed backend (the default is Euler Stream, which has its own free tier and paid plans). It is a self-host-the-client + managed-signing model maintained by the Euler Stream team.

TikTool Live is an independent managed API service with its own signing infrastructure. It handles protocol changes server-side, publishes a 99.9% uptime target, and works with any language via standard WebSocket. No protocol handling required - just connect and receive events. Choose whichever model fits your team.

Hosting model✓ Fully managed - 99.9% uptime~ Self-hosted client + managed signing
Setup✓ pip install websockets~ pip install TikTokLive
Live Captions✓ AI Speech-to-Text✗ Not available
Maintenance surface✓ Zero - handled server-side~ Client + signing backend updates

Prerequisites

  • Python 3.8+ installed
  • A free TikTool Live API key - get one here

Option 1: asyncio + websockets

The simplest approach - use the standard websockets library to connect to TikTool Live's WebSocket API:

pip install websockets
import asyncio
import websockets
import json
import os

API_KEY = os.environ.get("TIKTOOL_API_KEY", "YOUR_API_KEY")
STREAMER = "tv_asahi_news"  # TikTok username (without @)

async def connect():
    uri = f"wss://api.tik.tools?uniqueId={STREAMER}&apiKey={API_KEY}"

    async with websockets.connect(uri) as ws:
        print(f"✅ Connected to @{STREAMER}")

        async for message in ws:
            event = json.loads(message)
            event_type = event.get("event", "")
            data = event.get("data", {})

            if event_type == "chat":
                user = data.get("user", {}).get("uniqueId", "?")
                comment = data.get("comment", "")
                print(f"[CHAT] {user}: {comment}")

            elif event_type == "gift":
                user = data.get("user", {}).get("uniqueId", "?")
                gift = data.get("giftName", "?")
                diamonds = data.get("diamondCount", 0)
                print(f"[GIFT] {user} sent {gift} ({diamonds} 💎)")

            elif event_type == "member":
                user = data.get("user", {}).get("uniqueId", "?")
                print(f"[JOIN] {user} joined")

            elif event_type == "roomUserSeq":
                viewers = data.get("viewerCount", 0)
                print(f"[VIEWERS] {viewers} watching")

asyncio.run(connect())

Option 2: REST API with requests

For one-off data fetching (room info, user profiles), use the REST API:

pip install requests
import requests

API_KEY = "YOUR_API_KEY"
BASE = "https://api.tik.tools"

# Get room info for a streamer
resp = requests.get(f"{BASE}/webcast/room_info/", params={
    "uniqueId": "tv_asahi_news",
    "apiKey": API_KEY,
})
data = resp.json()
print(f"Title: {data.get('title', 'N/A')}")
print(f"Viewers: {data.get('viewer_count', 0)}")
print(f"Status: {'LIVE' if data.get('alive') else 'OFFLINE'}")

Option 3: Live Captions (Speech-to-Text)

Transcribe and translate any TikTok LIVE stream's audio in real-time. This feature is unique to TikTool Live - no other service offers it.

import asyncio
import websockets
import json
import os

API_KEY = os.environ.get("TIKTOOL_API_KEY", "YOUR_API_KEY")
STREAMER = "tv_asahi_news"

async def captions():
    uri = (
        f"wss://api.tik.tools/captions"
        f"?uniqueId={STREAMER}"
        f"&apiKey={API_KEY}"
        f"&translate=en"
        f"&diarization=true"
    )

    async with websockets.connect(uri) as ws:
        print(f"🎤 Captions started for @{STREAMER}")

        async for message in ws:
            event = json.loads(message)
            msg_type = event.get("type", "")

            if msg_type == "caption":
                speaker = event.get("speaker", "")
                text = event.get("text", "")
                is_final = event.get("isFinal", False)
                prefix = f"[{speaker}] " if speaker else ""
                suffix = " ✓" if is_final else "..."
                print(f"{prefix}{text}{suffix}")

            elif msg_type == "translation":
                print(f"  → {event.get('text', '')}")

            elif msg_type == "credits":
                remaining = event.get("remaining", 0)
                total = event.get("total", 0)
                print(f"[CREDITS] {remaining}/{total} min remaining")

asyncio.run(captions())

Running the Scripts

# Set your API key as environment variable
export TIKTOOL_API_KEY=your_api_key_here

# Run the WebSocket example
python tiktok_live.py

# Run the captions example
python tiktok_captions.py

Expected Output

✅ Connected to @tv_asahi_news
[VIEWERS] 1,234 watching
[CHAT] viewer42: Hello everyone!
[GIFT] big_fan sent Rose (1 💎)
[CHAT] news_watcher: Great coverage
[JOIN] new_viewer joined
[VIEWERS] 1,237 watching

Next Steps

  • Store events in a database - pipe events to PostgreSQL, MongoDB, or SQLite
  • Build a dashboard - use Flask or FastAPI to create a real-time web dashboard
  • AI analysis - feed chat messages to GPT/Claude for sentiment analysis
  • Multi-stream - monitor multiple streams simultaneously (Pro tier: 50 connections)
  • Live subtitles - use the Captions API for accessibility or translation