November 9, 2026 · 4 min read
How to Get YouTube Transcripts in PHP (and Laravel)
In short
Fetch any YouTube video's transcript in PHP with cURL or Laravel's HTTP client: timestamped JSON, SRT and VTT files, translation, and error handling.
PHP has no maintained library for reading YouTube captions, and scraping YouTube from a web host usually gets blocked. One HTTPS request to the TranscriptYT YouTube Transcript API returns the transcript as JSON, text, or a subtitle file, from plain PHP or Laravel.
Fetch a transcript with cURL
Create a free key in the dashboard (100 transcripts, no card) and keep it in an environment variable. Pass any YouTube URL or a bare video ID.
<?php
$query = http_build_query(['url' => 'https://youtu.be/5f3Pn-N6yLc']);
$ch = curl_init("https://transcript-yt.com/v1/transcript?$query");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('TRANSCRIPTYT_KEY')],
CURLOPT_TIMEOUT => 120,
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
$data = json_decode($body, true);
if ($status !== 200) {
throw new RuntimeException($data['error']['code'] . ': ' . $data['error']['message']);
}
echo $data['title'], PHP_EOL;
foreach (array_slice($data['segments'], 0, 3) as $seg) {
printf("%7.1fs %s\n", $seg['start'], $seg['text']);
}Laravel
Laravel's HTTP client keeps it to one call. Put the key in .env as TRANSCRIPTYT_KEY and read it through config in production.
use Illuminate\Support\Facades\Http;
$data = Http::withToken(env('TRANSCRIPTYT_KEY'))
->timeout(120)
->get('https://transcript-yt.com/v1/transcript', ['url' => '5f3Pn-N6yLc'])
->throw()
->json();
$text = collect($data['segments'])->pluck('text')->implode(' ');Subtitle files and translation
Set format to srt, vtt, text, csv, or md to get the file body directly. Add translate_to with a language code to translate any track into one of 150+ languages with the timings kept.
$srt = Http::withToken(env('TRANSCRIPTYT_KEY'))
->get('https://transcript-yt.com/v1/transcript', [
'url' => '5f3Pn-N6yLc',
'format' => 'srt',
'translate_to' => 'es',
])
->throw()
->body();
file_put_contents('captions.es.srt', $srt);Errors
Errors use one envelope, {"error": {"code", "message"}}. Retry BLOCKED, RATE_LIMITED, and UPSTREAM_ERROR with backoff; VIDEO_UNAVAILABLE, NO_CAPTIONS, and LANGUAGE_NOT_AVAILABLE are final. Failed requests are never billed. The full list is in the docs.
Common questions
How do I get a YouTube transcript in PHP?
Send a GET request to https://transcript-yt.com/v1/transcript with the video URL as the url parameter and your API key in the Authorization header. The JSON response has the title, language, and timestamped segments.
Does it work on shared hosting?
Yes. It only needs outbound HTTPS and the cURL extension, which almost every PHP host has. Your server never contacts YouTube, so datacenter IP blocks don't apply.
Can I get SRT subtitles in PHP?
Yes. Add format=srt (or vtt, text, csv, md) and write the response body to a file.