JavaScript and Node guide
fetch example.
Draft notice
Owner check needed: endpoint, parameter, limit and error names here come from the planning spec, not from the live service. Confirm them against the real API before launch.
Overview
Node 18 and later have fetch built in, so the call needs no packages.
- fetch, no packages.
- Key stays on the server.
const base = process.env.TTA_API_BASE ?? "https://api.example.com";
const url = new URL(`${base}/api/v1/tiktok/transcript`);
url.search = new URLSearchParams({ url: "https://www.tiktok.com/@gardenclub/video/7000000000000000001", lang: "en" });
const res = await fetch(url, { headers: { Authorization: `Bearer ${process.env.TTA_API_KEY}` } });
const data = await res.json();
if (!data.success) throw new Error(`${data.error.code}: ${data.error.message}`);
console.log(data.transcript_source, data.language_code, data.segments.length, "segments");
console.log(data.transcript);A minimal call
captions en 5 segments
Okay, three tips for a small garden. Tip one: measure the sun before you buy seeds. Tip two: raised beds drain better. Tip three: water in the morning. Follow for the full guide.Server side only
Keep the key in an environment variable on your server. Do not call this endpoint from browser code, because the key would be visible.
Errors
A failed call returns JSON with success: false. Throw on it and read error.code; see the error list.
Run against the local mock in tools/mock-api, which follows the assumed contract on these pages. It is not the real API, and the output is captured from that mock.
Ready to call it from your code?
Get API key