Guide
yt-dlp “Sign in to confirm you’re not a bot”: why it happens and how to fix it
Your VPS script downloaded YouTube videos yesterday, and today yt-dlp demands a sign-in. Here is where the block comes from, which fixes work, and where each one breaks in production.
What the error actually means
The full message looks like this:
ERROR: [youtube] dQw4w9WgXcQ: Sign in to confirm you’re not a bot. Use --cookies-from-browser or --cookies for the authentication.This is not a yt-dlp bug. It is YouTube refusing to hand over formats to an anonymous client it does not trust. The decision is based on a bundle of signals, and the biggest one is IP reputation. Datacenter ranges (pretty much any VPS: Hetzner, OVH, AWS, DigitalOcean) start out under suspicion, and a steady stream of requests from one address makes a block close to certain. The same command often works from a home connection, which is the quickest way to confirm the server is the problem.
The second factor is that your request carries no browser-like proof: no cookies from a logged-in session and no PO token (Proof of Origin, a token YouTube asks some clients to send). Below is what actually fixes the problem and what only postpones it.
Rule out the easy stuff first
- Update yt-dlp. YouTube changes clients and protections constantly, and a two-month-old build is the most common reason for a sudden breakage.
- Check the JS runtime. yt-dlp needs an external JavaScript runtime for YouTube (Deno by default) plus the yt-dlp-ejs package. Without them some formats cannot be extracted, so the bot error is not the only thing you will see.
- Run the same link from your laptop or over mobile data. If it works there and fails on the VPS, the IP is the problem and no update will fix it.
pip install -U "yt-dlp[default]" # fresh yt-dlp + yt-dlp-ejs
yt-dlp --version
deno --version # JS runtime for YouTubeFix 1: account cookies
The error message itself points to --cookies-from-browser and --cookies. A VPS has no browser, so people usually export cookies on their own machine and copy the file over:
# on your own machine, with a browser that is logged in to YouTube
yt-dlp --cookies-from-browser chrome --cookies cookies.txt "https://youtu.be/dQw4w9WgXcQ"
scp cookies.txt user@your-vps:~/cookies.txt
# on the server
yt-dlp --cookies ~/cookies.txt "https://youtu.be/dQw4w9WgXcQ"It works, but it comes with a price:
- You can lose the account. The yt-dlp docs warn that an account used with yt-dlp can be banned, temporarily or permanently. Use a throwaway account, never your main one.
- Cookies expire. YouTube rotates sessions, so an exported file stops working after a while. You need monitoring and manual re-exports; the usual advice is to export from a private window and close it right away.
- The file is access to the account. The command above saves cookies for every site. Treat it like a password and keep it out of git.
- It does not scale. One account means one request budget. A bot with real traffic hits it fast.
Fix 2: PO token
A PO token proves the request came from a “real” client. According to the yt-dlp docs, clients such as web and mweb need it to fetch media streams. A token is bound to a video and lives for a limited time, so you cannot paste one by hand. The usual route is a plugin plus a provider that generates tokens for you:
python3 -m pip install -U bgutil-ytdlp-pot-provider
docker run --name bgutil-provider -d --init \
-p 127.0.0.1:4416:4416 brainicism/bgutil-ytdlp-pot-provider
yt-dlp "https://youtu.be/dQw4w9WgXcQ" # the plugin finds the provider on its ownThe catch: a PO token does not lift an IP-based block. The provider authors say outright that cookies may still be required from a flagged address. On top of that, you now run and update one more service.
Fix 3: proxies
yt-dlp --proxy socks5://user:pass@host:1080 "https://youtu.be/dQw4w9WgXcQ"A datacenter proxy lands in the same gray zone as your VPS. Residential and mobile proxies help, but you pay per gigabyte, and video is measured in gigabytes. Add rotation, blocklisted addresses and uneven speeds, and you have another system to babysit.
Slow down: do not make it worse
If you download in batches, do not hammer YouTube without pauses. Delays lower the odds of a rate-based block:
yt-dlp --sleep-requests 1 --sleep-interval 5 --max-sleep-interval 10 -a urls.txtCache metadata and finished files, never request the same video twice, and avoid dozens of parallel processes from one address. It is not a silver bullet, but every other fix lasts noticeably longer with it.
The options side by side
| Option | Reliability on a VPS | Cost | Maintenance |
|---|---|---|---|
| Updated yt-dlp + JS runtime | Mandatory, but does not lift an IP block | Free | Update regularly |
| Account cookies | Medium: they expire, the account is at risk | Free + a throwaway account | Manual re-export, monitoring |
| PO token (plugin) | Medium: datacenter IPs often still need cookies | Free, but you run a service | Keep plugin and provider updated |
| Residential proxies | Higher, but speed and availability vary | Pay per GB, adds up fast on video | Rotation, blocklists, billing |
| API (InterAPI) | High: blocks are handled on the service side | 15 credits per YouTube request | Minimal: one HTTP call |
For a one-off script on your own machine, a current yt-dlp and maybe cookies are enough. For a bot or service that has to run 24/7, every option above turns into ongoing operational work.
The reliable option for production bots: an API instead of scraping
The idea is simple: you stop fighting blocks yourself, send the link to an API and get JSON back. For YouTube, InterAPI offers GET /api/v1/youtube. It accepts youtube.com, youtu.be, Shorts and music.youtube.com links and costs 15 credits per successful request (5xx responses are free, 4xx cost at most 1 credit). Authentication is the X-API-Key header.
What the response looks like
{
"status": "success",
"title": "Rick Astley - Never Gonna Give You Up (Official Video) (4K Remaster)",
"author": "Rick Astley",
"duration_sec": 213,
"thumbnail": "https://i.ytimg.com/vi_webp/dQw4w9WgXcQ/…",
"media": [
{ "type": "video", "quality": "mp4 (360p)", "format_id": "18", "height": 360, "ext": "mp4", "url": "https://…googlevideo.com/videoplayback?…" },
{ "type": "audio", "quality": "m4a (129kb/s)", "format_id": "140", "ext": "m4a", "bitrate": 129473, "url": "https://…googlevideo.com/videoplayback?…" }
],
"video_url": "…", "music_url": "…", "duration_ms": 3165
}media is the list of formats with format_id (the itag), height and extension. Note that formats above 360p usually arrive as separate video and audio tracks, so they have no sound. A single file with audio is, for example, format_id: 18 (mp4, 360p).
Downloading the file in Python
The links in media[] are signed googlevideo.com URLs. They carry an expiry (expire) and the IP they were issued for (ip), so they may refuse to open from your server. The safer route is the InterAPI file proxy: GET /api/v1/youtube/file takes the same url plus kind (video or audio) and mode=file, which makes the server stream the file bytes itself instead of redirecting you to a CDN. Downloads through this endpoint cost no credits; you pay only for the metadata request.
import os
import re
import sys
from pathlib import Path
import requests
API = "https://api.interapi.dev"
HEADERS = {"X-API-Key": os.environ["INTERAPI_KEY"]}
def video_info(url: str) -> dict:
"""15 credits per successful request: title, author, duration and the list of formats."""
r = requests.get(f"{API}/api/v1/youtube", params={"url": url}, headers=HEADERS, timeout=60)
if r.status_code != 200:
raise RuntimeError(f"InterAPI {r.status_code}: {r.json().get('detail')}")
return r.json()
def download(url: str, kind: str = "video", out_dir: str = "downloads") -> Path:
"""Stream the file through InterAPI so the CDN link never has to work from your IP."""
params = {"url": url, "kind": kind, "mode": "file"} # kind: video | audio
with requests.get(f"{API}/api/v1/youtube/file", params=params, headers=HEADERS,
stream=True, timeout=(10, 120)) as r:
r.raise_for_status()
size = int(r.headers.get("Content-Length", 0))
if size > 50 * 1024 * 1024:
print(f"warning: {size / 1e6:.0f} MB, too big for a regular Telegram bot upload")
ext = "m4a" if "audio" in r.headers.get("Content-Type", "") else "mp4"
Path(out_dir).mkdir(exist_ok=True)
video_id = re.search(r"(?:v=|youtu\.be/|shorts/)([\w-]{11})", url)[1]
path = Path(out_dir) / f"{video_id}.{ext}"
tmp = path.with_name(path.name + ".part")
with open(tmp, "wb") as f:
for chunk in r.iter_content(chunk_size=1 << 20):
f.write(chunk)
tmp.replace(path)
return path
if __name__ == "__main__":
link = sys.argv[1]
info = video_info(link)
print(info["title"], "|", info["author"], "|", info["duration_sec"], "s")
print(download(link, "audio"))The same thing with curl:
# 1) metadata and the format list (15 credits per successful request)
curl -G "https://api.interapi.dev/api/v1/youtube" \
-H "X-API-Key: YOUR_API_KEY" \
--data-urlencode "url=https://youtu.be/dQw4w9WgXcQ"
# 2) the file itself through the InterAPI proxy (kind=video or audio)
curl -G "https://api.interapi.dev/api/v1/youtube/file" \
-H "X-API-Key: YOUR_API_KEY" \
--data-urlencode "url=https://youtu.be/dQw4w9WgXcQ" \
-d "kind=video&mode=file" -o video.mp4Large files and timeouts
- Stream it. Use
stream=Trueand write 1 MB chunks so the whole file never sits in memory. Write to a.partfile and rename on success. - Budget for the first byte. For video the server builds the file first (video plus sound), so the first bytes can take several seconds or more. Set a 60–120 second read timeout, not the usual 5–10. Audio starts noticeably faster.
- Check the size up front. The response carries
Content-Length. If you forward the file to Telegram, remember that the regular Bot API accepts uploads up to 50 MB. See how to build such a bot in Python or in PHP. - Retries. 5xx errors are free and usually transient, so retry after a pause. Do not retry 4xx (bad link, private video): the answer will not change.
Honest limits: the API cannot open private videos, just like any tool that does not have your account. And if you grab a couple of clips a week from your own computer, plain yt-dlp is all you need.
Wrapping up
“Sign in to confirm you’re not a bot” is about trust in your IP, not about the version of your script. Updates and pauses always help, cookies and a PO token sometimes help at the cost of upkeep, and proxies help for money and effort. If you want a stable result without being on call, move downloading into an API. A new InterAPI account gets 1,000 free credits (up to 30 requests per hour until the first top-up), credits never expire and there is no subscription. Get a key, check the pricing or jump straight to the YouTube API docs.
Was this article helpful?
Related API docs
FAQ
Why does yt-dlp ask me to sign in when I am not logged in anywhere?
YouTube is not checking a login, it is checking how much it trusts the client: IP reputation, request rate, cookies and PO token. Datacenter addresses are suspicious from the start, so the error shows up mostly on a VPS and rarely on a home IP.
Will updating yt-dlp fix it?
Sometimes. YouTube changes its clients regularly and an old build breaks. But if the block is tied to your server's IP address, an update will not lift it. Try the same link from a home IP to see which case you are in.
Is it safe to use cookies from my main account?
No. The yt-dlp docs warn that the account can be banned, and the cookie file gives access to your session. If you cannot avoid cookies, use a separate account and store the file like a password.
How much does it cost to download a YouTube video through InterAPI?
A successful /api/v1/youtube request costs 15 credits. 5xx responses are free and 4xx responses cost at most 1 credit. Downloading the file through the /api/v1/youtube/file proxy does not charge credits. Every new account gets 1,000 credits.
Does the API work with Shorts and YouTube Music?
Yes. It accepts youtube.com, youtu.be, /shorts/ and music.youtube.com links. For searching YouTube there is a separate /api/v1/youtube/search endpoint.
More guides
-
How to download Instagram Reels, photos and carousels with an API in Python (no login)
Download Instagram Reels, photos and carousels with a Python API, no login: requests and aiohttp code, 429 handling, JS and PHP snippets, cost math. Read -
Social media downloader Telegram bot in PHP (webhook + InterAPI)
Write a Telegram bot in plain PHP that downloads TikTok, Instagram and YouTube videos: webhook setup, secret_token, full code and hosting tips. Read -
How to build a Telegram video downloader bot in Python (TikTok, Instagram, YouTube)
Build a Telegram bot with aiogram 3 that downloads videos from TikTok, Instagram and YouTube by link: full Python code, systemd deployment, cost math. Read