Skip to main content

TikTok LIVE API Client — Real-time chat, gifts, viewers, battles, and live captions from any TikTok livestream. Production-ready managed API.

Project description

tiktok-live-api

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.

PyPI Python License

Production-ready alternative to the TikTokLive library. Unlike TikTokLive which reverse-engineers TikTok's internal protocol and breaks frequently, tiktok-live-api connects to TikTool Live's managed API service — 99.9% uptime, zero maintenance. Also available for Node.js: npm install @tiktool/live.

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.0.tar.gz (8.8 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.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tiktok_live_api-1.0.0.tar.gz
  • Upload date:
  • Size: 8.8 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.0.tar.gz
Algorithm Hash digest
SHA256 4a6ca2e7325315023763d6736d3f4e38598a13b228234f476b80a8a236c2c36d
MD5 29395602c2ecafa1c105a8a1b083c8d6
BLAKE2b-256 07c09747779c36d7cb4cee36e6dc25c2cf2d7758426514836986fc3dba624db4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiktok_live_api-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c5e0fb4661492e552da18243381555af262993ef4cf6f58865fb63d19d56d1f2
MD5 818652eb2114bf9e2ff7ced0bdb5b2e0
BLAKE2b-256 febf0a1e4d39426b709d2a8146d4e72b546ba046b30abbf0a59eaa0228f4021a

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