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
requestspackage (pip install requests).csv,osand 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.
# 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()
python tiktok_transcripts.py links.txtRun it
- 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. - Set HANDLEHAUL_API_KEY. Export the key as the environment variable
HANDLEHAUL_API_KEYso it never sits in the code. - Install requests. Run
pip install requests. Python 3.9 or newer is required; everything else is in the standard library. - Save the script as tiktok_transcripts.py. Copy the script above into
tiktok_transcripts.py, and put your input inlinks.txt, one item per line. - 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:
https://www.tiktok.com/@river_wren29/video/7300000000000000123
7300000000000000456
export HANDLEHAUL_API_KEY=kd_live_... # your key from the dashboard
pip install requests
python tiktok_transcripts.py links.txt
$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.
| Job | Calls | Cost |
|---|---|---|
| 100 videos | 100 | $0.14 to $0.080 |
| 1,000 videos | 1,000 | $1.40 to $0.80 |
| 10,000 videos | 10,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.
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)
Hi, this is a sample caption. Post 0123 talks about coffee. Thanks for watching!
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.
| Status and code | When | What the script does |
|---|---|---|
404 | The video does not exist or was deleted | Prints the code and goes on. Free. |
403 private_account | The video belongs to a private account | Prints the code and goes on. Free. |
available: false | No captions, or none in LANG (HTTP 200) | Prints the languages that exist and goes on. 1 credit. |
401 invalid_api_key | The key is missing, wrong or revoked | Stops with the message. Check the variable with echo $HANDLEHAUL_API_KEY. |
402 insufficient_credits | The account is out of credits | Stops. Rows already fetched stay in the file. |
429 rate_limited | Too many requests per second | Waits for Retry-After and retries, up to 5 times. Not charged. |
502 / 503 / 504 | Data temporarily unavailable or slow | Retries 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.
# 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")
Next steps
- Get TikTok transcripts with Node.js (TXT and SRT): the same script in Node.js.
- TikTok transcript API: what the endpoint returns and how it compares.
- TikTok transcript API docs: every parameter, field and error.
- All tutorials: other jobs on Instagram and TikTok, in Python and Node.js.
TikTok transcripts to text and SRT with Python: questions
Does this transcribe the audio with Whisper?
Can I get transcripts for every video of an account?
/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?
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?
.txt files are plain text, one per video, named by video id. For summaries with timestamps, give the model the .srt file instead.Related
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.