Skip to main content
If your Rails app takes video or podcast links, the media job is the one that breaks once it runs on a server: sites block datacenter IPs, and many videos have no captions to read. Call Importly from the job instead. It returns the transcript, a download link for the file, or the video’s details, for links from YouTube, TikTok, Instagram, X, podcasts and 1,000+ other sites. Long imports can take a few minutes, so don’t hold a worker for them. One job starts the Importly job and stores its ID, and a second job checks the status and enqueues itself again 20 seconds later until it’s done. A retry only ever re-runs the check, so it never starts the job twice. The code uses plain Active Job and Net::HTTP, so it runs on Sidekiq, Solid Queue, GoodJob or any other backend.

1. Add your key

Create your key on the API key page (it is shown once). Add it as IMPORTLY_API_KEY to the environment your app and job workers run in, and to .env (or your credentials) for development:
.env
The jobs below save to a Video model with url, importly_job_id, importly_status, importly_result (json) and importly_error columns:

2. A small client

A 429 raises RetryLater with the retryAfter the API sent, and a 5xx raises it with 30 seconds. A 400 (a bad link), 401 (a wrong key) or 402 (balance too low) won’t change on a retry, so it raises Rejected and the job fails:
app/services/importly.rb

3. The jobs

A shared base class waits for retryAfter on a 429, up to 5 tries, and saves the outcome:
app/jobs/importly_job.rb
"mode": "auto" uses the video’s captions and falls back to speech-to-text when it has none. wait: true holds the request open for up to 30 seconds, so a transcript from captions usually comes back from the first call and is saved straight away:
app/jobs/transcribe_link_job.rb
POST /import returns a job ID straight away:
app/jobs/import_link_job.rb
Anything still queued or running goes to the check job:
app/jobs/check_importly_job.rb
A finished transcript’s importly_result has text, and data.segments with start and end times in seconds. A finished import’s has mediaUrl, a link to the file that’s valid for 7 days: attach it with Active Storage or copy it to your bucket if you keep it, or connect your bucket once and import with store: true (Save to your bucket). A caption transcript costs $0.003; speech-to-text is billed per minute, and maxCostDollars caps what one link can cost. See Transcripts and Downloads.

Run it

Enqueue the job from your controller once the record is saved:
app/controllers/videos_controller.rb

Notes

SOURCE_THROTTLED and LIVE_NOT_SUPPORTED are the failure codes that can work on a later attempt (a stream that is still live, or a site that is busy for now). For those, enqueue TranscribeLinkJob or ImportLinkJob again later; every other failure code is final. See Media unavailable and Source throttled. POST /import allows 240 requests per hour per key, and an account can have 50 imports queued or running at once. Status endpoints allow 3,600 requests per hour per job type; a check every 20 seconds is 180 an hour for each job in progress, so about 20 jobs can poll at once. With Sidekiq or Solid Queue, put these jobs on their own queue with a concurrency limit. For hundreds of links, see Batch imports. Prefer a webhook? Start the job with a webhookUrl, check the Importly-Signature header on the raw body (request.raw_post) as shown in Verify signatures, then read the job by its jobId with Importly.call. Each job gets one delivery and no retries, so keep the check job as a fallback for jobs that stay pending. A youtube.com/playlist?list=… link is rejected with PLAYLIST_NOT_SUPPORTED. Enqueue one job per video instead.