2026-11-23 · 5 min read
How to Caption Videos with Supabase Edge Functions
If your app already stores uploads in Supabase Storage or tracks them in a table, an Edge Function is the natural place to caption them. The caption.sh API is plain HTTPS, so a function can submit a job with fetch and no extra dependencies.
Submit on upload
A database webhook or a storage trigger can call a function that posts the video URL to the API. Documented styling options ride in the nested options object.
Deno.serve(async (req) => {
const { videoUrl } = await req.json();
const res = await fetch("https://api.caption.sh/v1/videos", {
method: "POST",
headers: {
Authorization: "Bearer " + Deno.env.get("CAPTION_API_KEY"),
"Content-Type": "application/json",
},
body: JSON.stringify({
source_url: videoUrl,
options: { caps: true, position: "bottom" },
}),
});
const job = await res.json();
// store job.job_id on the row so the poller can find it
return Response.json({ job_id: job.job_id });
});Keep the API key in the function's secrets, not in code. One job covers a video up to 10 minutes long; split longer files into segments first.
Poll on a schedule, not in the request
Jobs move through queued, awaiting_upload, running, then done or error. Rather than holding the original request open, run a scheduled function that checks open jobs and updates their rows. Cover three exits per job: done, error, or a timeout you choose.
async function check(jobId: string) {
const st = await fetch("https://api.caption.sh/v1/jobs/" + jobId, {
headers: { Authorization: "Bearer " + Deno.env.get("CAPTION_API_KEY") },
}).then((r) => r.json());
if (st.status !== "done") return st.status;
const out = await fetch(
"https://api.caption.sh/v1/jobs/" + jobId + "/result",
{ headers: { Authorization: "Bearer " +
Deno.env.get("CAPTION_API_KEY") }, redirect: "manual" }
);
return out.headers.get("Location");
}The result endpoint answers with a redirect, so use redirect: "manual" and read the Location header. Results are stored for 24 hours, then deleted; copy the file into Supabase Storage as soon as the job completes.
Cost and limits
- A 429 means the transcription throughput ceiling is saturated; wait and retry on the next scheduled run.
- Pricing is prepaid at $0.10 per minute of video, so a 2 minute clip costs twenty cents.
- Keep a submitted_at timestamp on the row so stale jobs can be timed out cleanly.
Burned-in captions cannot be toggled, resized, or translated by the viewer. If your audience needs adjustable captions, keep the platform's own caption track enabled alongside the burn-in.