Tutorial · TikTok · Node.js

Get TikTok transcripts with Node.js (TXT and SRT)

To download TikTok transcripts with Node.js, call /v1/tiktok/post/transcript for each link with the built-in fetch and write the text to a file. The script below also turns the timed segments into .srt subtitles and notes videos without captions.

Short answer. Run node tiktok-transcripts.mjs links.txt with HANDLEHAUL_API_KEY set, one link or video id per line. Each video gets transcripts/<id>.txt and .srt. 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.
  • Node.js 18 or newer, for the built-in fetch. No npm packages: the CSV is written by hand with proper quoting.
  • 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.mjs.

tiktok-transcripts.mjs
// Save the transcripts of a list of TikTok videos as .txt files (and .srt subtitles).
// Usage: node tiktok-transcripts.mjs links.txt   (one video link or id per line)
// Needs Node 18+ (built-in fetch) and HANDLEHAUL_API_KEY in the environment. No dependencies.
import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
import { join } from "node:path";

const API = "https://api.handlehaul.com";
const KEY = process.env.HANDLEHAUL_API_KEY;
if (!KEY) fail("Set HANDLEHAUL_API_KEY first, e.g. export HANDLEHAUL_API_KEY=kd_live_...");

function fail(message) {
  console.error(message);
  process.exit(1);
}

class ApiError extends Error {
  constructor(status, code, message) {
    super(`HTTP ${status} ${code}: ${message}`);
    this.status = status;
    this.code = code;
  }
}

const sleep = (seconds) => new Promise((resolve) => setTimeout(resolve, seconds * 1000));

// One API call. Waits and retries on 429 (honouring Retry-After) and on 502/503/504,
// throws ApiError for any other error. Failed calls and 429 answers are not charged.
async function get(path, params = {}) {
  const url = new URL(API + path);
  for (const [k, v] of Object.entries(params)) url.searchParams.set(k, v);
  for (let attempt = 0; ; attempt++) {
    const res = await fetch(url, { headers: { "X-Api-Key": KEY } });
    if ([429, 502, 503, 504].includes(res.status) && attempt < 5) {
      const wait = Number(res.headers.get("retry-after")) || 2 ** attempt;
      console.error(`  HTTP ${res.status}, retrying in ${wait}s`);
      await res.arrayBuffer();
      await sleep(wait);
      continue;
    }
    const body = await res.json().catch(() => ({}));
    if (res.ok) return body;
    const err = body.error ?? {};
    throw new ApiError(res.status, err.code ?? "unknown", err.message ?? res.statusText);
  }
}

const OUT_DIR = "transcripts";
const WRITE_SRT = true; // also write <video_id>.srt from the timed segments
const LANG = null;      // e.g. "en" or "es"; null = the video's original language
const SKIP = new Set(["user_not_found", "private_account"]); // note these and go on (failed calls are free)

const pad = (n, width = 2) => String(n).padStart(width, "0");
function srtTime(seconds) {
  let ms = Math.round(seconds * 1000);
  const h = Math.floor(ms / 3_600_000); ms %= 3_600_000;
  const m = Math.floor(ms / 60_000); ms %= 60_000;
  const s = Math.floor(ms / 1000); ms %= 1000;
  return `${pad(h)}:${pad(m)}:${pad(s)},${pad(ms, 3)}`;
}
const toSrt = (segments) => segments
  .map((seg, i) => `${i + 1}\n${srtTime(seg.start)} --> ${srtTime(seg.end)}\n${seg.text}\n`)
  .join("\n");

const file = process.argv[2];
if (!file) fail("Usage: node tiktok-transcripts.mjs links.txt");
const lines = readFileSync(file, "utf8").split(/\r?\n/).map((l) => l.trim());
const links = [...new Set(lines.filter((l) => l && !l.startsWith("#")))];
mkdirSync(OUT_DIR, { recursive: true });

let saved = 0, noCaptions = 0, failed = 0, credits = 0;
for (const link of links) {
  const params = /^\d+$/.test(link) ? { id: link } : { url: link };
  if (LANG) params.lang = LANG;
  let body;
  try {
    body = await get("/v1/tiktok/post/transcript", params);
  } catch (e) {
    if (!SKIP.has(e.code)) fail(`Stopped at ${link}: ${e.message}\n${saved} transcripts saved in ${OUT_DIR}/`);
    console.log(`${link}: ${e.code}`);
    failed++;
    continue;
  }
  const t = body.data;
  credits += body.meta.credits_charged ?? 0;
  if (!t.available) {
    // No captions (or not in LANG). Still 1 credit: the post had to be fetched to find out.
    console.log(`${link}: no captions (languages: ${(t.languages ?? []).join(", ") || "none"})`);
    noCaptions++;
    continue;
  }
  const base = join(OUT_DIR, t.video_id);
  writeFileSync(`${base}.txt`, t.text + "\n");
  if (WRITE_SRT && t.segments?.length) writeFileSync(`${base}.srt`, toSrt(t.segments));
  saved++;
  console.log(`${link}: ${t.text.length} characters (${t.language})`);
}
console.log(`Saved ${saved} transcripts to ${OUT_DIR}/, ${noCaptions} without captions, ` +
  `${failed} not found or private (${credits} credits)`);
Tested 2026-12-02 against the documented API responses on Node.js 26, using only Node 18 features. Run: node tiktok-transcripts.mjs 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. Check Node.js. Run node --version and make sure it is 18 or newer, for the built-in fetch. No npm packages are needed.
  4. Save the script as tiktok-transcripts.mjs. Copy the script above into tiktok-transcripts.mjs, and put your input in links.txt, one item per line.
  5. Run it. Run node tiktok-transcripts.mjs 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
node --version                  # v18 or newer
node tiktok-transcripts.mjs 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 JavaScript SDK (npm install handlehaul) does the paging, retries 429 for you and raises typed errors. The script above is the same job with every request visible.

Node SDK
// npm install handlehaul
import { HandleHaul } from "handlehaul";

const hh = new HandleHaul(); // reads HANDLEHAUL_API_KEY
const { data: t } = await hh.tiktok.transcriptByUrl({ url: "https://www.tiktok.com/@river_wren29/video/7300000000000000123" });
console.log(t.available ? t.text : "no captions");
Source and reference: handlehaul-js on GitHub.

Next steps

TikTok transcripts to text and SRT with Node.js: questions

How is the SRT file built?
Each segment has start and end in seconds. srtTime() turns them into HH:MM:SS,mmm and toSrt() numbers the blocks. Video editors and players load the file as subtitles.
Why does a video without captions still cost a credit?
The API has to fetch the post to find out that it has no captions. To avoid paying for those, check has_captions on /v1/tiktok/posts/{post} or /v1/tiktok/users/{user}/posts before asking for the transcript.
Can I run it in a serverless function?
Yes, as long as the runtime has Node 18+ and somewhere to write files. On platforms without a writable disk, return or upload t.text instead of calling writeFileSync. Keep the key in an environment variable, never in client code.
Is there a no-code way to try it first?
The free TikTok transcript tool runs the same endpoint for a few links a day in the browser, no key needed.

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.