Skip to main content
If your Django or Flask app hands video or podcast links to Celery, the media task 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 task 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 task starts the job, and a second task checks its status and schedules itself again with self.retry(countdown=20) until the job is done. A retry only ever re-runs the check, so it never starts the job twice. This page uses Celery 5 with Redis as the broker and httpx.

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 Celery workers run in, and to .env for local development:
.env

2. A small client

The tasks share one helper. A 429 raises RetryLater with the retryAfter the API sent, and a 5xx raises it with 30 seconds, so the task retries after that wait. 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 task fails:
myapp/importly.py

3. The tasks

"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. Anything still queued or running goes to check_job:
myapp/tasks.py
save_result is yours: store job["result"] on the record when status is "completed", or job["code"] and job["message"] when it’s "failed". A transcript has result["text"]. An import has result["mediaUrl"], a link to the file that’s valid for 7 days, so copy the file to your storage 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. More options are in Transcripts and Downloads.

Run it

Queue the task from your view once the record is saved. In Django, transaction.on_commit makes sure the worker can read the row:
views.py
Start a worker with celery -A myapp.tasks worker --loglevel=info. If your Django project already has a Celery app, use it in place of the Celery(...) line.

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, queue transcribe_link or import_link again later; every other failure code is final. See Media unavailable and Source throttled. POST /import allows 240 requests per hour per key, and rate_limit="4/m" keeps one worker under that. Celery applies rate_limit per worker, so divide it by the number of workers that run the task. 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. For hundreds of links, see Batch imports. Prefer a webhook? Start the job with a webhookUrl and save the result in a Django or Flask view, as in Python (FastAPI). Each job gets one delivery and no retries, so keep check_job as a fallback for jobs that stay pending. Running on AWS Lambda instead of a Celery worker? See the AWS Lambda recipe. A youtube.com/playlist?list=… link is rejected with PLAYLIST_NOT_SUPPORTED. Queue one task per video instead.