Tutorial · TikTok · Python

Get TikTok transcripts with Python (TXT and SRT)

To get TikTok transcripts in Python, send each video link to /v1/tiktok/post/transcript with requests and save data.text. The script below handles a whole list, writes a .txt and an .srt file per video, and reports videos that have no captions.

Short answer. Put one TikTok link or video id per line in links.txt, set HANDLEHAUL_API_KEY and run python tiktok_transcripts.py links.txt. Transcripts land in transcripts/. One call per video: 1,000 videos cost $1.40 to $0.80; re-runs within 24 hours are free.

Facts checked 2 December 2026. Prices change: follow the links before you decide.

What you need

  • An API key. Sign up and create one in the dashboard. A sandbox key (kd_test_) returns sample data for free, so you can run the script before you spend anything.
  • Python 3.9 or newer and the requests package (pip install requests). csv, os and the rest come with Python.
  • The key in HANDLEHAUL_API_KEY. The script reads it from the environment, so the key never sits in your code or your repository.
  • Public TikTok videos. The API returns public data only: no logins, no private accounts, no DMs.

The script

It calls GET /v1/tiktok/post/transcript (see the TikTok transcript API docs), retries on 429 using Retry-After, and stops with a clear message on any other error. Save it as tiktok_transcripts.py.

tiktok_transcripts.py
# Save the transcripts of a list of TikTok videos as .txt files (and .srt subtitles).
# Usage: python tiktok_transcripts.py links.txt   (one video link or id per line)
# Needs Python 3.9+, the requests package and HANDLEHAUL_API_KEY in the environment.
import os
import sys
import time

import requests

API = "https://api.handlehaul.com"
KEY = os.environ.get("HANDLEHAUL_API_KEY")
if not KEY:
    sys.exit("Set HANDLEHAUL_API_KEY first, e.g. export HANDLEHAUL_API_KEY=kd_live_...")

session = requests.Session()
session.headers["X-Api-Key"] = KEY


class ApiError(Exception):
    def __init__(self, status, code, message):
        super().__init__(f"HTTP {status} {code}: {message}")
        self.status = status
        self.code = code


def get(path, params=None):
    # One API call. Waits and retries on 429 (honouring Retry-After) and on 502/503/504,
    # raises ApiError for any other error. Failed calls and 429 answers are not charged.
    for attempt in range(6):
        r = session.get(API + path, params=params, timeout=60)
        if r.status_code in (429, 502, 503, 504) and attempt < 5:
            try:
                wait = float(r.headers.get("Retry-After", ""))
            except ValueError:
                wait = 2 ** attempt
            print(f"  HTTP {r.status_code}, retrying in {wait:g}s", file=sys.stderr)
            time.sleep(wait)
            continue
        try:
            body = r.json()
        except ValueError:
            body = {}
        if r.ok:
            return body
        err = body.get("error") or {}
        raise ApiError(r.status_code, err.get("code", "unknown"), err.get("message", r.text[:200]))


OUT_DIR = "transcripts"
WRITE_SRT = True  # also write <video_id>.srt from the timed segments
LANG = None       # e.g. "en" or "es"; None = the video's original language
SKIP = {"user_not_found", "private_account"}  # note these and go on (failed calls are free)


def srt_time(seconds):
    ms = int(round(seconds * 1000))
    h, ms = divmod(ms, 3_600_000)
    m, ms = divmod(ms, 60_000)
    s, ms = divmod(ms, 1000)
    return f"{h:02}:{m:02}:{s:02},{ms:03}"


def to_srt(segments):
    blocks = []
    for i, seg in enumerate(segments, 1):
        blocks.append(f"{i}\n{srt_time(seg['start'])} --> {srt_time(seg['end'])}\n{seg['text']}\n")
    return "\n".join(blocks)


def main():
    if len(sys.argv) < 2:
        sys.exit("Usage: python tiktok_transcripts.py links.txt")
    with open(sys.argv[1], encoding="utf-8") as f:
        links = list(dict.fromkeys(line.strip() for line in f if line.strip() and not line.startswith("#")))
    os.makedirs(OUT_DIR, exist_ok=True)

    saved, no_captions, failed, credits = 0, 0, 0, 0
    for link in links:
        params = {"id": link} if link.isdigit() else {"url": link}
        if LANG:
            params["lang"] = LANG
        try:
            body = get("/v1/tiktok/post/transcript", params)
        except ApiError as e:
            if e.code not in SKIP:
                sys.exit(f"Stopped at {link}: {e}\n{saved} transcripts saved in {OUT_DIR}/")
            print(f"{link}: {e.code}")
            failed += 1
            continue
        except requests.RequestException as e:
            sys.exit(f"Stopped at {link}: {e}\n{saved} transcripts saved in {OUT_DIR}/")
        t = body["data"]
        credits += body["meta"].get("credits_charged", 0)
        if not t["available"]:
            # No captions (or not in LANG). Still 1 credit: the post had to be fetched to find out.
            print(f"{link}: no captions (languages: {', '.join(t.get('languages') or []) or 'none'})")
            no_captions += 1
            continue
        base = os.path.join(OUT_DIR, t["video_id"])
        with open(base + ".txt", "w", encoding="utf-8") as f:
            f.write(t["text"] + "\n")
        if WRITE_SRT and t.get("segments"):
            with open(base + ".srt", "w", encoding="utf-8") as f:
                f.write(to_srt(t["segments"]))
        saved += 1
        print(f"{link}: {len(t['text'])} characters ({t['language']})")

    print(f"Saved {saved} transcripts to {OUT_DIR}/, {no_captions} without captions, "
          f"{failed} not found or private ({credits:g} credits)")


if __name__ == "__main__":
    main()
Tested 2026-12-02 against the documented API responses on Python 3.9.6. Run: python tiktok_transcripts.py links.txt

Run it

  1. Get an API key. Sign up at api.handlehaul.com/signup and create a key. A sandbox key (kd_test_) returns sample data for free while you test.
  2. Set HANDLEHAUL_API_KEY. Export the key as the environment variable HANDLEHAUL_API_KEY so it never sits in the code.
  3. Install requests. Run pip install requests. Python 3.9 or newer is required; everything else is in the standard library.
  4. Save the script as tiktok_transcripts.py. Copy the script above into tiktok_transcripts.py, and put your input in links.txt, one item per line.
  5. Run it. Run python tiktok_transcripts.py links.txt. Progress prints as it goes; the output file is written as rows arrive, so an interrupted run keeps what it fetched.

Example links.txt:

links.txt
https://www.tiktok.com/@river_wren29/video/7300000000000000123
7300000000000000456
Terminal
export HANDLEHAUL_API_KEY=kd_live_...   # your key from the dashboard
pip install requests
python tiktok_transcripts.py links.txt
On Windows PowerShell, set the key with $env:HANDLEHAUL_API_KEY="kd_live_...".

How it works

One call per video. The script calls /v1/tiktok/post/transcript with ?url= for a link or ?id= for a bare video id, and writes data.text to transcripts/<video_id>.txt.

No captions. When data.available is false, the video has no captions (or none in the language you asked for) and data.languages lists what exists. That call still costs 1 credit, because the post had to be fetched to find out. Photo posts and videos without speech usually have none.

Where the text comes from. It is the caption track TikTok publishes for the video, most of it auto-generated (is_auto_generated). It is not our own speech recognition, so it matches what viewers see.

SRT subtitles. Each segment has start and end in seconds from the start of the video. The script turns them into numbered SRT blocks with HH:MM:SS,mmm times. Set WRITE_SRT to false to skip them.

Language. Leave LANG empty for the video’s original language, or set a code such as en or es.

Repeats are free. A transcript is kept 24 hours (1 hour when there were no captions yet, since TikTok can add them shortly after upload), so re-running the same list is free within that window.

What it costs

Every successful call is 1 credit, at $1.40 to $0.80 per 1,000 calls. One call per video, with or without captions. Links that do not exist and answers from the cache are free. To skip videos without captions before paying, check has_captions on the post or posts endpoints first.

Calls and cost for tiktok transcripts to text and srt
JobCallsCost
100 videos100$0.14 to $0.080
1,000 videos1,000$1.40 to $0.80
10,000 videos10,000$14.00 to $8.00

The script makes one call at a time, well under the account limit of 10 to 30 requests per second. Each response says what it cost in meta.credits_charged, and the script adds those up in its last line.

Sample output

An example run with example values, not a real export. Field names and shapes are the ones in the API docs.

Terminal
https://www.tiktok.com/@river_wren29/video/7300000000000000123: 80 characters (en)
7300000000000000456: no captions (languages: none)
Saved 1 transcripts to transcripts/, 1 without captions, 0 not found or private (2 credits)
transcripts/7300000000000000123.txt
Hi, this is a sample caption. Post 0123 talks about coffee. Thanks for watching!
transcripts/7300000000000000123.srt
1
00:00:00,000 --> 00:00:01,580
Hi, this is a sample caption.

2
00:00:01,581 --> 00:00:03,421
Post 0123 talks about coffee.

3
00:00:03,422 --> 00:00:05,000
Thanks for watching!

Common errors

Errors come back as { "error": { "code", "message", "request_id" } } with an HTTP status. Failed calls are never charged. Full list: error codes.

Errors this script can meet and what it does
Status and codeWhenWhat the script does
404The video does not exist or was deletedPrints the code and goes on. Free.
403 private_accountThe video belongs to a private accountPrints the code and goes on. Free.
available: falseNo captions, or none in LANG (HTTP 200)Prints the languages that exist and goes on. 1 credit.
401 invalid_api_keyThe key is missing, wrong or revokedStops with the message. Check the variable with echo $HANDLEHAUL_API_KEY.
402 insufficient_creditsThe account is out of creditsStops. Rows already fetched stay in the file.
429 rate_limitedToo many requests per secondWaits for Retry-After and retries, up to 5 times. Not charged.
502 / 503 / 504Data temporarily unavailable or slowRetries with a growing wait (1, 2, 4, 8, 16 s). Failed calls are free.

The same job with the SDK

If you would rather not maintain the HTTP code, the official Python SDK (pip install handlehaul) does the paging, retries 429 for you and raises typed errors. The script above is the same job with every request visible.

Python SDK
# pip install handlehaul
from handlehaul import HandleHaul

hh = HandleHaul()  # reads HANDLEHAUL_API_KEY
t = hh.tiktok.transcript_by_url(url="https://www.tiktok.com/@river_wren29/video/7300000000000000123").data
print(t["text"] if t["available"] else "no captions")
Source and reference: handlehaul-python on GitHub.

Next steps

TikTok transcripts to text and SRT with Python: questions

Does this transcribe the audio with Whisper?
No. It reads the caption track TikTok publishes for the video, most of it auto-generated by TikTok. Nothing is downloaded or run on your machine. If a video has no captions, run speech recognition on it yourself.
Can I get transcripts for every video of an account?
Yes, in two steps: list the account’s videos with /v1/tiktok/users/{user}/posts, keep those with has_captions true, and write their links to links.txt. That way you do not pay for videos without captions.
How do I get the transcript in another language?
Set LANG = "es" (or any code). If the video has no captions in that language, available is false and the script prints the languages it does have.
Can I feed the transcripts to an LLM?
Yes. The .txt files are plain text, one per video, named by video id. For summaries with timestamps, give the model the .srt file instead.

Run it on your own list

One key for Instagram and TikTok. $1.40 to $0.80 per 1,000 calls; failed calls are free.

Want to test first? Sandbox keys are free and unlimited, with sample data in the live schema.