TikTokLive supports proxying both HTTP requests and WebSocket connections. This is useful for bypassing regional restrictions or managing connection limits.
Proxy Types
TikTokLive supports two types of proxies:
- HTTP Proxy (
web_proxy) - Used for HTTP requests when fetching room information
- WebSocket Proxy (
ws_proxy) - Used for the WebSocket connection to TikTok’s live chat
Using ws_proxy will never subject you to reduced connection limits, while web_proxy may experience reduced limits during high load.
Supported Proxy Protocols
Basic Configuration
Import required modules
from httpx import Proxy
from TikTokLive import TikTokLiveClient
from TikTokLive.events import ConnectEvent
Create proxy objects
# HTTP proxy for web requests
web_proxy = Proxy(
"http://hostname:port",
auth=("username", "password")
)
# SOCKS5 proxy for WebSocket connection
ws_proxy = Proxy(
"socks5://hostname:port",
auth=("username", "password")
)
Create client with proxies
client: TikTokLiveClient = TikTokLiveClient(
unique_id="@username",
web_proxy=web_proxy,
ws_proxy=ws_proxy
)
Complete Example
from httpx import Proxy
from TikTokLive.client.client import TikTokLiveClient
from TikTokLive.client.logger import LogLevel
from TikTokLive.events import ConnectEvent
# Create the client
client: TikTokLiveClient = TikTokLiveClient(
unique_id="@tv_asahi_news",
# You can configure a proxy for web requests
web_proxy=Proxy("http://hostname:port", auth=("username", "password")),
# You can also configure a proxy for the websocket connection
ws_proxy=Proxy("socks5://hostname:port", auth=("username", "password")),
)
@client.on(ConnectEvent)
async def on_connect(event: ConnectEvent):
client.logger.info(f"Connected to {event.unique_id}!")
if __name__ == '__main__':
client.logger.setLevel(LogLevel.INFO.value)
client.run()
Proxy Authentication
If your proxy requires authentication, pass credentials using the auth parameter:
proxy = Proxy(
"http://hostname:port",
auth=("username", "password")
)
Using Different Proxy Types
HTTP Proxy
web_proxy = Proxy("http://proxy.example.com:8080")
HTTPS Proxy
web_proxy = Proxy("https://proxy.example.com:443")
SOCKS5 Proxy
ws_proxy = Proxy("socks5://proxy.example.com:1080")
Proxy Without Authentication
If your proxy doesn’t require authentication, simply omit the auth parameter:
client: TikTokLiveClient = TikTokLiveClient(
unique_id="@username",
web_proxy=Proxy("http://hostname:port"),
ws_proxy=Proxy("socks5://hostname:port")
)
Use Cases
When to use web_proxy: For bypassing regional restrictions when fetching room informationWhen to use ws_proxy: For maintaining stable WebSocket connections and avoiding connection limits
Best Practices
Always test your proxy connection before deploying to production. Invalid proxy configurations will cause connection failures.
- Use
ws_proxy for the most reliable connection
- Rotate proxies if you’re managing multiple connections
- Monitor proxy performance and switch if experiencing issues
- Keep proxy credentials secure and never commit them to version control