tiktok-live-api 1.1.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,364 +1,435 @@
1
- # tiktok-live-api
2
-
3
- **Unofficial TikTok LIVE API Client for Node.js & TypeScript** — Connect to any TikTok LIVE stream and receive real-time chat messages, gifts, likes, follows, viewer counts, battles, and more. Includes AI-powered live captions (speech-to-text). Powered by the [TikTool](https://tik.tools) managed API.
4
-
5
- [![npm](https://img.shields.io/npm/v/tiktok-live-api)](https://www.npmjs.com/package/tiktok-live-api)
6
- [![npm downloads](https://img.shields.io/npm/dm/tiktok-live-api)](https://www.npmjs.com/package/tiktok-live-api)
7
- [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue)](https://www.typescriptlang.org/)
8
- [![License](https://img.shields.io/npm/l/tiktok-live-api)](https://github.com/tiktool/tiktok-live-api/blob/main/LICENSE)
9
- [![Discord](https://img.shields.io/discord/1482387222912172159?logo=discord&label=Discord&color=5865F2)](https://discord.gg/y8TwuFBAmD)
10
-
11
- > This package is **not affiliated with or endorsed by TikTok**. It connects to the [TikTool Live](https://tik.tools) managed API service — 99.9% uptime, no reverse engineering, no maintenance required. Also available for [Python](https://pypi.org/project/tiktok-live-api/) and [any language via WebSocket](https://tik.tools/docs).
12
-
13
- ## Install
14
-
15
- ```bash
16
- npm install tiktok-live-api
17
- ```
18
-
19
- ```bash
20
- # or with yarn / pnpm / bun
21
- yarn add tiktok-live-api
22
- pnpm add tiktok-live-api
23
- bun add tiktok-live-api
24
- ```
25
-
26
- ## Quick Start
27
-
28
- ```typescript
29
- import { TikTokLive } from 'tiktok-live-api';
30
-
31
- const client = new TikTokLive('streamer_username', { apiKey: 'YOUR_API_KEY' });
32
-
33
- client.on('chat', (event) => {
34
- console.log(`${event.user.uniqueId}: ${event.comment}`);
35
- });
36
-
37
- client.on('gift', (event) => {
38
- console.log(`${event.user.uniqueId} sent ${event.giftName} (${event.diamondCount} 💎)`);
39
- });
40
-
41
- client.on('like', (event) => {
42
- console.log(`${event.user.uniqueId} liked (total: ${event.totalLikes})`);
43
- });
44
-
45
- client.on('follow', (event) => {
46
- console.log(`${event.user.uniqueId} followed!`);
47
- });
48
-
49
- client.on('roomUserSeq', (event) => {
50
- console.log(`${event.viewerCount} viewers watching`);
51
- });
52
-
53
- client.connect();
54
- ```
55
-
56
- That's it. **No complex setup, no protobuf, no reverse engineering, no breakages when TikTok updates.**
57
-
58
- ---
59
-
60
- ## 🚀 Try It Now — 5-Minute Live Demo
61
-
62
- Copy-paste this into a file and run it. Connects to a live TikTok stream, prints every event for 5 minutes, then exits. Works on the free Sandbox tier.
63
-
64
- **Save as `demo.mjs` and run with `node demo.mjs`:**
65
-
66
- ```javascript
67
- // demo.mjs — TikTok LIVE in 5 minutes
68
- // npm install tiktok-live-api
69
- import { TikTokLive } from 'tiktok-live-api';
70
-
71
- const API_KEY = 'YOUR_API_KEY'; // Get free key → https://tik.tools
72
- const LIVE_USERNAME = 'tv_asahi_news'; // Any live TikTok username
73
-
74
- const client = new TikTokLive(LIVE_USERNAME, { apiKey: API_KEY });
75
- let events = 0;
76
-
77
- client.on('chat', e => { events++; console.log(`💬 ${e.user.uniqueId}: ${e.comment}`); });
78
- client.on('gift', e => { events++; console.log(`🎁 ${e.user.uniqueId} sent ${e.giftName} (${e.diamondCount}💎)`); });
79
- client.on('like', e => { events++; console.log(`❤️ ${e.user.uniqueId} liked × ${e.likeCount}`); });
80
- client.on('member', e => { events++; console.log(`👋 ${e.user.uniqueId} joined`); });
81
- client.on('follow', e => { events++; console.log(`➕ ${e.user.uniqueId} followed`); });
82
- client.on('roomUserSeq', e => { events++; console.log(`👀 Viewers: ${e.viewerCount}`); });
83
-
84
- client.on('connected', () => console.log(`\n✅ Connected to @${LIVE_USERNAME} — listening for 5 min...\n`));
85
- client.on('disconnected', () => console.log(`\n📊 Done! Received ${events} events.\n`));
86
-
87
- client.connect();
88
- setTimeout(() => { client.disconnect(); }, 300_000);
89
- ```
90
-
91
- <details>
92
- <summary><strong>🔌 Pure WebSocket version (no SDK, any language)</strong></summary>
93
-
94
- ```javascript
95
- // ws-demo.mjs — Pure WebSocket, zero SDK
96
- // npm install ws
97
- import WebSocket from 'ws';
98
-
99
- const API_KEY = 'YOUR_API_KEY';
100
- const LIVE_USERNAME = 'tv_asahi_news';
101
-
102
- const ws = new WebSocket(`wss://api.tik.tools?uniqueId=${LIVE_USERNAME}&apiKey=${API_KEY}`);
103
- let events = 0;
104
-
105
- ws.on('open', () => console.log(`\n✅ Connected to @${LIVE_USERNAME} — listening for 5 min...\n`));
106
- ws.on('message', (raw) => {
107
- const msg = JSON.parse(raw);
108
- events++;
109
- const d = msg.data || {};
110
- const user = d.user?.uniqueId || '';
111
- switch (msg.event) {
112
- case 'chat': console.log(`💬 ${user}: ${d.comment}`); break;
113
- case 'gift': console.log(`🎁 ${user} sent ${d.giftName} (${d.diamondCount}💎)`); break;
114
- case 'like': console.log(`❤️ ${user} liked × ${d.likeCount}`); break;
115
- case 'member': console.log(`👋 ${user} joined`); break;
116
- case 'roomUserSeq': console.log(`👀 Viewers: ${d.viewerCount}`); break;
117
- case 'roomInfo': console.log(`📡 Room: ${msg.roomId}`); break;
118
- default: console.log(`📦 ${msg.event}`); break;
119
- }
120
- });
121
- ws.on('close', () => console.log(`\n📊 Done! Received ${events} events.\n`));
122
-
123
- setTimeout(() => ws.close(), 300_000);
124
- ```
125
-
126
- </details>
127
-
128
- ---
129
-
130
- ## JavaScript (CommonJS)
131
-
132
- ```javascript
133
- const { TikTokLive } = require('tiktok-live-api');
134
-
135
- const client = new TikTokLive('streamer_username', { apiKey: 'YOUR_API_KEY' });
136
- client.on('chat', (e) => console.log(`${e.user.uniqueId}: ${e.comment}`));
137
- client.connect();
138
- ```
139
-
140
- ## Get a Free API Key
141
-
142
- 1. Go to [tik.tools](https://tik.tools)
143
- 2. Sign up (no credit card required)
144
- 3. Copy your API key
145
-
146
- The free Sandbox tier gives you 50 requests/day and 1 WebSocket connection.
147
-
148
- ## Environment Variable
149
-
150
- Instead of passing `apiKey` directly, you can set it as an environment variable:
151
-
152
- ```bash
153
- # Linux / macOS
154
- export TIKTOOL_API_KEY=your_api_key_here
155
-
156
- # Windows (CMD)
157
- set TIKTOOL_API_KEY=your_api_key_here
158
-
159
- # Windows (PowerShell)
160
- $env:TIKTOOL_API_KEY="your_api_key_here"
161
- ```
162
-
163
- ```typescript
164
- import { TikTokLive } from 'tiktok-live-api';
165
-
166
- // Automatically reads TIKTOOL_API_KEY from environment
167
- const client = new TikTokLive('streamer_username');
168
- client.on('chat', (e) => console.log(e.comment));
169
- client.connect();
170
- ```
171
-
172
- ## Events
173
-
174
- | Event | Description | Key Fields |
175
- |-------|-------------|------------|
176
- | `chat` | Chat message | `user`, `comment`, `emotes` |
177
- | `gift` | Virtual gift | `user`, `giftName`, `diamondCount`, `repeatCount` |
178
- | `like` | Like event | `user`, `likeCount`, `totalLikes` |
179
- | `follow` | New follower | `user` |
180
- | `share` | Stream share | `user` |
181
- | `member` | Viewer joined | `user` |
182
- | `subscribe` | New subscriber | `user` |
183
- | `roomUserSeq` | Viewer count | `viewerCount`, `topViewers` |
184
- | `battle` | Battle event | `type`, `teams`, `scores` |
185
- | `roomPin` | Pinned/starred message | `user`, `comment`, `action`, `durationSeconds` |
186
- | `envelope` | Treasure chest | `diamonds`, `user` |
187
- | `streamEnd` | Stream ended | `reason` |
188
- | `connected` | Connected | `uniqueId` |
189
- | `disconnected` | Disconnected | `uniqueId` |
190
- | `error` | Error occurred | `error` |
191
- | `event` | Catch-all | Full raw event |
192
-
193
- All events are fully typed with TypeScript interfaces. Your IDE will show autocompletion for every field.
194
-
195
- ## Live Captions (Speech-to-Text)
196
-
197
- Transcribe and translate any TikTok LIVE stream in real-time. **This feature is unique to TikTool Live — no other TikTok library offers it.**
198
-
199
- ```typescript
200
- import { TikTokCaptions } from 'tiktok-live-api';
201
-
202
- const captions = new TikTokCaptions('streamer_username', {
203
- apiKey: 'YOUR_API_KEY',
204
- translate: 'en', // translate to English
205
- diarization: true, // identify who is speaking
206
- });
207
-
208
- captions.on('caption', (event) => {
209
- const speaker = event.speaker ? `[${event.speaker}] ` : '';
210
- console.log(`${speaker}${event.text}${event.isFinal ? ' ✓' : '...'}`);
211
- });
212
-
213
- captions.on('translation', (event) => {
214
- console.log(` → ${event.text}`);
215
- });
216
-
217
- captions.on('credits', (event) => {
218
- console.log(`${event.remaining}/${event.total} minutes remaining`);
219
- });
220
-
221
- captions.connect();
222
- ```
223
-
224
- ### Caption Events
225
-
226
- | Event | Description | Key Fields |
227
- |-------|-------------|------------|
228
- | `caption` | Real-time caption text | `text`, `speaker`, `isFinal`, `language` |
229
- | `translation` | Translated caption | `text`, `sourceLanguage`, `targetLanguage` |
230
- | `credits` | Credit balance update | `total`, `used`, `remaining` |
231
- | `credits_low` | Low credit warning | `remaining`, `percentage` |
232
- | `status` | Session status | `status`, `message` |
233
-
234
- ## Chat Bot Example
235
-
236
- ```typescript
237
- import { TikTokLive } from 'tiktok-live-api';
238
-
239
- const client = new TikTokLive('streamer_username', { apiKey: 'YOUR_API_KEY' });
240
- const giftLeaderboard = new Map<string, number>();
241
- let messageCount = 0;
242
-
243
- client.on('chat', (event) => {
244
- messageCount++;
245
- const msg = event.comment.toLowerCase().trim();
246
- const user = event.user.uniqueId;
247
-
248
- if (msg === '!hello') {
249
- console.log(`>> BOT: Welcome ${user}! 👋`);
250
- } else if (msg === '!stats') {
251
- console.log(`>> BOT: ${messageCount} messages, ${giftLeaderboard.size} gifters`);
252
- } else if (msg === '!top') {
253
- const top = [...giftLeaderboard.entries()]
254
- .sort((a, b) => b[1] - a[1])
255
- .slice(0, 5);
256
- top.forEach(([name, diamonds], i) => {
257
- console.log(` ${i + 1}. ${name} ${diamonds} 💎`);
258
- });
259
- }
260
- });
261
-
262
- client.on('gift', (event) => {
263
- const user = event.user.uniqueId;
264
- const diamonds = event.diamondCount || 0;
265
- giftLeaderboard.set(user, (giftLeaderboard.get(user) || 0) + diamonds);
266
- });
267
-
268
- client.connect();
269
- ```
270
-
271
- ## TypeScript
272
-
273
- This package ships with full TypeScript support. All events are typed:
274
-
275
- ```typescript
276
- import { TikTokLive, ChatEvent, GiftEvent } from 'tiktok-live-api';
277
-
278
- const client = new TikTokLive('streamer', { apiKey: 'KEY' });
279
-
280
- // Full autocompletion your IDE knows the type of `event`
281
- client.on('chat', (event: ChatEvent) => {
282
- console.log(event.user.uniqueId); // ✓ typed
283
- console.log(event.comment); // ✓ typed
284
- });
285
-
286
- client.on('gift', (event: GiftEvent) => {
287
- console.log(event.giftName); // ✓ typed
288
- console.log(event.diamondCount); // typed
289
- });
290
- ```
291
-
292
- ## API Reference
293
-
294
- ### `new TikTokLive(uniqueId, options?)`
295
-
296
- | Option | Type | Default | Description |
297
- |--------|------|---------|-------------|
298
- | `apiKey` | `string` | `process.env.TIKTOOL_API_KEY` | Your TikTool API key |
299
- | `autoReconnect` | `boolean` | `true` | Auto-reconnect on disconnect |
300
- | `maxReconnectAttempts` | `number` | `5` | Max reconnection attempts |
301
-
302
- **Methods:**
303
- - `client.on(event, handler)` Register event handler
304
- - `client.off(event, handler)` — Remove event handler
305
- - `client.connect()` Connect to stream (returns Promise)
306
- - `client.disconnect()` — Disconnect from stream
307
- - `client.connected` — Whether currently connected
308
- - `client.eventCount` Total events received
309
-
310
- ### `new TikTokCaptions(uniqueId, options?)`
311
-
312
- | Option | Type | Default | Description |
313
- |--------|------|---------|-------------|
314
- | `apiKey` | `string` | `process.env.TIKTOOL_API_KEY` | Your TikTool API key |
315
- | `translate` | `string` | `undefined` | Target translation language |
316
- | `diarization` | `boolean` | `true` | Enable speaker identification |
317
- | `maxDurationMinutes` | `number` | `60` | Auto-disconnect timer |
318
-
319
- **Methods:**
320
- - `captions.on(event, handler)` Register event handler
321
- - `captions.off(event, handler)` Remove event handler
322
- - `captions.connect()` Start receiving captions (returns Promise)
323
- - `captions.disconnect()` Stop receiving captions
324
- - `captions.connected` Whether currently connected
325
-
326
- ## Why tiktok-live-api?
327
-
328
- | | tiktok-live-api | tiktok-live-connector | TikTokLive (Python) |
329
- |---|---|---|---|
330
- | **Stability** | ✓ Managed API, 99.9% uptime | ✗ Breaks on TikTok updates | ✗ Breaks on TikTok updates |
331
- | **TypeScript** | ✓ First-class, fully typed | Partial | N/A |
332
- | **Live Captions** | ✓ AI speech-to-text | ✗ | ✗ |
333
- | **Translation** | ✓ Real-time, 50+ languages | ✗ | ✗ |
334
- | **Maintenance** | ✓ Zero — we handle it | ✗ You fix breakages | ✗ You fix breakages |
335
- | **CAPTCHA Solving** | Built-in (Pro+) | ✗ | ✗ |
336
- | **Feed Discovery** | See who's live | ✗ | ✗ |
337
- | **Free Tier** | ✓ 50 requests/day | ✓ Free (unreliable) | ✓ Free (unreliable) |
338
- | **ESM + CJS** | ✓ Both supported | ✓ | N/A |
339
-
340
- ## Pricing
341
-
342
- | Tier | Requests/Day | WebSocket Connections | Price |
343
- |------|-------------|----------------------|-------|
344
- | Sandbox | 50 | 1 (5 min) | Free |
345
- | Basic | 10,000 | 3 (8h) | $7/week |
346
- | Pro | 75,000 | 50 (8h) | $15/week |
347
- | Ultra | 300,000 | 500 (8h) | $45/week |
348
-
349
- ## Also Available
350
-
351
- - **Python**: [`pip install tiktok-live-api`](https://pypi.org/project/tiktok-live-api/)
352
- - **Any language**: Connect via WebSocket: `wss://api.tik.tools?uniqueId=USERNAME&apiKey=KEY`
353
- - **Unreal Engine**: Native C++/Blueprint plugin
354
-
355
- ## Links
356
-
357
- - 🌐 **Website**: [tik.tools](https://tik.tools)
358
- - 📖 **Documentation**: [tik.tools/docs](https://tik.tools/docs)
359
- - 🐍 **Python SDK**: [pypi.org/project/tiktok-live-api](https://pypi.org/project/tiktok-live-api/)
360
- - 💻 **GitHub**: [github.com/tiktool/tiktok-live-api](https://github.com/tiktool/tiktok-live-api)
361
-
362
- ## License
363
-
364
- MIT
1
+ <p align="center">
2
+ <img src="banner.png" alt="tiktok-live-api" width="100%" />
3
+ </p>
4
+
5
+ # tiktok-live-api
6
+
7
+ **Unofficial TikTok LIVE API Client for Node.js & TypeScript** — Connect to any TikTok LIVE stream and receive real-time chat messages, gifts, likes, follows, viewer counts, battles, and more. Includes AI-powered live captions (speech-to-text). Powered by the [TikTool](https://tik.tools) managed API.
8
+
9
+ [![npm](https://img.shields.io/npm/v/tiktok-live-api)](https://www.npmjs.com/package/tiktok-live-api)
10
+ [![npm downloads](https://img.shields.io/npm/dm/tiktok-live-api)](https://www.npmjs.com/package/tiktok-live-api)
11
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue)](https://www.typescriptlang.org/)
12
+ [![License](https://img.shields.io/npm/l/tiktok-live-api)](https://github.com/tiktool/tiktok-live-api/blob/main/LICENSE)
13
+ [![Discord](https://img.shields.io/discord/1482387222912172159?logo=discord&label=Discord&color=5865F2)](https://discord.gg/y8TwuFBAmD)
14
+
15
+ <p align="center">
16
+ <img src="https://raw.githubusercontent.com/tiktool/tiktok-live-api/main/tiktok-live-api.gif" alt="TikTok Live API Demo — real-time chat, gifts, and viewer events" width="700">
17
+ </p>
18
+
19
+ > This package is **not affiliated with or endorsed by TikTok**. It connects to the [TikTool Live](https://tik.tools) managed API service — 99.9% uptime, no reverse engineering, no maintenance required. Also available for [Python](https://pypi.org/project/tiktok-live-api/) and [any language via WebSocket](https://tik.tools/docs).
20
+
21
+ ## Install
22
+
23
+ ```bash
24
+ npm install tiktok-live-api
25
+ ```
26
+
27
+ ```bash
28
+ # or with yarn / pnpm / bun
29
+ yarn add tiktok-live-api
30
+ pnpm add tiktok-live-api
31
+ bun add tiktok-live-api
32
+ ```
33
+
34
+ ## Quick Start
35
+
36
+ ```typescript
37
+ import { TikTokLive } from 'tiktok-live-api';
38
+
39
+ const client = new TikTokLive('streamer_username', { apiKey: 'YOUR_API_KEY' });
40
+
41
+ client.on('chat', (event) => {
42
+ console.log(`${event.user.uniqueId}: ${event.comment}`);
43
+ });
44
+
45
+ client.on('gift', (event) => {
46
+ console.log(`${event.user.uniqueId} sent ${event.giftName} (${event.diamondCount} 💎)`);
47
+ });
48
+
49
+ client.on('like', (event) => {
50
+ console.log(`${event.user.uniqueId} liked (total: ${event.totalLikes})`);
51
+ });
52
+
53
+ client.on('follow', (event) => {
54
+ console.log(`${event.user.uniqueId} followed!`);
55
+ });
56
+
57
+ client.on('roomUserSeq', (event) => {
58
+ console.log(`${event.viewerCount} viewers watching`);
59
+ });
60
+
61
+ client.connect();
62
+ ```
63
+
64
+ That's it. **No complex setup, no protobuf, no reverse engineering, no breakages when TikTok updates.**
65
+
66
+ ---
67
+
68
+ ## 🚀 Try It Now — 5-Minute Live Demo
69
+
70
+ Copy-paste this into a file and run it. Connects to a live TikTok stream, prints every event for 5 minutes, then exits. Works on the free Sandbox tier.
71
+
72
+ **Save as `demo.mjs` and run with `node demo.mjs`:**
73
+
74
+ ```javascript
75
+ // demo.mjs TikTok LIVE in 5 minutes
76
+ // npm install tiktok-live-api
77
+ import { TikTokLive } from 'tiktok-live-api';
78
+
79
+ const API_KEY = 'YOUR_API_KEY'; // Get free key https://tik.tools
80
+ const LIVE_USERNAME = 'tv_asahi_news'; // Any live TikTok username
81
+
82
+ const client = new TikTokLive(LIVE_USERNAME, { apiKey: API_KEY });
83
+ let events = 0;
84
+
85
+ client.on('chat', e => { events++; console.log(`💬 ${e.user.uniqueId}: ${e.comment}`); });
86
+ client.on('gift', e => { events++; console.log(`🎁 ${e.user.uniqueId} sent ${e.giftName} (${e.diamondCount}💎)`); });
87
+ client.on('like', e => { events++; console.log(`❤️ ${e.user.uniqueId} liked × ${e.likeCount}`); });
88
+ client.on('member', e => { events++; console.log(`👋 ${e.user.uniqueId} joined`); });
89
+ client.on('follow', e => { events++; console.log(`➕ ${e.user.uniqueId} followed`); });
90
+ client.on('roomUserSeq', e => { events++; console.log(`👀 Viewers: ${e.viewerCount}`); });
91
+
92
+ client.on('connected', () => console.log(`\n✅ Connected to @${LIVE_USERNAME} listening for 5 min...\n`));
93
+ client.on('disconnected', () => console.log(`\n📊 Done! Received ${events} events.\n`));
94
+
95
+ client.connect();
96
+ setTimeout(() => { client.disconnect(); }, 300_000);
97
+ ```
98
+
99
+ <details>
100
+ <summary><strong>🔌 Pure WebSocket version (no SDK, any language)</strong></summary>
101
+
102
+ ```javascript
103
+ // ws-demo.mjs Pure WebSocket, zero SDK
104
+ // npm install ws
105
+ import WebSocket from 'ws';
106
+
107
+ const API_KEY = 'YOUR_API_KEY';
108
+ const LIVE_USERNAME = 'tv_asahi_news';
109
+
110
+ const ws = new WebSocket(`wss://api.tik.tools?uniqueId=${LIVE_USERNAME}&apiKey=${API_KEY}`);
111
+ let events = 0;
112
+
113
+ ws.on('open', () => console.log(`\n✅ Connected to @${LIVE_USERNAME} — listening for 5 min...\n`));
114
+ ws.on('message', (raw) => {
115
+ const msg = JSON.parse(raw);
116
+ events++;
117
+ const d = msg.data || {};
118
+ const user = d.user?.uniqueId || '';
119
+ switch (msg.event) {
120
+ case 'chat': console.log(`💬 ${user}: ${d.comment}`); break;
121
+ case 'gift': console.log(`🎁 ${user} sent ${d.giftName} (${d.diamondCount}💎)`); break;
122
+ case 'like': console.log(`❤️ ${user} liked × ${d.likeCount}`); break;
123
+ case 'member': console.log(`👋 ${user} joined`); break;
124
+ case 'roomUserSeq': console.log(`👀 Viewers: ${d.viewerCount}`); break;
125
+ case 'roomInfo': console.log(`📡 Room: ${msg.roomId}`); break;
126
+ default: console.log(`📦 ${msg.event}`); break;
127
+ }
128
+ });
129
+ ws.on('close', () => console.log(`\n📊 Done! Received ${events} events.\n`));
130
+
131
+ setTimeout(() => ws.close(), 300_000);
132
+ ```
133
+
134
+ </details>
135
+
136
+ ---
137
+
138
+ ## JavaScript (CommonJS)
139
+
140
+ ```javascript
141
+ const { TikTokLive } = require('tiktok-live-api');
142
+
143
+ const client = new TikTokLive('streamer_username', { apiKey: 'YOUR_API_KEY' });
144
+ client.on('chat', (e) => console.log(`${e.user.uniqueId}: ${e.comment}`));
145
+ client.connect();
146
+ ```
147
+
148
+ ## Get a Free API Key
149
+
150
+ 1. Go to [tik.tools](https://tik.tools)
151
+ 2. Sign up (no credit card required)
152
+ 3. Copy your API key
153
+
154
+ The free Sandbox tier gives you 50 requests/day and 1 WebSocket connection.
155
+
156
+ ## Environment Variable
157
+
158
+ Instead of passing `apiKey` directly, you can set it as an environment variable:
159
+
160
+ ```bash
161
+ # Linux / macOS
162
+ export TIKTOOL_API_KEY=your_api_key_here
163
+
164
+ # Windows (CMD)
165
+ set TIKTOOL_API_KEY=your_api_key_here
166
+
167
+ # Windows (PowerShell)
168
+ $env:TIKTOOL_API_KEY="your_api_key_here"
169
+ ```
170
+
171
+ ```typescript
172
+ import { TikTokLive } from 'tiktok-live-api';
173
+
174
+ // Automatically reads TIKTOOL_API_KEY from environment
175
+ const client = new TikTokLive('streamer_username');
176
+ client.on('chat', (e) => console.log(e.comment));
177
+ client.connect();
178
+ ```
179
+
180
+ ## Events
181
+
182
+ | Event | Description | Key Fields |
183
+ |-------|-------------|------------|
184
+ | `chat` | Chat message | `user`, `comment`, `emotes`, `starred?` |
185
+ | `gift` | Virtual gift | `user`, `giftName`, `diamondCount`, `repeatCount` |
186
+ | `like` | Like event | `user`, `likeCount`, `totalLikes` |
187
+ | `follow` | New follower | `user` |
188
+ | `share` | Stream share | `user` |
189
+ | `member` | Viewer joined | `user` |
190
+ | `subscribe` | New subscriber | `user` |
191
+ | `roomUserSeq` | Viewer count | `viewerCount`, `topViewers` |
192
+ | `battle` | Battle event | `type`, `teams`, `scores` |
193
+ | `roomPin` | Pinned/starred message | `user`, `comment`, `action`, `durationSeconds` |
194
+ | `envelope` | Treasure chest | `diamonds`, `user` |
195
+ | `streamEnd` | Stream ended | `reason` |
196
+ | `connected` | Connected | `uniqueId` |
197
+ | `disconnected` | Disconnected | `uniqueId` |
198
+ | `error` | Error occurred | `error` |
199
+ | `event` | Catch-all | Full raw event |
200
+
201
+ All events are fully typed with TypeScript interfaces. Your IDE will show autocompletion for every field.
202
+
203
+ ## Live Captions (Speech-to-Text)
204
+
205
+ Transcribe and translate any TikTok LIVE stream in real-time. **This feature is unique to TikTool Live — no other TikTok library offers it.**
206
+
207
+ ```typescript
208
+ import { TikTokCaptions } from 'tiktok-live-api';
209
+
210
+ <<<<<<< HEAD
211
+ live.on('event', (event) => {
212
+ console.log(event.type, event);
213
+ });
214
+ ```
215
+
216
+ ### Reference
217
+
218
+ | Event | Type | Description | Fields |
219
+ |-------|------|-------------|--------|
220
+ | `chat` | `ChatEvent` | Chat message | `user`, `comment`, `starred?` |
221
+ | `member` | `MemberEvent` | User joined | `user`, `action` |
222
+ | `like` | `LikeEvent` | User liked | `user`, `likeCount`, `totalLikes` |
223
+ | `gift` | `GiftEvent` | Gift sent | `user`, `giftName`, `diamondCount`, `repeatCount`, `combo` |
224
+ | `social` | `SocialEvent` | Follow / Share | `user`, `action` |
225
+ | `roomUserSeq` | `RoomUserSeqEvent` | Viewer count | `viewerCount`, `totalViewers` |
226
+ | `battle` | `BattleEvent` | Link Mic battle | `status` |
227
+ | `battleArmies` | `BattleArmiesEvent` | Battle teams | — |
228
+ | `subscribe` | `SubscribeEvent` | New subscriber | `user`, `subMonth` |
229
+ | `emoteChat` | `EmoteChatEvent` | Emote in chat | `user`, `emoteId` |
230
+ | `envelope` | `EnvelopeEvent` | Treasure chest | `diamondCount` |
231
+ | `question` | `QuestionEvent` | Q&A question | `user`, `questionText` |
232
+ | `control` | `ControlEvent` | Stream control | `action` (3 = ended) |
233
+ | `room` | `RoomEvent` | Room status | `status` |
234
+ | `liveIntro` | `LiveIntroEvent` | Stream intro | `title` |
235
+ | `rankUpdate` | `RankUpdateEvent` | Rank update | `rankType` |
236
+ | `linkMic` | `LinkMicEvent` | Link Mic | `action` |
237
+ | `roomPin` | `RoomPinEvent` | Pinned/starred message | `user`, `comment`, `action`, `durationSeconds` |
238
+ | `unknown` | `UnknownEvent` | Unrecognized | `method` |
239
+
240
+ ### Connection Events
241
+
242
+ | Event | Callback | Description |
243
+ |-------|----------|-------------|
244
+ | `connected` | `() => void` | Connected to stream |
245
+ | `disconnected` | `(code, reason) => void` | Disconnected |
246
+ | `roomInfo` | `(info: RoomInfo) => void` | Room info |
247
+ | `error` | `(error: Error) => void` | Error |
248
+
249
+ ---
250
+
251
+ ## 🎤 Real-Time Live Captions
252
+
253
+ AI-powered speech-to-text transcription and translation for TikTok LIVE streams. Features include:
254
+
255
+ - **Auto-detect language** — Automatically identifies the spoken language
256
+ - **Speaker diarization** Identifies individual speakers in multi-person streams
257
+ - **Real-time translation**Translate to any supported language with sub-second latency
258
+ - **Partial + final results** — Get streaming partial transcripts and confirmed final text
259
+ - **Credit-based billing** — 1 credit = 1 minute of transcription/translation
260
+
261
+ ### Quick Start
262
+
263
+ ```typescript
264
+ import { TikTokCaptions } from '@tiktool/live';
265
+
266
+ const captions = new TikTokCaptions({
267
+ uniqueId: 'streamer_name',
268
+ apiKey: 'YOUR_API_KEY',
269
+ translate: 'en',
270
+ diarization: true,
271
+ =======
272
+ const captions = new TikTokCaptions('streamer_username', {
273
+ apiKey: 'YOUR_API_KEY',
274
+ translate: 'en', // translate to English
275
+ diarization: true, // identify who is speaking
276
+ >>>>>>> ac7990ac0be77c4206d9d8fa0bccbe1c85a2bbe6
277
+ });
278
+
279
+ captions.on('caption', (event) => {
280
+ const speaker = event.speaker ? `[${event.speaker}] ` : '';
281
+ console.log(`${speaker}${event.text}${event.isFinal ? '' : '...'}`);
282
+ });
283
+
284
+ captions.on('translation', (event) => {
285
+ console.log(` → ${event.text}`);
286
+ });
287
+
288
+ captions.on('credits', (event) => {
289
+ console.log(`${event.remaining}/${event.total} minutes remaining`);
290
+ });
291
+
292
+ captions.connect();
293
+ ```
294
+
295
+ ### Caption Events
296
+
297
+ | Event | Description | Key Fields |
298
+ |-------|-------------|------------|
299
+ | `caption` | Real-time caption text | `text`, `speaker`, `isFinal`, `language` |
300
+ | `translation` | Translated caption | `text`, `sourceLanguage`, `targetLanguage` |
301
+ | `credits` | Credit balance update | `total`, `used`, `remaining` |
302
+ | `credits_low` | Low credit warning | `remaining`, `percentage` |
303
+ | `status` | Session status | `status`, `message` |
304
+
305
+ ## Chat Bot Example
306
+
307
+ ```typescript
308
+ import { TikTokLive } from 'tiktok-live-api';
309
+
310
+ const client = new TikTokLive('streamer_username', { apiKey: 'YOUR_API_KEY' });
311
+ const giftLeaderboard = new Map<string, number>();
312
+ let messageCount = 0;
313
+
314
+ client.on('chat', (event) => {
315
+ messageCount++;
316
+ const msg = event.comment.toLowerCase().trim();
317
+ const user = event.user.uniqueId;
318
+
319
+ if (msg === '!hello') {
320
+ console.log(`>> BOT: Welcome ${user}! 👋`);
321
+ } else if (msg === '!stats') {
322
+ console.log(`>> BOT: ${messageCount} messages, ${giftLeaderboard.size} gifters`);
323
+ } else if (msg === '!top') {
324
+ const top = [...giftLeaderboard.entries()]
325
+ .sort((a, b) => b[1] - a[1])
326
+ .slice(0, 5);
327
+ top.forEach(([name, diamonds], i) => {
328
+ console.log(` ${i + 1}. ${name} ${diamonds} 💎`);
329
+ });
330
+ }
331
+ });
332
+
333
+ client.on('gift', (event) => {
334
+ const user = event.user.uniqueId;
335
+ const diamonds = event.diamondCount || 0;
336
+ giftLeaderboard.set(user, (giftLeaderboard.get(user) || 0) + diamonds);
337
+ });
338
+
339
+ client.connect();
340
+ ```
341
+
342
+ ## TypeScript
343
+
344
+ This package ships with full TypeScript support. All events are typed:
345
+
346
+ ```typescript
347
+ import { TikTokLive, ChatEvent, GiftEvent } from 'tiktok-live-api';
348
+
349
+ const client = new TikTokLive('streamer', { apiKey: 'KEY' });
350
+
351
+ // Full autocompletion your IDE knows the type of `event`
352
+ client.on('chat', (event: ChatEvent) => {
353
+ console.log(event.user.uniqueId); // typed
354
+ console.log(event.comment); // ✓ typed
355
+ });
356
+
357
+ client.on('gift', (event: GiftEvent) => {
358
+ console.log(event.giftName); // ✓ typed
359
+ console.log(event.diamondCount); // ✓ typed
360
+ });
361
+ ```
362
+
363
+ ## API Reference
364
+
365
+ ### `new TikTokLive(uniqueId, options?)`
366
+
367
+ | Option | Type | Default | Description |
368
+ |--------|------|---------|-------------|
369
+ | `apiKey` | `string` | `process.env.TIKTOOL_API_KEY` | Your TikTool API key |
370
+ | `autoReconnect` | `boolean` | `true` | Auto-reconnect on disconnect |
371
+ | `maxReconnectAttempts` | `number` | `5` | Max reconnection attempts |
372
+
373
+ **Methods:**
374
+ - `client.on(event, handler)` — Register event handler
375
+ - `client.off(event, handler)` — Remove event handler
376
+ - `client.connect()` — Connect to stream (returns Promise)
377
+ - `client.disconnect()` — Disconnect from stream
378
+ - `client.connected` — Whether currently connected
379
+ - `client.eventCount` — Total events received
380
+
381
+ ### `new TikTokCaptions(uniqueId, options?)`
382
+
383
+ | Option | Type | Default | Description |
384
+ |--------|------|---------|-------------|
385
+ | `apiKey` | `string` | `process.env.TIKTOOL_API_KEY` | Your TikTool API key |
386
+ | `translate` | `string` | `undefined` | Target translation language |
387
+ | `diarization` | `boolean` | `true` | Enable speaker identification |
388
+ | `maxDurationMinutes` | `number` | `60` | Auto-disconnect timer |
389
+
390
+ **Methods:**
391
+ - `captions.on(event, handler)` — Register event handler
392
+ - `captions.off(event, handler)` — Remove event handler
393
+ - `captions.connect()` — Start receiving captions (returns Promise)
394
+ - `captions.disconnect()` — Stop receiving captions
395
+ - `captions.connected` — Whether currently connected
396
+
397
+ ## Why tiktok-live-api?
398
+
399
+ | | tiktok-live-api | tiktok-live-connector | TikTokLive (Python) |
400
+ |---|---|---|---|
401
+ | **Stability** | ✓ Managed API, 99.9% uptime | ✗ Breaks on TikTok updates | ✗ Breaks on TikTok updates |
402
+ | **TypeScript** | ✓ First-class, fully typed | Partial | N/A |
403
+ | **Live Captions** | ✓ AI speech-to-text | ✗ | ✗ |
404
+ | **Translation** | ✓ Real-time, 50+ languages | ✗ | ✗ |
405
+ | **Maintenance** | ✓ Zero — we handle it | ✗ You fix breakages | ✗ You fix breakages |
406
+ | **CAPTCHA Solving** | ✓ Built-in (Pro+) | ✗ | ✗ |
407
+ | **Feed Discovery** | ✓ See who's live | ✗ | ✗ |
408
+ | **Free Tier** | ✓ 50 requests/day | ✓ Free (unreliable) | ✓ Free (unreliable) |
409
+ | **ESM + CJS** | ✓ Both supported | ✓ | N/A |
410
+
411
+ ## Pricing
412
+
413
+ | Tier | Requests/Day | WebSocket Connections | Price |
414
+ |------|-------------|----------------------|-------|
415
+ | Sandbox | 50 | 1 (5 min) | Free |
416
+ | Basic | 10,000 | 3 (8h) | $7/week |
417
+ | Pro | 75,000 | 50 (8h) | $15/week |
418
+ | Ultra | 300,000 | 500 (8h) | $45/week |
419
+
420
+ ## Also Available
421
+
422
+ - **Python**: [`pip install tiktok-live-api`](https://pypi.org/project/tiktok-live-api/)
423
+ - **Any language**: Connect via WebSocket: `wss://api.tik.tools?uniqueId=USERNAME&apiKey=KEY`
424
+ - **Unreal Engine**: Native C++/Blueprint plugin
425
+
426
+ ## Links
427
+
428
+ - 🌐 **Website**: [tik.tools](https://tik.tools)
429
+ - 📖 **Documentation**: [tik.tools/docs](https://tik.tools/docs)
430
+ - 🐍 **Python SDK**: [pypi.org/project/tiktok-live-api](https://pypi.org/project/tiktok-live-api/)
431
+ - 💻 **GitHub**: [github.com/tiktool/tiktok-live-api](https://github.com/tiktool/tiktok-live-api)
432
+
433
+ ## License
434
+
435
+ MIT
package/dist/index.d.mts CHANGED
@@ -23,6 +23,11 @@ interface ChatEvent {
23
23
  emoteId: string;
24
24
  image: string;
25
25
  }>;
26
+ /** Present only for starred (paid highlighted) chat messages. */
27
+ starred?: {
28
+ claps: number;
29
+ score: number;
30
+ };
26
31
  }
27
32
  /** Payload for `gift` events. */
28
33
  interface GiftEvent {
package/dist/index.d.ts CHANGED
@@ -23,6 +23,11 @@ interface ChatEvent {
23
23
  emoteId: string;
24
24
  image: string;
25
25
  }>;
26
+ /** Present only for starred (paid highlighted) chat messages. */
27
+ starred?: {
28
+ claps: number;
29
+ score: number;
30
+ };
26
31
  }
27
32
  /** Payload for `gift` events. */
28
33
  interface GiftEvent {
package/package.json CHANGED
@@ -1,84 +1,84 @@
1
- {
2
- "name": "tiktok-live-api",
3
- "version": "1.1.0",
4
- "description": "Unofficial TikTok LIVE API Client — Real-time chat, gifts, viewers, battles, and AI live captions from any TikTok livestream. Managed WebSocket API with 99.9% uptime.",
5
- "main": "dist/index.js",
6
- "module": "dist/index.mjs",
7
- "types": "dist/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "types": "./dist/index.d.ts",
11
- "import": "./dist/index.mjs",
12
- "require": "./dist/index.js"
13
- }
14
- },
15
- "files": [
16
- "dist",
17
- "README.md",
18
- "LICENSE"
19
- ],
20
- "scripts": {
21
- "build": "tsup src/index.ts --format cjs,esm --dts --clean",
22
- "prepublishOnly": "npm run build"
23
- },
24
- "keywords": [
25
- "tiktok",
26
- "tiktok-live",
27
- "tiktok-api",
28
- "tiktok-live-api",
29
- "tiktok-live-connector",
30
- "tiktok-live-sdk",
31
- "tiktok-websocket",
32
- "tiktok-chat",
33
- "tiktok-gifts",
34
- "tiktok-bot",
35
- "tiktok-data",
36
- "tiktok-stream",
37
- "tiktok-events",
38
- "tiktok-viewer",
39
- "live-streaming",
40
- "live-chat",
41
- "webcast",
42
- "websocket",
43
- "real-time",
44
- "speech-to-text",
45
- "captions",
46
- "transcription",
47
- "translation",
48
- "tiktok-live-python",
49
- "tiktok-tools",
50
- "euler-stream",
51
- "tiktoklive",
52
- "tiktok-connector",
53
- "tiktok-live-node",
54
- "tiktok-live-js",
55
- "tiktok-scraper",
56
- "tiktok-monitoring",
57
- "livestream-api"
58
- ],
59
- "author": {
60
- "name": "TikTool",
61
- "email": "support@tik.tools",
62
- "url": "https://tik.tools"
63
- },
64
- "license": "MIT",
65
- "repository": {
66
- "type": "git",
67
- "url": "https://github.com/tiktool/tiktok-live-api"
68
- },
69
- "bugs": {
70
- "url": "https://github.com/tiktool/tiktok-live-api/issues"
71
- },
72
- "homepage": "https://tik.tools",
73
- "dependencies": {
74
- "ws": "^8.16.0"
75
- },
76
- "devDependencies": {
77
- "@types/ws": "^8.5.10",
78
- "tsup": "^8.0.0",
79
- "typescript": "^5.3.0"
80
- },
81
- "engines": {
82
- "node": ">=16.0.0"
83
- }
84
- }
1
+ {
2
+ "name": "tiktok-live-api",
3
+ "version": "1.2.1",
4
+ "description": "Unofficial TikTok LIVE API Client — Real-time chat, gifts, viewers, battles, and AI live captions from any TikTok livestream. Managed WebSocket API with 99.9% uptime.",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsup src/index.ts --format cjs,esm --dts --clean",
22
+ "prepublishOnly": "npm run build"
23
+ },
24
+ "keywords": [
25
+ "tiktok",
26
+ "tiktok-live",
27
+ "tiktok-api",
28
+ "tiktok-live-api",
29
+ "tiktok-live-connector",
30
+ "tiktok-live-sdk",
31
+ "tiktok-websocket",
32
+ "tiktok-chat",
33
+ "tiktok-gifts",
34
+ "tiktok-bot",
35
+ "tiktok-data",
36
+ "tiktok-stream",
37
+ "tiktok-events",
38
+ "tiktok-viewer",
39
+ "live-streaming",
40
+ "live-chat",
41
+ "webcast",
42
+ "websocket",
43
+ "real-time",
44
+ "speech-to-text",
45
+ "captions",
46
+ "transcription",
47
+ "translation",
48
+ "tiktok-live-python",
49
+ "tiktok-tools",
50
+ "euler-stream",
51
+ "tiktoklive",
52
+ "tiktok-connector",
53
+ "tiktok-live-node",
54
+ "tiktok-live-js",
55
+ "tiktok-scraper",
56
+ "tiktok-monitoring",
57
+ "livestream-api"
58
+ ],
59
+ "author": {
60
+ "name": "TikTool",
61
+ "email": "support@tik.tools",
62
+ "url": "https://tik.tools"
63
+ },
64
+ "license": "MIT",
65
+ "repository": {
66
+ "type": "git",
67
+ "url": "https://github.com/tiktool/tiktok-live-api"
68
+ },
69
+ "bugs": {
70
+ "url": "https://github.com/tiktool/tiktok-live-api/issues"
71
+ },
72
+ "homepage": "https://tik.tools",
73
+ "dependencies": {
74
+ "ws": "^8.16.0"
75
+ },
76
+ "devDependencies": {
77
+ "@types/ws": "^8.5.10",
78
+ "tsup": "^8.0.0",
79
+ "typescript": "^5.3.0"
80
+ },
81
+ "engines": {
82
+ "node": ">=16.0.0"
83
+ }
84
+ }