2026-11-26 · 5 min read

How to Caption Videos in Laravel

Dark film strip with the glowing red neon caption word LARAVEL on a black background.
This image was generated with AI.

Laravel's HTTP client is a fluent wrapper around Guzzle, which makes the caption.sh API a three-call integration: submit, poll, download. No package to install.

Submit the job

POST the video URL to the API. Documented styling options go in the nested options object, and the key lives in .env as CAPTION_API_KEY.

use Illuminate\Support\Facades\Http;

$response = Http::withHeaders([
    'Authorization' => 'Bearer ' . config('services.caption.key'),
])->post('https://api.caption.sh/v1/videos', [
    'source_url' => $request->input('url'),
    'options' => [
        'position' => 'bottom',
        'highlight' => true,
    ],
]);

$jobId = $response->json('job_id');

Poll until done

Jobs move through queued, running, and done. A queued Laravel job that re-dispatches itself every few seconds is the tidy way to poll, but a plain loop works for a command or a synchronous demo.

use Illuminate\Support\Facades\Http;

$deadline = now()->addMinutes(12);
while (now()->lt($deadline)) {
    $job = Http::withHeaders([
        'Authorization' => 'Bearer ' . config('services.caption.key'),
    ])->get("https://api.caption.sh/v1/jobs/{$jobId}")->json();

    if ($job['status'] === 'done') break;
    if ($job['status'] === 'error') throw new RuntimeException('caption job failed');
    sleep(5);
}

When the status is done, GET /v1/jobs/{id}/result answers with a 302 redirect to the finished MP4. Tell the client not to follow redirects and read the Location header yourself:

$result = Http::withOptions(['allow_redirects' => false])
    ->withHeaders(['Authorization' => 'Bearer ' . config('services.caption.key')])
    ->get("https://api.caption.sh/v1/jobs/{$jobId}/result");

$downloadUrl = $result->header('Location');

Results are stored for 24 hours, then deleted, so copy the file to your own disk or S3 right away.

Cost and limits

Captioning costs $0.10 per minute of video, prepaid. A single job can be up to 10 minutes long, so clip longer videos first. If you hit a 429, the transcription throughput ceiling is full: wait and retry.

Back to all articles