ytdlp.org
On this page

Workflow guide

How to use yt-dlp as an API

yt-dlp is a command-line tool and a Python library — it has no official HTTP API. If your app, backend, or automation needs to turn a video URL into a file programmatically, you have four real options, each with different costs. This guide covers all four honestly, plus what to check in a hosted API before you ship it.

Short answer: yt-dlp has no HTTP API. In Python, import it as a library; from any other language, shell out to the CLI or wrap it in a small service of your own (all three below). If downloads have to keep working inside an app, a hosted API such as Importly takes the link and returns the file, transcript or metadata, and it works from servers where self-hosted downloads get blocked, with nothing to install or patch on the box.

Quick answer

  • Python project? Import yt-dlp directly as a library — no API needed.
  • Other language, low volume? Shell out to the CLI and parse --dump-json output.
  • Production service, real volume? Either build and babysit your own wrapper service, or use a managed media-import API and skip the maintenance.

Option 1: Embed yt-dlp as a Python library

If your code is Python, you do not need an API at all. yt-dlp is on PyPI and is designed to be imported:

import yt_dlp

opts = {
    "format": "bestvideo*+bestaudio/best",
    "outtmpl": "%(uploader)s/%(title)s.%(ext)s",
}

with yt_dlp.YoutubeDL(opts) as ydl:
    info = ydl.extract_info(url, download=True)
    print(info["title"], info["duration"])

Use download=False to fetch metadata only. The yt-dlp Python guide covers the options dict, the downloaded file path, progress hooks and error handling. This is the cleanest integration — full access to formats, progress hooks, and postprocessors. The catch: your process now owns yt-dlp's failure modes (extractor breakage, IP blocks, updates), and downloads are long-running and CPU/network heavy, so you will end up adding a job queue anyway.

Option 2: Shell out to the CLI from any language

From Node, Go, Rust, PHP, or anything else, spawn the binary. The flag that makes this workable is -J / --dump-json, which prints machine-readable metadata instead of downloading:

# Metadata only, as JSON
yt-dlp -J "URL"

# Download and print the final filepath for your program to pick up
yt-dlp -o "%(id)s.%(ext)s" --print after_move:filepath "URL"

Watch out for: non-zero exit codes on partial playlist failures, output that mixes progress and warnings on stderr, and the yt-dlp binary needing regular updates on whatever machine runs this. Fine for internal tools and low volume; brittle as a product dependency.

Option 3: Wrap it in your own HTTP service

The classic build: a small FastAPI/Express app that accepts a URL, runs yt-dlp in a worker, and returns a file or a storage link. A minimal sketch:

from fastapi import FastAPI
import yt_dlp

app = FastAPI()

@app.post("/import")
def import_media(url: str):
    with yt_dlp.YoutubeDL({"outtmpl": "/data/%(id)s.%(ext)s"}) as ydl:
        info = ydl.extract_info(url, download=True)
    return {"id": info["id"], "title": info["title"]}

That sketch works in a demo and falls over in production. Before trusting it, you need: a job queue (downloads take minutes), disk cleanup, concurrency limits, retry logic, a strategy for datacenter IP blocks, cookie management for gated content, and a cron job updating yt-dlp before extractor breakage takes you down. Budget for ongoing maintenance, not a weekend project.

Option 4: Use a managed media-import API

If the download capability is part of a product — a SaaS feature, an AI pipeline, a no-code automation — the honest comparison is build-vs-buy. A managed API like Importly does the same job as the wrapper service above — public link in, usable media out — but the extractor updates, server-side blocks, rate limits, and retries are someone else's pager. You get webhook or direct-to-S3 delivery instead of managing disks. The trade-off is a per-import cost and an external dependency, which is why self-hosting still makes sense for personal tools and unusual requirements.

Running this inside your app on a server?

If the download has to keep working in production, the same job is one API call to Importly. You send the link and get the file back at your webhook (or by polling), from servers where self-hosted downloads get blocked. Free to try, no card required.

import os
import requests

# Submit the link; Importly POSTs the finished file to your webhook.
res = requests.post(
    "https://api.importly.io/import",
    headers={"Authorization": f"Bearer {os.environ['IMPORTLY_API_KEY']}"},
    json={
        "url": "https://www.youtube.com/watch?v=jNQXAC9IVRw",
        "webhookUrl": "https://example.com/webhooks/importly",
    },
)
print(res.json()["data"]["jobId"])  # or poll GET /import/status?id=...

Get a key and make your first call in the quick start, with transcripts and metadata too.

Guides for your stack: Python, Next.js, Laravel, Rails, Go, BullMQ, Celery, Supabase Edge Functions.

What to check in a hosted download API before you ship

Most hosted download APIs work in a demo. The ones that fail tend to fail a few weeks after launch, when the site changes something or your traffic moves to production servers. Check these before you build on one:

  • Test from your production host, not your laptop. Run a dozen real links from the same cloud region your app runs in. Datacenter IPs get blocked first, so a laptop test tells you little.
  • Errors you can act on. A private, removed or login-only video should come back as a specific error code you can show the user, not a generic 500 you retry forever.
  • Failed jobs cost nothing. If the provider charges for failures, a bad week on their side becomes your bill.
  • Webhooks for failures too. You want to hear when a job fails, not find out from a customer.
  • A cost cap per request. Users paste three-hour streams. You should be able to reject those before anything downloads.
  • A file, not a direct YouTube link. Many download APIs hand back a googlevideo.com URL. It expires within hours and is often tied to the IP that requested it, so your server gets a 403 when it fetches it later or from another machine. Why those links 403 and how to check.
  • Delivery to your storage. A short-lived link is fine for a preview; for a product you usually want the file in your own bucket.
  • Signs it's maintained. A public changelog with recent fixes for the sites you care about, and a provider that answers email. A marketplace listing with no changelog is the pattern that dies quietly.

For reference, Importly (from the people behind this site) returns error codes like VIDEO_PRIVATE and AUTH_REQUIRED, doesn't charge for failed imports, sends a webhook on success or failure, takes a maxCostDollars cap, can copy files into your S3, R2 or B2 bucket, and keeps a public changelog. It's free to try, no card required. Hold any provider, including that one, to the same checks.

For builders

Using yt-dlp inside an app or script?

Paste a link to see what a managed media-import API returns — no install, no signup.

Building this into an app? See the API your backend calls instead

Which option fits your case

  • personal scripts and internal tools → library or CLI, keep it simple
  • Python app, modest volume, tolerant of breakage → library + a job queue
  • product feature, paying users, or AI pipeline at volume → managed API, or a wrapper service with real ops investment
  • anything running on cloud IPs at scale → read the server guide first; IP blocking changes the math

Frequently asked questions

Does yt-dlp have an HTTP API?

No. yt-dlp is a command-line tool and a Python library. To call it over HTTP you either wrap it in your own service or use a hosted media API that takes a link and returns the file.

Why does yt-dlp work on my laptop but get 403 or bot-check errors in production?

Sites like YouTube treat cloud and datacenter IPs much more strictly than home connections, so the same command that works locally fails on AWS, GCP, Fly or a CI runner. See the server guide for the free fixes; if downloads are part of your product, a hosted API that works from servers is the other route.

Which YouTube download APIs hold up after you ship?

Judge them on what happens in production, not in a demo: test from your own server region, check that failures return specific error codes and aren't charged, that failed jobs send a webhook, that you can cap cost per request, and that the provider keeps a public changelog. Providers that only exist as a marketplace listing are the ones that tend to stop working without notice.

Should I self-host yt-dlp or use a hosted API?

Self-host for personal scripts, internal tools and anything running from a home connection: it's free and you control it. Use a hosted API when downloads are a feature paying users rely on and your app runs on servers, because keeping a self-hosted wrapper working there becomes ongoing ops work.