# TikTok Transcript API

> Turn a TikTok video into text: the transcript from its captions, with timed segments and the languages available, by video id or link. 1 credit per call, cached 24 hours.

**Get the transcript of a TikTok video** from its captions (most of them auto-generated by TikTok): the full text, timed segments and the caption languages available.

```
GET https://api.handlehaul.com/v1/tiktok/posts/{post}/transcript
GET https://api.handlehaul.com/v1/tiktok/post/transcript?url=
```

- `GET /v1/tiktok/posts/{post}/transcript`: by post id or URL-encoded link
- `GET /v1/tiktok/post/transcript?url=` (or `?id=`): the same, with the link in the query

**Cost:** 1 credit per successful call. **A video without captions still costs 1 credit** (we had to fetch the post to find out) and answers `available: false`. A transcript is kept 24 hours (1 hour when there were no captions yet, since TikTok can add them shortly after upload); repeats from cache are free.

## Parameters

| Parameter | In | Description |
|---|---|---|
| `post` | path | Post id or URL-encoded tiktok.com video link. |
| `url` / `id` | query | Alias route only: the video link, or its id. |
| `lang` | query | Optional caption language code (`en`, `es`…). Default: the video's original language. |
| `fresh` | query | `true` skips the cache. |

## Response

```json
{
  "data": {
    "video_id": "7300000000000000123",
    "available": true,
    "language": "en",
    "languages": [
      "en"
    ],
    "is_auto_generated": true,
    "text": "Hi, this is a sample caption. Post 0123 talks about coffee. Thanks for watching!",
    "segments": [
      {
        "start": 0,
        "end": 1.58,
        "text": "Hi, this is a sample caption."
      },
      {
        "start": 1.581,
        "end": 3.421,
        "text": "Post 0123 talks about coffee."
      },
      {
        "start": 3.422,
        "end": 5,
        "text": "Thanks for watching!"
      }
    ]
  },
  "meta": {
    "request_id": "req_…",
    "cached": false,
    "cache_age_seconds": 0,
    "credits_charged": 1,
    "credits_remaining": 26943
  }
}
```

- `start` and `end` are seconds from the start of the video.
- `languages` lists every caption language the video has; ask for one with `lang`. If that language is missing, `available` is `false` and `languages` shows what exists.
- Photo posts and videos without speech usually have no captions. `has_captions` on any post tells you in advance.

## Examples

```bash
curl "https://api.handlehaul.com/v1/tiktok/posts/7300000000000000123/transcript" -H "X-Api-Key: $HANDLEHAUL_API_KEY"
```

```python
import os, requests
r = requests.get("https://api.handlehaul.com/v1/tiktok/posts/7300000000000000123/transcript",
                 headers={"X-Api-Key": os.environ["HANDLEHAUL_API_KEY"]}, timeout=60)
r.raise_for_status()
t = r.json()["data"]
print(t["text"] if t["available"] else "no captions")
```

```javascript
const res = await fetch("https://api.handlehaul.com/v1/tiktok/posts/7300000000000000123/transcript", {
  headers: { "X-Api-Key": process.env.HANDLEHAUL_API_KEY },
});
const { data, meta } = await res.json();
```

```php
$ch = curl_init("https://api.handlehaul.com/v1/tiktok/posts/7300000000000000123/transcript");
curl_setopt_array($ch, [
    CURLOPT_HTTPHEADER => ["X-Api-Key: " . getenv("HANDLEHAUL_API_KEY")],
    CURLOPT_RETURNTRANSFER => true,
]);
$body = json_decode(curl_exec($ch), true);
print_r($body["data"]);
```

```go
req, _ := http.NewRequest("GET", "https://api.handlehaul.com/v1/tiktok/posts/7300000000000000123/transcript", nil)
req.Header.Set("X-Api-Key", os.Getenv("HANDLEHAUL_API_KEY"))
res, err := http.DefaultClient.Do(req)
if err != nil {
    log.Fatal(err)
}
defer res.Body.Close()
var body map[string]any
json.NewDecoder(res.Body).Decode(&body)
fmt.Println(body["data"])
```

## FAQ

### How do I get the text of a TikTok video?
Call `GET /v1/tiktok/post/transcript?url=<the TikTok link>`. `data.text` is the full transcript and `data.segments` the timed lines.

### Is this speech recognition?
No: we read the captions TikTok publishes for the video. When TikTok has none, `available` is `false`.
