Deployment guide
yt-dlp on Hugging Face Spaces
A Space that takes a YouTube link, grabs the audio and runs Whisper on it works on your laptop. Once it's deployed, every link fails with ERROR: [youtube] <id>: Sign in to confirm you're not a bot. Your code is fine. Spaces run on cloud servers, and YouTube treats requests from cloud IPs as likely bots. The popular Whisper demo Spaces have open threads reporting this exact error with no fix from the maintainers.
Short answer: Spaces run on cloud IPs, and YouTube blocks them. The free fix is letting people upload the file instead, and cookies help for a while (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.
Why it works locally and not on the Space
Your laptop sits on a home or office IP that YouTube sees real people use. A Space runs in a datacenter, on IPs shared with lots of other automated traffic, so YouTube asks it to sign in before it serves the video. Updating yt-dlp, changing the format or adding a User-Agent doesn't change that. It's the same wall as on a VPS or a CI runner, covered in yt-dlp works locally but not on my server and yt-dlp in GitHub Actions.
Other sites behave differently. A direct file link or a podcast feed usually downloads fine from a Space, so test with one of those before you rip out your download code.
Fix 1 (free, most reliable): let people upload the file
If the Space is a demo of your model, the simplest fix is to stop fetching from YouTube on the Space at all. Accept an audio or video upload next to the URL box, and say in the description that YouTube links may be blocked on hosted Spaces. In Gradio that's an extra input:
import gradio as gr
def transcribe(audio_path):
# audio_path is a local file Gradio saved from the upload
return model.transcribe(audio_path)["text"]
gr.Interface(
fn=transcribe,
inputs=gr.Audio(type="filepath", sources=["upload", "microphone"]),
outputs="text",
).launch()People who want a YouTube video can download it on their own machine with yt-dlp -x --audio-format mp3 "URL" and upload the result. See extract audio as MP3.
Fix 2: cookies from a Space secret (and the catch)
If the Space has to accept links, you can pass yt-dlp the cookies of a signed-in YouTube account. Export a cookies.txt from a browser (see how to use cookies with yt-dlp), paste its contents into a secret named YT_COOKIESin the Space's settings, and write it to a file when the app starts. Spaces expose secrets as environment variables:
import os
import yt_dlp
opts = {"format": "bestaudio/best", "outtmpl": "audio.%(ext)s"}
cookies = os.environ.get("YT_COOKIES")
if cookies:
with open("/tmp/cookies.txt", "w") as f:
f.write(cookies)
opts["cookiefile"] = "/tmp/cookies.txt"
def fetch_audio(url):
with yt_dlp.YoutubeDL(opts) as ydl:
info = ydl.extract_info(url, download=True)
return ydl.prepare_filename(info)Keep the Space's secret a secret: never commit cookies.txtto the Space repo, which is public for public Spaces. Then be honest about the trade-offs. Using an account from a datacenter IP is the pattern that gets accounts flagged, so use a throwaway, never your main. The cookies expire, so the Space works for a week or two and then fails again. And on a public Space every visitor's request runs on that one account. Cookies also don't change the IP, so some requests still get blocked.
If cookies get you in but formats fail
Signed in, you may still see skipped formats or HTTP 403 on the media itself. That's YouTube asking for a PO token. A token provider is a separate service, which is awkward to run inside a Space. The background and setup are in run a yt-dlp PO token provider on a server and the SABR 403 guide.
The limit: you don't choose the Space's IP
You can't move a Space to a home IP, so a link-based YouTube Space is always one YouTube change away from breaking. If the Space is a demo, Fix 1 is the honest answer. If it's turning into a real app, move the download out of the Space: run that step on a machine you control, or call a hosted API that takes the link and returns the audio file or transcript, and keep only your model on the Space.
Servers & agents
Works on your laptop but not on the server?
Paste a link to see what a hosted API returns, running from servers and agent sandboxes where datacenter IPs get blocked — nothing to install or maintain on the box.
Building this into an app? See the API your backend calls instead