Skip to main content

Unofficial TikTok LIVE API Client — Real-time chat, gifts, viewers, battles, and live captions from any TikTok livestream via the TikTool managed API.

Project description

tiktok-live-api

Unofficial TikTok LIVE API Client for Python — Connect to any TikTok LIVE stream and receive real-time chat messages, gifts, likes, follows, viewer counts, battles, and more. Powered by the TikTool managed API.

PyPI Python License

This package is not affiliated with or endorsed by TikTok. It connects to the TikTool Live managed API service — 99.9% uptime, no reverse engineering, no maintenance required. Also available for Node.js and any language via WebSocket.

Install

pip install tiktok-live-api

Quick Start

from tiktok_live_api import TikTokLive

client = TikTokLive("streamer_username", api_key="YOUR_API_KEY")

@client.on("chat")
def on_chat(event):
    print(f"{event['user']['uniqueId']}: {event['comment']}")

@client.on("gift")
def on_gift(event):
    print(f"{event['user']['uniqueId']} sent {event['giftName']} ({event['diamondCount']} 💎)")

@client.on("like")
def on_like(event):
    print(f"{event['user']['uniqueId']} liked (total: {event['totalLikes']})")

@client.on("follow")
def on_follow(event):
    print(f"{event['user']['uniqueId']} followed!")

@client.on("roomUserSeq")
def on_viewers(event):
    print(f"{event['viewerCount']} viewers watching")

client.run()

That's it. No complex setup, no protobuf, no reverse engineering.

Get a Free API Key

  1. Go to tik.tools
  2. Sign up (no credit card required)
  3. Copy your API key

The free Sandbox tier gives you 50 requests/day and 1 WebSocket connection.

Environment Variable

Instead of passing api_key directly, you can set it as an environment variable:

# Linux / macOS
export TIKTOOL_API_KEY=your_api_key_here

# Windows (CMD)
set TIKTOOL_API_KEY=your_api_key_here

# Windows (PowerShell)
$env:TIKTOOL_API_KEY="your_api_key_here"
python my_bot.py
from tiktok_live_api import TikTokLive

# Automatically reads TIKTOOL_API_KEY from environment
client = TikTokLive("streamer_username")
client.on("chat", lambda e: print(e["comment"]))
client.run()

Events

Event Description Key Fields
chat Chat message user, comment, emotes
gift Virtual gift user, giftName, diamondCount, repeatCount
like Like event user, likeCount, totalLikes
follow New follower user
share Stream share user
member Viewer joined user
subscribe New subscriber user
roomUserSeq Viewer count viewerCount, topViewers
battle Battle event type, teams, scores
envelope Treasure chest diamonds, user
streamEnd Stream ended reason
connected Connected uniqueId
disconnected Disconnected uniqueId
error Error occurred error
event Catch-all Full raw event

Live Captions (Speech-to-Text)

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

from tiktok_live_api import TikTokCaptions

captions = TikTokCaptions(
    "streamer_username",
    api_key="YOUR_API_KEY",
    translate="en",       # translate to English
    diarization=True,     # identify who is speaking
)

@captions.on("caption")
def on_caption(event):
    speaker = event.get("speaker", "")
    text = event["text"]
    is_final = event.get("isFinal", False)
    print(f"[{speaker}] {text}{'  ✓' if is_final else '...'}")

@captions.on("translation")
def on_translation(event):
    print(f"  → {event['text']}")

captions.run()

Async Usage

For integration with async frameworks (FastAPI, aiohttp, etc.):

import asyncio
from tiktok_live_api import TikTokLive

async def main():
    client = TikTokLive("streamer_username", api_key="YOUR_API_KEY")

    @client.on("chat")
    async def on_chat(event):
        print(f"{event['user']['uniqueId']}: {event['comment']}")

    await client.connect()

asyncio.run(main())

Chat Bot Example

from tiktok_live_api import TikTokLive

client = TikTokLive("streamer_username", api_key="YOUR_API_KEY")
gift_leaderboard = {}
message_count = 0

@client.on("chat")
def on_chat(event):
    global message_count
    message_count += 1
    msg = event["comment"].lower().strip()
    user = event["user"]["uniqueId"]

    if msg == "!hello":
        print(f">> BOT: Welcome {user}! 👋")
    elif msg == "!stats":
        print(f">> BOT: {message_count} messages, {len(gift_leaderboard)} gifters")
    elif msg == "!top":
        top = sorted(gift_leaderboard.items(), key=lambda x: -x[1])[:5]
        for i, (name, diamonds) in enumerate(top):
            print(f"  {i+1}. {name}{diamonds} 💎")

@client.on("gift")
def on_gift(event):
    user = event["user"]["uniqueId"]
    diamonds = event.get("diamondCount", 0)
    gift_leaderboard[user] = gift_leaderboard.get(user, 0) + diamonds

client.run()

Why tiktok-live-api?

tiktok-live-api TikTokLive (Python) tiktok-live-connector (Node.js)
Stability ✓ Managed API, 99.9% uptime ✗ Breaks on TikTok updates ✗ Breaks on TikTok updates
Live Captions ✓ AI speech-to-text
Maintenance ✓ Zero — we handle it ✗ You fix breakages ✗ You fix breakages
CAPTCHA Solving ✓ Built-in (Pro+)
Feed Discovery ✓ See who's live
Free Tier ✓ 50 requests/day ✓ Free (unreliable) ✓ Free (unreliable)

Pricing

Tier Requests/Day WebSocket Connections Price
Sandbox 50 1 (60s) Free
Basic 10,000 3 (8h) $7/week
Pro 75,000 50 (8h) $15/week
Ultra 300,000 500 (8h) $45/week

Also Available

  • Node.js/TypeScript: npm install @tiktool/live
  • Any language: Connect via WebSocket: wss://api.tik.tools?uniqueId=USERNAME&apiKey=KEY
  • Unreal Engine: Native C++/Blueprint plugin

Links

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tiktok_live_api-1.0.1.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tiktok_live_api-1.0.1-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file tiktok_live_api-1.0.1.tar.gz.

File metadata

  • Download URL: tiktok_live_api-1.0.1.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for tiktok_live_api-1.0.1.tar.gz
Algorithm Hash digest
SHA256 855c97a0012120ef8000c18283e872f37fc8d70ceb810e81a7b749975374aae6
MD5 d595c0e61d7ac5cefb4388919974885d
BLAKE2b-256 26de367cdd2126c56fb72514ee4a857c2ed0d29ace95024e9d564ccddc226f7c

See more details on using hashes here.

File details

Details for the file tiktok_live_api-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for tiktok_live_api-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 baabc08449ca961ea35b1ddf0485f22b4c3df4d49266316507332e6d4c524dce
MD5 6304bb2855dfac9f5bf9a92cb1be5244
BLAKE2b-256 1181e4429c796e860f81057ac24c5022db6f35dd29315e3fd29a2a31a36d51af

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page