# How to use cookies with yt-dlp

Pass cookies to yt-dlp with --cookies-from-browser or a cookies.txt file to reach login-required, age-gated, and private content - plus fixes for the 'could not copy cookie database' error.

If yt-dlp can find a page but fails on the actual media, cookies are often the missing piece. In plain English: you are letting yt-dlp reuse the signed-in session from your browser so it can access content that is not available to an anonymous request.

<HostedAnswer>
On your own machine, pass cookies with `--cookies-from-browser chrome` or a `cookies.txt` file. On a server there is no browser to read from, so you keep a cookie file alive as a secret and re-export it when it goes stale (below).
</HostedAnswer>

## Quick answer

Start with browser extraction. It is the fastest and cleanest option when you are already logged in.

```bash
yt-dlp --cookies-from-browser chrome "URL"
```

Replace `chrome` with the browser you actually use, like `firefox`, `edge`, or `brave` when supported.

## When cookies are needed

- the site says sign in is required
- the media is age-gated or region-gated
- private or semi-private content works in your browser but not in yt-dlp
- the extractor says cookies are required or the request returns 403/401 style failures

If the page truly requires a logged-in session, updating yt-dlp alone will not fix it. You need to pass session state in a way yt-dlp can use.

## Use browser cookies first

```bash
yt-dlp --cookies-from-browser chrome "URL"
yt-dlp --cookies-from-browser firefox "URL"
```

This is usually better than exporting a file manually because it avoids one more stale artifact in your workflow. If it works, use it and move on.

## Pick the right browser and profile

The browser name is only the first part of the flag. The full form lets you point yt-dlp at a specific profile, a Linux keyring, or a Firefox container:

```bash
--cookies-from-browser BROWSER[+KEYRING][:PROFILE][::CONTAINER]
```

Supported browsers today are `brave`, `chrome`, `chromium`, `edge`, `firefox`, `opera`, `safari`, `vivaldi` and `whale`. If you do not name a profile, yt-dlp uses the most recently accessed one - which is the usual reason extraction pulls the wrong cookies when you keep more than one profile.

If the cookies you need live in a different profile - a work profile, a second signed-in account - name it explicitly:

```bash
yt-dlp --cookies-from-browser "chrome:Profile 1" "URL"
yt-dlp --cookies-from-browser "firefox:dev-edition-default" "URL"
```

On Linux, Chromium-family cookies are encrypted with the desktop keyring, so if extraction comes back empty, name the keyring with a `+`: `chrome+gnomekeyring`, or `chrome+kwallet6` on KDE (`basictext`, `kwallet` and `kwallet5` are also supported).

Two platform gotchas worth knowing. On macOS, Safari keeps its cookies in a protected location, so the terminal you run yt-dlp from needs Full Disk Access (System Settings → Privacy & Security → Full Disk Access). And with Chrome, close the browser completely before extracting - a running Chrome locks the cookie database, and recent versions encrypt it in a way yt-dlp cannot always read, which is why Firefox or a `cookies.txt` file is often the more dependable source.

## Use a cookies.txt file when browser extraction fails

```bash
yt-dlp --cookies cookies.txt "URL"
```

This is useful when browser-keychain access fails, when you need a repeatable scriptable setup, or when you are troubleshooting a difficult auth problem. Just remember that exported cookies can expire quickly.

## YouTube cookies that stop working after a day

YouTube rotates the cookies of a signed-in session while a YouTube tab is open. If you export from the browser you use every day, the file is a copy of a session that keeps moving on without it, and it goes stale within hours or days. The fix the yt-dlp wiki recommends is to export from a session nothing else will touch:

1. Open a private or incognito window and sign in to YouTube.
2. In that same tab, go to `https://www.youtube.com/robots.txt`. Keep it the only private tab open.
3. Export the youtube.com cookies to `cookies.txt` with a cookies.txt browser extension. `--cookies-from-browser` reads your normal profile, not this private session.
4. Close the private window without signing out, so the session is never opened in a browser again.

Use a separate Google account for this, not your personal one. Heavy automated use can get the account challenged too.

## Most common cookie failures

- wrong browser selected
- wrong browser profile selected
- expired login session
- the OS keychain blocks yt-dlp from reading cookies
- the site requires more than a simple signed-in session
- the User-Agent doesn't match the browser the cookies came from. TikTok rejects that with a 403 ([fix in the TikTok guide](/guides/yt-dlp-for-tiktok)). Don't pin an old User-Agent next to fresh cookies.
- yt-dlp read no cookies for that site at all, even though the browser is logged in. It happens with Reddit ([fix in the Reddit guide](/guides/yt-dlp-for-reddit)).

To see what yt-dlp actually gets, have it write the extracted cookies to a file and look for the site's login cookie. It complains that there's no URL, but it still writes the file. Delete the file afterwards, because it holds your session:

```bash
yt-dlp --ignore-config --cookies-from-browser firefox --cookies check.txt
grep -c reddit.com check.txt
```

The fast debugging move is simple: confirm the content plays in the browser you are extracting from, then rerun the command with that browser explicitly.

## "HTTP Error 413: Request Entity Too Large" with --cookies

```bash
ERROR: [youtube] <id>: Unable to download API page: HTTP Error 413: Request Entity Too Large
```

A 413 when passing `--cookies` means the request yt-dlp sent was too big for the server to accept, and the cookie header is the usual reason. This points at a stale or malformed cookie file, not something you need to tune. A current yt-dlp already drops expired cookies from the jar on its first request to YouTube, so a cookie header large enough to trip 413 almost always means the file was exported wrong or has gone stale.

The fix, in order: update yt-dlp (`yt-dlp -U`, or update your package) so the expired-cookie handling is current; then re-export your cookies cleanly rather than reusing an old file. Pulling straight from the browser with `--cookies-from-browser` avoids a hand-exported file drifting out of date. If you keep a `cookies.txt`, regenerate it from a fresh logged-in session instead of editing the old one by hand. Only pass cookies when the content actually needs a signed-in session — many downloads do not.

## What not to do

- do not assume old exported cookies will keep working forever
- do not guess the browser name or profile
- do not keep retrying broken commands without verifying the browser session still works
- do not use cookies for content you are not authorized to access

## Cookies on a server or in automation

Both methods above assume a logged-in browser on the same machine. On a headless server, a CI runner, or a container there is no browser profile for `--cookies-from-browser` to read, so that flag has nothing to pull from and errors out. That leaves a `cookies.txt` file, which works but is a live login you now have to store as a secret - and session cookies expire, so a job that ran last week starts failing with 401/403 once the file goes stale.

The usual pattern is to export a fresh `cookies.txt` on a machine that is signed in, copy it to the server, and re-export it whenever it rots.

`--cookies FILE` isn't read-only: yt-dlp writes its cookie jar back to the file when it exits, so the file keeps whatever the site refreshed during the run. In Docker or CI, mount the file somewhere writable and keep it between runs. A read-only mount, or a fresh copy from a secret on every run, throws those updates away.

```bash
docker run --rm -v "$PWD/cookies.txt:/cookies.txt" -v "$PWD:/downloads" \
  your-yt-dlp-image --cookies /cookies.txt "URL"
```

If you are also on a datacenter IP, the IP reputation can block you even with valid cookies - see [when cookies still fail on a server](/guides/yt-dlp-blocked-on-server).

If this is a download your app runs for its users, re-exporting cookies by hand every time they rot doesn't scale. The block below shows the same download as one API call, with no cookie file to keep alive.

<AppCodeTabs />

<DocCta variant="server-agent" />

<Faq />

## Related guides

- [Update yt-dlp](/guides/update-yt-dlp)
- [Fix common yt-dlp errors](/guides/fix-yt-dlp-errors)
- [Use yt-dlp for YouTube](/guides/yt-dlp-for-youtube)
- [Download Bilibili videos with yt-dlp](/guides/yt-dlp-for-bilibili)
- [Understand format selection](/guides/yt-dlp-format-selection)
- [When cookies still fail on a server](/guides/yt-dlp-blocked-on-server)