2026-11-21 · 4 min read

How to Caption Videos with Google Apps Script

AI-generated hero image: a dark 35mm film strip with the word SCRIPT glowing in green neon at the center.
This image was generated with AI.

If your workflow already lives in Google Sheets or Drive, Google Apps Script is a handy place to caption videos. You do not need to deploy anything: UrlFetchApp can call the caption.sh API directly from a script bound to a spreadsheet, a Doc, or a standalone project.

Submit the caption job

Send a POST to the API with your video URL. Any documented styling options go in the nested options object.

function submitCaptionJob() {
  var apiKey = "YOUR_API_KEY";
  var res = UrlFetchApp.fetch("https://api.caption.sh/v1/videos", {
    method: "post",
    contentType: "application/json",
    headers: { Authorization: "Bearer " + apiKey },
    payload: JSON.stringify({
      source_url: "https://example.com/clip.mp4",
      options: { caps: true, position: "bottom", max_lines: 2 }
    }),
    muteHttpExceptions: true
  });
  var job = JSON.parse(res.getContentText());
  return job.job_id;
}

The response gives you a job_id. Note that a single video can be up to 10 minutes long; for anything longer, split it into segments first and caption each segment as its own job.

Poll until it is done

Apps Script has no background workers, so poll on a bounded loop with Utilities.sleep. Give the loop three exits: done, error, or a timeout you choose.

function waitForJob(jobId) {
  var apiKey = "YOUR_API_KEY";
  var deadline = Date.now() + 12 * 60 * 1000;
  while (Date.now() < deadline) {
    Utilities.sleep(15000);
    var st = JSON.parse(UrlFetchApp.fetch(
      "https://api.caption.sh/v1/jobs/" + jobId,
      { headers: { Authorization: "Bearer " + apiKey } }
    ).getContentText());
    if (st.status === "done") return true;
    if (st.status === "error") throw new Error("caption job failed");
  }
  throw new Error("timed out waiting for job " + jobId);
}

If you hit a 429 while polling or submitting, you have hit the transcription throughput ceiling. Wait a bit and retry; it clears on its own.

Download the result

The result endpoint replies with a redirect to the finished file, so tell UrlFetchApp not to follow it and read the Location header yourself.

function getResultUrl(jobId) {
  var apiKey = "YOUR_API_KEY";
  var res = UrlFetchApp.fetch(
    "https://api.caption.sh/v1/jobs/" + jobId + "/result",
    { headers: { Authorization: "Bearer " + apiKey },
      followRedirects: false, muteHttpExceptions: true }
  );
  return res.getHeaders()["Location"];
}

Results are stored for 24 hours, then deleted, so pull the file into Drive with UrlFetchApp or DriveApp soon after the job completes. Pricing is prepaid at $0.10 per minute of video, so a 30 second clip costs about a nickel.

When this approach fits

  • You already keep a content calendar or shot list in Sheets and want a caption button next to each row.
  • The videos are short clips under the 10 minute per job maximum.
  • You want burned-in captions with no local tooling at all.

One tradeoff to keep in mind: 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.

Back to all articles