> ## Documentation Index
> Fetch the complete documentation index at: https://tiktools.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Quick Start

> Connect to a TikTok Live stream and receive real-time events in under 30 seconds.

## 1. Get Your API Key

Sign up at [tik.tools](https://tik.tools) and get a free sandbox API key from the [dashboard](https://tik.tools/dashboard). No credit card required.

## 2. Install (Optional)

If using the Node.js SDK, install it via npm:

```bash theme={null}
npm install @tiktool/live
```

Or use the WebSocket directly - no SDK required. Any language with WebSocket support works.

## 3. Connect

<CodeGroup>
  ```javascript Node.js (SDK) theme={null}
  import { TikTokLive } from '@tiktool/live';

  const client = new TikTokLive({
    apiKey: 'YOUR_API_KEY',
    uniqueId: 'streamer_username',
  });

  client.on('chat', (event) => {
    console.log(`${event.user.uniqueId}: ${event.comment}`);
  });

  client.on('gift', (event) => {
    console.log(`${event.user.uniqueId} sent ${event.giftName} (${event.diamondCount}💎)`);
  });

  client.on('connected', () => console.log('Connected!'));

  await client.connect();
  ```

  ```javascript Node.js (WebSocket) theme={null}
  import WebSocket from 'ws';

  const ws = new WebSocket('wss://api.tik.tools?uniqueId=streamer_name&apiKey=YOUR_KEY');

  ws.on('open', () => console.log('Connected!'));

  ws.on('message', (raw) => {
    const { event, data } = JSON.parse(raw);
    switch (event) {
      case 'chat':     console.log(`💬 ${data.user.uniqueId}: ${data.comment}`); break;
      case 'gift':     console.log(`🎁 ${data.user.uniqueId} sent ${data.giftName}`); break;
      case 'like':     console.log(`❤️ ${data.user.uniqueId} liked × ${data.likeCount}`); break;
      case 'member':   console.log(`👋 ${data.user.uniqueId} joined`); break;
      case 'roomUserSeq': console.log(`👀 Viewers: ${data.viewerCount}`); break;
    }
  });

  ws.on('close', (code, reason) => console.log('Closed:', code, reason.toString()));
  ```

  ```python Python theme={null}
  import asyncio, websockets, json

  async def listen():
      url = "wss://api.tik.tools?uniqueId=streamer_name&apiKey=YOUR_KEY"
      async with websockets.connect(url) as ws:
          print("Connected!")
          async for message in ws:
              msg = json.loads(message)
              event = msg["event"]
              data = msg.get("data", {})
              user = data.get("user", {}).get("uniqueId", "")
              if event == "chat":        print(f"💬 {user}: {data.get('comment', '')}")
              elif event == "gift":      print(f"🎁 {user} sent {data.get('giftName', '')}")
              elif event == "like":      print(f"❤️ {user} liked × {data.get('likeCount', 0)}")
              elif event == "member":    print(f"👋 {user} joined")
              elif event == "roomUserSeq": print(f"👀 Viewers: {data.get('viewerCount', 0)}")

  asyncio.run(listen())
  ```

  ```bash cURL / wscat theme={null}
  # Install wscat for WebSocket testing:
  npm install -g wscat

  # Connect to a live stream:
  wscat -c "wss://api.tik.tools?uniqueId=streamer_name&apiKey=YOUR_KEY"

  # Or check if a user is live via REST:
  curl "https://api.tik.tools/webcast/check_alive?apiKey=YOUR_KEY&unique_id=streamer_name"
  ```

  ```java Java theme={null}
  import org.java_websocket.client.WebSocketClient;
  import org.java_websocket.handshake.ServerHandshake;
  import java.net.URI;

  var ws = new WebSocketClient(new URI("wss://api.tik.tools?uniqueId=streamer_name&apiKey=YOUR_KEY")) {
      public void onMessage(String msg) {
          var json = new org.json.JSONObject(msg);
          if (json.getString("event").equals("chat")) {
              var data = json.getJSONObject("data");
              System.out.println(data.getJSONObject("user").getString("uniqueId") + ": " + data.getString("comment"));
          }
      }
      public void onOpen(ServerHandshake h) { System.out.println("Connected!"); }
      public void onClose(int code, String reason, boolean remote) {}
      public void onError(Exception e) { e.printStackTrace(); }
  };
  ws.connect();
  ```

  ```go Go theme={null}
  package main

  import (
      "fmt"
      "log"
      "github.com/gorilla/websocket"
  )

  func main() {
      url := "wss://api.tik.tools?uniqueId=streamer_name&apiKey=YOUR_KEY"
      conn, _, err := websocket.DefaultDialer.Dial(url, nil)
      if err != nil { log.Fatal(err) }
      defer conn.Close()
      for {
          _, msg, err := conn.ReadMessage()
          if err != nil { break }
          fmt.Println(string(msg))
      }
  }
  ```

  ```csharp C# theme={null}
  using System.Net.WebSockets;
  using System.Text;
  using System.Text.Json;

  var ws = new ClientWebSocket();
  await ws.ConnectAsync(new Uri("wss://api.tik.tools?uniqueId=streamer_name&apiKey=YOUR_KEY"), CancellationToken.None);
  var buf = new byte[4096];
  while (ws.State == WebSocketState.Open) {
      var result = await ws.ReceiveAsync(buf, CancellationToken.None);
      var msg = Encoding.UTF8.GetString(buf, 0, result.Count);
      var json = JsonDocument.Parse(msg);
      if (json.RootElement.GetProperty("event").GetString() == "chat") {
          var data = json.RootElement.GetProperty("data");
          Console.WriteLine(data.GetProperty("user").GetProperty("uniqueId") + ": " + data.GetProperty("comment"));
      }
  }
  ```
</CodeGroup>

## 4. What's Next?

<CardGroup cols={2}>
  <Card title="WebSocket Events" icon="bolt" href="/websocket/events">
    See all 30+ event types you can receive.
  </Card>

  <Card title="REST API" icon="server" href="/rest-api/overview">
    Explore signing, room info, rankings, and more.
  </Card>

  <Card title="Live Captions" icon="closed-captioning" href="/captions/overview">
    Add real-time AI transcription to any stream.
  </Card>

  <Card title="Authentication" icon="key" href="/authentication">
    Learn about API keys and JWT tokens for frontend use.
  </Card>
</CardGroup>
