Video transcription pipeline
Turn YouTube, TikTok and Instagram video links into plain-text transcripts with one function, and know what each one costs
This recipe takes a list of video links from YouTube, TikTok and Instagram and returns what is said in each one as plain text, ready to search, summarise or feed to an AI model. Each platform has its own transcript route and returns the words in its own shape, so the code below calls the right route for each link and turns every answer into the same row.
For a one-off transcript you don't need any code: paste the link into the free YouTube, TikTok or Instagram Reel transcript tool. Use this recipe when you have many videos, or want the text in your own app or database.
What you'll need
- An API key. The Quickstart shows how to create one.
- The TypeScript SDK:
npm install @socialfetch/sdk. - Links to public videos. Private accounts and deleted posts come back as
not_found.
What it costs
| Platform | Cost |
|---|---|
| YouTube | 5 credits when a transcript comes back. Free when the video has no readable captions, isn't found or the lookup fails. |
| TikTok | 5 credits for each completed lookup, including a video that isn't found or has no captions. With useAiFallback=true, a video with no captions is transcribed by AI for 10 more credits (15 in total), charged only when AI produced the text. |
| 5 credits for each completed lookup, found or not found. AI transcription is included. |
AI transcription covers videos up to 2 minutes by default. Longer videos cost more; see Long videos.
Lookups that fail on our side (502 lookup_failed, 503 temporarily_unavailable) cost nothing. See Credits for the full rules, and check your balance with the free GET /v1/balance before a large batch.
Try one video first
Open the Playground, pick YouTube, then Transcript, paste a video link into url and click Send. Do the same with a TikTok and an Instagram video to see how differently the three answers are laid out.

TikTok returns captions as a WebVTT file: the text broken into cues, each with a start and end time. A video with no caption track comes back found with transcript: null, unless you set useAiFallback to true.

Instagram returns plain text with no timings. The media field takes the post or Reel link, its shortcode (the part after /reel/) or the numeric media id. Share links (instagram.com/share/...) are refused with a 400.

The routes
| Platform | Route | SDK method | Where the words are |
|---|---|---|---|
| YouTube | GET /v1/youtube/videos/transcript | client.youtube.getVideoTranscript({ url }) | data.transcript.plainText, and timed segments |
| TikTok | GET /v1/tiktok/videos/transcript | client.tiktok.getVideoTranscript({ url, useAiFallback, allowLongTranscription }) | data.transcript.content, as WebVTT or plain text |
GET /v2/instagram/media/{media}/transcript | client.instagram.getMediaTranscriptV2({ media }) | data.transcript.text |
The same pattern works for X posts, Facebook posts, Reddit posts and LinkedIn posts with video.
Long videos
Long mode (allowLongTranscription=true) costs 5 credits plus 10 credits for each started minute when AI produces text, including short clips, with billing capped at 60 minutes (605 credits). Keep at least 605 credits available for a long-mode request's preflight check. TikTok also requires useAiFallback=true; caption reads and empty results stay at 5 credits. Instagram with no transcript also stays at 5 credits.
The SDK's getMediaTranscriptV2({ media }) currently sends no query parameters, so it cannot opt into long transcription. The worker below handles Instagram videos up to the default 2-minute AI limit. For a longer Instagram video, call the HTTP route directly:
curl --get 'https://api.socialfetch.dev/v2/instagram/media/DKuRMDEsbYB/transcript' \
--header "x-api-key: $SOCIALFETCH_API_KEY" \
--data-urlencode 'allowLongTranscription=true'Replace DKuRMDEsbYB with your video's shortcode and set SOCIALFETCH_API_KEY to your key. This example uses the same public Reel as the screenshots; long-mode pricing applies even to that short clip. The response still puts the words in data.transcript.text and the charge in meta.creditsCharged.
Transcribe a link
transcribe() works out the platform from the link, calls its transcript route and returns one row with the text in the same place, whatever the platform. TikTok's WebVTT is turned into plain text by dropping the header and the timing lines. For long TikTok AI transcription, pass { useAiFallback: true, allowLongTranscription: true } as the second argument. These options affect TikTok only; use the HTTP request above for long Instagram videos.
import { SocialFetchClient } from "@socialfetch/sdk";
const client = new SocialFetchClient({
apiKey: process.env.SOCIALFETCH_API_KEY!,
});
type Platform = "youtube" | "tiktok" | "instagram";
export type TranscriptRow = {
platform: Platform;
url: string;
lookupStatus: string;
text: string | null; // null when the video has no transcript
language: string | null;
creditsCharged: number;
requestId: string;
};
function detectPlatform(url: string): Platform | null {
const host = new URL(url).hostname.replace(/^(www|m)\./, "");
if (host === "youtube.com" || host === "youtu.be") return "youtube";
if (host === "tiktok.com" || host.endsWith(".tiktok.com")) return "tiktok";
if (host === "instagram.com") return "instagram";
return null;
}
// WebVTT to plain text: drop the "WEBVTT" header, the timings and blank lines.
function webvttToText(vtt: string): string {
return vtt
.split("\n")
.map((line) => line.trim())
.filter((line) => line && line !== "WEBVTT" && !line.includes("-->"))
.join(" ");
}
// What every successful response has in common.
type Envelope = {
data: { lookupStatus: string };
meta: { requestId: string; creditsCharged: number };
};
function row(
platform: Platform,
url: string,
value: Envelope,
text: string | null | undefined,
language: string | null | undefined,
): TranscriptRow {
return {
platform,
url,
lookupStatus: value.data.lookupStatus,
text: text?.replace(/\s+/g, " ").trim() || null,
language: language ?? null,
creditsCharged: value.meta.creditsCharged,
requestId: value.meta.requestId,
};
}
export async function transcribe(
url: string,
{ useAiFallback = false, allowLongTranscription = false } = {},
): Promise<TranscriptRow> {
const platform = detectPlatform(url);
if (!platform) throw new Error(`Not a YouTube, TikTok or Instagram link: ${url}`);
if (platform === "youtube") {
const r = await client.youtube.getVideoTranscript({ url });
if (!r.ok) throw r.error;
const t = r.value.data.transcript;
return row(platform, url, r.value, t?.plainText, t?.languageCode);
}
if (platform === "tiktok") {
const r = await client.tiktok.getVideoTranscript({ url, useAiFallback, allowLongTranscription });
if (!r.ok) throw r.error;
const t = r.value.data.transcript;
const text = t?.format === "webvtt" ? webvttToText(t.content) : t?.content;
return row(platform, url, r.value, text, null);
}
const r = await client.instagram.getMediaTranscriptV2({ media: url });
if (!r.ok) throw r.error;
const t = r.value.data.transcript;
return row(platform, url, r.value, t?.text, t?.language);
}A failed request throws the SDK's error, which has a code such as insufficient_credits or temporarily_unavailable and a requestId to quote to support. Errors lists what each code means.
Run it
Call transcribe() once for each link. This loop runs one video at a time. You can run several at once for a long list; if you send too many, the API answers 503 temporarily_unavailable with a Retry-After header, which costs nothing, so wait and try that video again.
const videos = [
{ url: "https://www.youtube.com/watch?v=3H74qlwh5tY" },
{ url: "https://www.tiktok.com/@duolingo/video/7514320905909194030" },
{ url: "https://www.instagram.com/reel/DKuRMDEsbYB/" },
// This TikTok has no captions, so let AI transcribe it.
{ url: "https://www.tiktok.com/@duolingo/video/7695766121307196686", useAiFallback: true },
];
async function main() {
const rows: TranscriptRow[] = [];
for (const { url, useAiFallback } of videos) {
rows.push(await transcribe(url, { useAiFallback }));
}
console.table(rows);
}
main();Save the worker and loop TypeScript blocks as transcribe.ts and run it with your key in SOCIALFETCH_API_KEY, for example with npx tsx transcribe.ts. A real run on four public Duolingo videos returned four rows of the same shape. The chess announcement is on both TikTok and Instagram, so the two rows hold the same words:

Each request also appears in Usage, then Request history in the app, with what it cost. Type transcript in Path contains to see only transcript lookups.

When there's no text
A row with text: null is a video with nothing to read, and lookupStatus says why:
foundwith no text: the video exists but has no transcript. On YouTube it has no readable captions (and costs nothing). On TikTok it has no caption track: run it again withuseAiFallback: true. On Instagram the video has no speech.not_found: the video doesn't exist, was deleted or is on a private account. On Instagram, a photo post with no video is alsonot_found.lookup_failed(YouTube only): the lookup couldn't be completed. It's free, so try again later.
A TikTok photo post is refused with 400 transcript_target_not_video, which costs 5 credits. A TikTok video with no captions, or an Instagram video, over the AI limit without allowLongTranscription is refused with 400 video_too_long_for_transcription, which is free.
Store it for search or AI
- Store
textfor search and for embeddings. Split long transcripts into overlapping chunks, and keepurl,platformandlanguagewith each chunk so an answer can link back to the video. - Keep YouTube's
segmentsor TikTok's WebVTT as well if you want to link to the moment something is said. - Store
requestIdandcreditsChargedto reconcile what you spent with the request log.
For more on each platform's transcripts, see the guide How to get YouTube, TikTok and Instagram transcripts. If you'd rather ask in plain English than pick a route, POST /v1/ask sends the question to the right lookup. AI assistants can call the same transcript routes through MCP.
Competitor profile tracking
Look up a competitor's profile on TikTok, Instagram, YouTube and X, store each platform's lookupStatus and follower count, and compare snapshots over time
Facebook Ad Library aggregation
Search Meta's Ad Library by keyword, find an advertiser's page and list its ads, page through results and fetch one ad, with the Playground and the TypeScript SDK.