Skip to main content
A Worker can’t run a binary or start a subprocess, so a downloader or ffmpeg can’t run inside one. You don’t need either: the Worker sends the link to Importly over HTTPS and gets back the transcript, a link to the file, or the metadata. This recipe is one Worker with three routes: start a transcript, check on a long one, and receive the webhook.

1. Add your key as a secret

Create your key on the API key page (it’s shown once) and store it as a Worker secret, so it never sits in wrangler.toml or your repo:
For wrangler dev, put the same value in a .dev.vars file next to wrangler.toml and keep that file out of git:
.dev.vars

2. The Worker

POST /transcribe sends the link to Importly. "mode": "auto" uses the video’s captions and falls back to speech-to-text when there are none. wait holds the request until the transcript is ready, so a captioned video usually comes back in this one call. Time spent waiting on fetch doesn’t count against a Worker’s CPU limit.
src/index.ts
A rejected request (a bad link, a key problem, or a low balance) comes back with an HTTP error and an error message. A job that fails later, for example because the video is private, comes back with status: "failed", a code and a message. See Error handling.

3. Poll if it’s still running

Long videos without captions take longer than wait. Then the response has status: "queued" or "running" and a jobId. Have your frontend call GET /transcribe/status?id=<jobId> every few seconds until the status is completed or failed:
segments holds the same transcript with start and end times in seconds, for captions, chapters or search.

4. In production: a webhook, verified with Web Crypto

When the transcript belongs to a record in your database (D1, KV, Supabase), don’t keep anyone waiting. Start the job with a webhookUrl pointing at your Worker and save the result when Importly calls back:
Every delivery is signed. Copy the Webhook signing secret (it starts with whsec_) from the API key page and add it as a second secret:
Workers have no node:crypto by default, so this check uses Web Crypto. crypto.subtle.verify compares the signature in constant time, which is what you want here. The handler then takes only the jobId from the payload and reads the result from the API with your key:
src/index.ts
Each job gets one delivery and no retries, so also check jobs that have been pending for a few minutes with the status endpoint (a Cron Trigger works well for that). The Importly-Webhook-Id header is the same for every delivery of a job’s outcome, so you can store it and skip repeats. The webhook URL must be public https://, so wrangler dev on localhost gets nothing: use polling in development. See Webhooks.

Downloading the file instead

For the video or audio file itself, send the link to POST /import and read GET /import/status the same way. The finished job has result.mediaUrl, a link to the file that’s valid for 7 days. Set includeVideo: false for audio only. To keep files, set store: true and have each import copied to your own bucket, including Cloudflare R2 (recipe). /import has no wait, so use polling or a webhook. See Downloads.
A transcript from captions costs $0.003. Speech-to-text for a video without captions is $0.01 per minute, and maxCostDollars stops a long one before it’s charged. Try it free, no card required. See Pricing & credits.

Let your agent write it

Using Claude Code or Cursor on this Worker? Connect the MCP server and ask it to add transcripts with Importly: it reads the same integration guide and can test with a real link first. See Build with your agent.