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 inwrangler.toml or your repo:
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
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 thanwait. 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 awebhookUrl pointing at your Worker and save the result when Importly calls back:
whsec_) from the API key page and add it as a second secret:
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
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 toPOST /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.