Skip to main content
If your app runs on Firebase, a video transcript is the feature that breaks once it ships: the code that worked on your laptop gets blocked from Google Cloud’s servers, and many videos have no captions to read. Send the link to Importly from a Cloud Function instead and save what comes back in Firestore. This recipe is three functions and one collection:
  • startTranscript, a callable function, starts the job for a signed-in user and creates a transcripts/{jobId} document.
  • importlyWebhook receives Importly’s signed webhook and fills in the document.
  • sweepTranscripts runs every five minutes and finishes any document whose webhook never arrived.
Your app reads the document with the normal Firebase SDK, so it never sees your Importly key. Tested with firebase-functions 7 and firebase-admin 14 (2nd gen functions, Node 22) against the Firestore emulator.

1. Add your keys as secrets

Create your key on the API key page (it is shown once), and copy the Webhook signing secret (it starts with whsec_) from the same page. Store both in Secret Manager:
Each function lists the secrets it reads, and only those are available to it. For the emulator, put the two values in functions/.secret.local and keep that file out of git.

2. The functions

All three live in one file. saveJob is shared: the webhook and the sweep both read the job from the status endpoint with your key and save it in a transaction that only updates a document still queued or running, so a second delivery, or the sweep finding a job the webhook already saved, does nothing.
functions/src/index.ts
startTranscript: "mode": "auto" uses the video’s captions and falls back to speech-to-text when there are none, and webhookUrl points at importlyWebhook. A rejected request (a bad link, a key problem, or a low balance) throws an HttpsError with Importly’s code in details, and no document is written. See Error handling. importlyWebhook: Firebase keeps the exact bytes of the request in req.rawBody, which is what the signature covers. The handler takes only the jobId from the payload and reads the result from the API with your key. Right after you rotate the signing secret, Importly sends two v1 signatures for 24 hours, and this check accepts either. See Webhooks. sweepTranscripts: each job gets one webhook delivery and no retries. The sweep also covers the emulator: the webhook URL must be public https://, so a function on localhost never receives it. If you deploy to another region, change REGION; the webhook URL is built from it and the project ID.

3. Security rules

Signed-in users can read their own transcripts. Only the functions, which use the Admin SDK, write them:
firestore.rules

4. Deploy and call it

Cloud Functions need the Blaze plan. The first deploy of the sweep turns on Cloud Scheduler for the project. From your app, start a transcript and listen for the result:
segments holds the same transcript with start and end times in seconds, for captions, chapters or search. A job that fails later, for example because the video is private, is saved with status: 'failed' and its errorCode and errorMessage.

Downloading the file instead

For the video or audio file itself, start POST /import the same way and save mediaUrl from GET /import/status in saveJob. That link is valid for 7 days, so store the file if your app needs it longer: with store: true, each import is copied to your own S3 or R2 bucket (recipe). Set includeVideo: false for audio only. 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, Cursor or Firebase Studio on this project? 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.