> ## 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.

# Fetch Events

> Fetch live stream events via HTTP long-polling. Returns the same real-time data as WebSocket (chat, gifts, likes, battles) but over HTTP. Uses TikTok's binary protobuf protocol and returns decoded eve

## `POST` `/webcast/fetch`

Fetch live stream events via HTTP long-polling. Returns the same real-time data as WebSocket (chat, gifts, likes, battles) but over HTTP. Uses TikTok's binary protobuf protocol and returns decoded events.

**How it works:** The API signs and fetches TikTok's internal polling endpoint, decodes the protobuf response, and returns structured event data. Pass a `cursor` from the previous response for continuous polling.

**Identification:** Provide either `unique_id` (username) or `room_id`. If using `unique_id`, the server resolves the room ID automatically.

**WebSocket vs Fetch:** WebSocket connections are preferred for real-time use - they deliver events instantly with lower latency. Use `/webcast/fetch` when WebSocket is not possible (serverless environments, HTTP-only infrastructure) or for one-off data snapshots.

### Parameters

| Parameter   | Type   | Required | Description                              |
| ----------- | ------ | -------- | ---------------------------------------- |
| `unique_id` | string | No       | TikTok username                          |
| `room_id`   | string | No       | Room ID (alternative to unique\_id)      |
| `cursor`    | string | No       | Pagination cursor from previous response |

### Response

```json theme={null}
{ "status_code": 0, "data": { "room_id": "...", "alive": true, "message_count": 5, "raw_data": "base64...", "cursor": "" } }
```

### Examples

<CodeGroup>
  ```javascript Node.js theme={null}
  const res = await fetch('https://api.tik.tools/webcast/fetch?apiKey=YOUR_KEY', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ unique_id: 'username' })
  });
  const { data } = await res.json();
  console.log(`Messages: ${data.message_count}`);
  ```

  ```python Python theme={null}
  import requests
  res = requests.post('https://api.tik.tools/webcast/fetch',
      params={'apiKey': 'YOUR_KEY'},
      json={'unique_id': 'username'})
  data = res.json()['data']
  print(f"Messages: {data['message_count']}")
  ```

  ```bash cURL theme={null}
  curl -X POST "https://api.tik.tools/webcast/fetch?apiKey=YOUR_KEY" \
    -H "Content-Type: application/json" \
    -d '{"unique_id": "username"}'
  ```

  ```java Java theme={null}
  HttpClient client = HttpClient.newHttpClient();
  String json = "{\"unique_id\": \"username\"}";
  HttpRequest req = HttpRequest.newBuilder()
      .uri(URI.create("https://api.tik.tools/webcast/fetch?apiKey=YOUR_KEY"))
      .header("Content-Type", "application/json")
      .POST(HttpRequest.BodyPublishers.ofString(json))
      .build();
  HttpResponse<String> res = client.send(req, HttpResponse.BodyHandlers.ofString());
  System.out.println(res.body());
  ```

  ```go Go theme={null}
  payload := bytes.NewBufferString(`{"unique_id":"username"}`)
  resp, err := http.Post(
      "https://api.tik.tools/webcast/fetch?apiKey=YOUR_KEY",
      "application/json", payload)
  if err != nil { log.Fatal(err) }
  defer resp.Body.Close()
  body, _ := io.ReadAll(resp.Body)
  fmt.Println(string(body))
  ```

  ```csharp C# theme={null}
  using var client = new HttpClient();
  var json = new StringContent(
      @"{""unique_id"":""username""}",
      Encoding.UTF8, "application/json");
  var res = await client.PostAsync(
      "https://api.tik.tools/webcast/fetch?apiKey=YOUR_KEY", json);
  Console.WriteLine(await res.Content.ReadAsStringAsync());
  ```
</CodeGroup>
