Connect to any TikTok Live stream and receive real-time events in Elixir. No signing server, no API keys, no authentication required.
# Start a GenServer that connects and streams events to the calling process
{:ok, pid} = PirateTok.Live.Client.start_link("username_here")
# Events arrive as messages — pattern match on the type
receive do
{:tiktok_live, :chat, msg} ->
IO.puts("[chat] #{msg.user.nickname}: #{msg.comment}")
{:tiktok_live, :gift, msg} ->
IO.puts("[gift] #{msg.user.nickname} sent #{msg.gift.name} x#{msg.repeat_count}")
{:tiktok_live, :like, msg} ->
IO.puts("[like] #{msg.user.nickname} (#{msg.total_likes} total)")
{:tiktok_live, :disconnected, _} ->
IO.puts("stream ended")
enddef deps do
[
{:piratetok_live, "~> 0.1.0"}
]
endRequires Elixir >= 1.15.
| Language | Install | Repo |
|---|---|---|
| Rust | cargo add piratetok-live-rs |
live-rs |
| Go | go get github.com/PirateTok/live-go |
live-go |
| Python | pip install piratetok-live-py |
live-py |
| JavaScript | npm install piratetok-live-js |
live-js |
| C# | dotnet add package PirateTok.Live |
live-cs |
| Java | com.piratetok:live |
live-java |
| Lua | luarocks install piratetok-live-lua |
live-lua |
| Dart | dart pub add piratetok_live |
live-dart |
| C | #include "piratetok.h" |
live-c |
| PowerShell | Install-Module PirateTok.Live |
live-ps1 |
| Shell | bpkg install PirateTok/live-sh |
live-sh |
- Zero signing dependency -- no API keys, no signing server, no external auth
- 64 decoded event types -- protobuf DSL modules via
protobufhex package, no codegen - GenServer-based -- events delivered as process messages
{:tiktok_live, type, data} - Auto-reconnection -- stale detection, exponential backoff, self-healing auth
- Enriched User data -- badges, gifter level, moderator status, follow info, fan club
- Sub-routed convenience events --
:follow,:share,:join,:live_endedfire alongside raw events
{:ok, pid} = PirateTok.Live.Client.start_link("username_here",
cdn: :eu, # :eu / :us / :global (default)
timeout: 15_000, # HTTP timeout in ms (default 10_000)
max_retries: 10, # reconnect attempts (default 5)
stale_timeout: 90_000 # reconnect after N ms of silence (default 60_000)
)# Check if user is live
{:ok, room_id} = PirateTok.Live.Http.Api.check_online("username_here")
# Fetch room metadata (title, viewers, stream URLs)
{:ok, info} = PirateTok.Live.Http.Api.fetch_room_info(room_id)
# 18+ rooms -- pass session cookies from browser DevTools
{:ok, info} = PirateTok.Live.Http.Api.fetch_room_info(room_id,
cookies: "sessionid=abc; sid_tt=abc")- Resolves username to room ID via TikTok JSON API
- Authenticates and opens a direct WSS connection
- Sends protobuf heartbeats every 10s to keep alive
- Decodes protobuf event stream into Elixir structs
- Auto-reconnects on stale/dropped connections with fresh credentials
All protobuf schemas are defined via use Protobuf field declarations -- no .proto files, no codegen.
mix run examples/basic_chat.exs <username> # connect + print chat events
mix run examples/online_check.exs <username> # check if user is live
mix run examples/stream_info.exs <username> # fetch room metadata + stream URLs
mix run examples/gift_tracker.exs <username> # track gifts with diamond totals- Explicit
DEVICE_BLOCKEDhandshake handling is not implemented yet. - Proxy support is not implemented yet.
0BSD
