Skip to main content

Overview

The TikTokWebClient is a wrapper for the HTTP client that provides access to TikTok LIVE API routes. It extends TikTokHTTPClient and registers various routes for interacting with TikTok’s web services.

Usage

The web client is automatically instantiated when you create a TikTokLiveClient. Access it via the client.web property:
from TikTokLive import TikTokLiveClient

client = TikTokLiveClient(unique_id="@username")

# Access the web client
web_client = client.web

# Use routes
room_id = await web_client.fetch_room_id_from_api("username")
is_live = await web_client.fetch_is_live(room_id=room_id)

Available Routes

The TikTokWebClient provides the following route attributes:

Room Information Routes

fetch_room_id_from_html

Type: FetchRoomIdLiveHTMLRoute Fetch a user’s room ID by parsing their livestream HTML page.
room_id = await client.web.fetch_room_id_from_html("username")

fetch_room_id_from_api

Type: FetchRoomIdAPIRoute Fetch a user’s room ID from TikTok’s API endpoint.
room_id = await client.web.fetch_room_id_from_api("username")

fetch_room_info

Type: FetchRoomInfoRoute Retrieve detailed room information for a livestream.
room_info = await client.web.fetch_room_info(room_id=123456)
# Or by unique_id
room_info = await client.web.fetch_room_info(unique_id="username")

Status Routes

fetch_is_live

Type: FetchIsLiveRoute Check if a user is currently live.
# Check by room_id
is_live = await client.web.fetch_is_live(room_id=123456)

# Check by unique_id
is_live = await client.web.fetch_is_live(unique_id="username")

Gift Routes

fetch_gift_list

Type: FetchGifListRoute Fetch the list of available gifts from TikTok.
gift_data = await client.web.fetch_gift_list()

Media Routes

fetch_image_data

Type: FetchImageDataRoute Download image data from TikTok’s CDN.
from TikTokLive.proto import ImageModel

# From ImageModel
image_bytes = await client.web.fetch_image_data(image_model)

# From URL string
image_bytes = await client.web.fetch_image_data("https://...")

fetch_video_data

Type: FetchVideoDataRoute Record a livestream video in real-time.
from TikTokLive.client.web.routes.fetch_video_data import VideoFetchQuality, VideoFetchFormat

client.web.fetch_video_data(
    output_fp="recording.flv",
    room_info=room_info,
    quality=VideoFetchQuality.HD,
    record_format=VideoFetchFormat.FLV,
    record_for=300  # Record for 5 minutes
)

WebSocket Routes

fetch_signed_websocket

Type: FetchSignedWebSocketRoute Fetch signed WebSocket connection data from the signature server.
from TikTokLive.client.web.routes.fetch_signed_websocket import WebcastPlatform

ws_data = await client.web.fetch_signed_websocket(
    platform=WebcastPlatform.WEB,
    room_id=123456
)

User Routes

fetch_user_unique_id

Type: FetchUserUniqueIdRoute Resolve a user ID to their unique_id (username).
unique_id = await client.web.fetch_user_unique_id(user_id=7230478347297063942)

Interaction Routes

These routes require authentication via session cookies. See Session Management for details.

send_room_chat

Type: SendRoomChatRoute Send a chat message to a livestream room.
response = await client.web.send_room_chat(
    content="Hello!",
    room_id=123456,
    session_id="your_session_id"
)

send_room_like

Type: SendRoomLikeRoute Send likes to a livestream room.
response = await client.web.send_room_like(
    count=5,
    room_id=123456
)

send_room_gift

Type: SendRoomGiftRoute Send a gift to a livestream broadcaster.
from TikTokLive.client.web.routes.send_room_gift import GiftPayload
import time

payload: GiftPayload = {
    "room_id": 123456,
    "count": 1,
    "gift_id": 5655,
    "to_user_id": 7230478347297063942,
    "enter_from": "live_detail_",
    "is_opted_in_host": True,
    "is_subscription": False,
    "send_gift_req_start_ms": int(time.time() * 1000),
    "send_scene": 1,
    "send_type": 1
}

response = await client.web.send_room_gift(payload)

Deprecated Properties

fetch_video

Deprecated. Use fetch_video_data instead.

fetch_image

Deprecated. Use fetch_image_data instead.

Constructor

TikTokWebClient(**kwargs)

Parameters

  • **kwargs - Arguments passed to the parent TikTokHTTPClient class

See Also

Build docs developers (and LLMs) love