A YouTube Download API for AI Agents, Without the Bot Checks

8 min read Summarize with Claude ChatGPT Gemini Perplexity
Your AI agent hit YouTube's 'Sign in to confirm you're not a bot' error

Why your agent hits "Sign in to confirm you're not a bot"

Claude Code, Codex, Cursor, n8n and most agent frameworks run their tools on a server or in a sandbox. When the agent decides to download a YouTube video, it usually installs yt-dlp and runs it from there. YouTube gives requests from data-centre IP addresses far less trust than requests from home connections, so the agent gets a sign-in check, a 403 or a 429 instead of a video. We explain the error itself in this fix guide.

The usual workaround, exporting your browser cookies so yt-dlp looks signed in, is a bad fit for agents:

  • It hands your Google account to an autonomous loop. The cookies sit in a file the agent can read, log or paste into a prompt.
  • It can get the account restricted. Heavy automated downloading from a signed-in session is exactly what YouTube rate-limits, sometimes for days.
  • It breaks silently. Cookies expire, yt-dlp needs updates when YouTube changes, and the agent spends tokens retrying a command that can't work.

What an agent needs from a download tool

Agents work best with tools that are boring: one call, a predictable result, and errors that say what to do next. For YouTube downloads that means:

Needyt-dlp inside the agentDownload API
Works from a cloud sandboxOften blocked by bot checksYes, downloads run on the provider's side
Secrets the agent holdsYour Google cookiesOne API key with no account access
ResultA file on the sandbox disk, or a stack traceA download link, size, codecs and resolution
ErrorsFree-text output the model has to interpretNumbered codes: private, deleted, geo-blocked, quota
UpkeepUpdate yt-dlp when YouTube changesNone on your side

How the API works

Two endpoints. Start a job with the video URL, then poll until it's done. Every call takes your key in the X-API-Key header.

An AI agent sends a video URL to the videodl.app API, which downloads it and returns a direct download link
Your agent sends a video URL, the API does the download, and the agent gets a direct download link back.
cURL
curl -X POST https://api.videodl.app/api/start-download \
  -H "X-API-Key: $VIDEODL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://www.youtube.com/watch?v=VIDEO_ID", "resolution": "1080"}'

curl "https://api.videodl.app/api/download-status?worker_id=WORKER_ID" \
  -H "X-API-Key: $VIDEODL_API_KEY"

The first call returns {"worker_id": "...", "status": "queued"}. The status call moves through queued, downloading and finally downloaded, with a download_url, the resolution, the codecs and an expires_in time, or error with an error_code. While a job runs, the response includes retry_after, the number of seconds to wait before the next check.

Give your agent the tool

Option 1: an MCP server

If your agent supports the Model Context Protocol (Claude Code, Claude Desktop, Cursor, Codex and many others do), add a small MCP server and the agent discovers the tool on its own. We wrote a tested 90-line server and the setup for each client in YouTube download MCP server for Claude Code, Cursor and Codex.

Option 2: a function-calling tool

For your own agent built on a model API or an agent framework, wrap the two calls in one function. It waits up to wait_seconds and returns either a link, an error code, or a job ID to check later, so the agent never blocks forever. Building in n8n instead? The same two calls work with the HTTP Request node; see how to download YouTube videos in n8n.

Python
import os
import time

import requests

API = "https://api.videodl.app"
HEADERS = {"X-API-Key": os.environ["VIDEODL_API_KEY"]}


def download_youtube_video(url, resolution="1080", audio_only=False, wait_seconds=300):
    body = {"url": url}
    if audio_only:
        body.update({"audio_only": True, "audio_format": "mp3"})
    else:
        body["resolution"] = resolution
    r = requests.post(f"{API}/api/start-download", json=body, headers=HEADERS, timeout=30)
    data = r.json()
    if r.status_code != 202:
        return {"status": "error", "error_code": data.get("error_code"), "error": data.get("error")}

    deadline = time.time() + wait_seconds
    while time.time() < deadline:
        job = requests.get(f"{API}/api/download-status", params={"worker_id": data["worker_id"]},
                           headers=HEADERS, timeout=30).json()
        if job["status"] == "downloaded":
            return {"status": "downloaded", "title": job.get("title"),
                    "download_url": job["download_url"], "expires_in": job.get("expires_in")}
        if job["status"] == "error":
            return {"status": "error", "error_code": job.get("error_code"),
                    "error_label": job.get("error_label")}
        time.sleep(job.get("retry_after", 3))
    return {"status": "still_running", "worker_id": data["worker_id"]}

Then describe it to the model. This is the Anthropic Messages API shape. For OpenAI function tools, the same JSON Schema goes under parameters instead of input_schema.

JSON
{
  "name": "download_youtube_video",
  "description": "Download a public YouTube video and return a temporary download link. Use audio_only for transcription. If status is still_running, report the worker_id.",
  "input_schema": {
    "type": "object",
    "properties": {
      "url": {"type": "string", "description": "YouTube video URL or 11-character video ID"},
      "resolution": {"type": "string", "enum": ["360", "480", "720", "1080", "2160"]},
      "audio_only": {"type": "boolean", "description": "Return an MP3 of the audio only"}
    },
    "required": ["url"]
  }
}

Teach the agent what errors mean

The biggest win over a raw yt-dlp call is that failures come back as codes. Put a short version of this table in your system prompt so the agent stops retrying videos that can't be downloaded:

CodeMeaningWhat the agent should do
1, 2, 3Deleted, unavailable or privateTell the user. Don't retry
4, 60Geo-restrictedTell the user. Retrying won't help
6, 7, 8, 11Age-restricted, members-only, Premium or sign-in requiredTell the user. These need an account we don't use
5, 9Live now, or a scheduled stream that hasn't startedTry again after the stream ends
55Too many requestsWait for retry_after seconds, then retry
51, 54Monthly video or bandwidth quota usedStop and tell the user

The full list is in YouTube download API error codes. Temporary failures, like a blocked download server, are retried for you on other servers before the job reports an error, so the agent doesn't need its own retry logic for those.

Settings that save tokens and bandwidth

  • Transcribing or summarising? Send "audio_only": true. An MP3 is a fraction of the video size. See YouTube to MP3 by API.
  • Only need the words? Ask for "captions": true with "skip_download": true to get subtitles and metadata without the video. See downloading YouTube subtitles by API.
  • Handing the file to another tool? Set a resolution cap like "720", and ask for H.264 if the next tool is picky. See H.264-only downloads.
  • Large batches? Connect S3, GCS, R2 or Google Drive in the dashboard, and files land in your storage instead of a link that expires in about an hour.

Use it on content you're allowed to use

An agent makes it easy to download a lot very quickly. The API only fetches publicly available videos, and our acceptable use policy applies to agents the same as to people: use videos you own, have permission for, or are licensed to use.

FAQ

Why does my AI agent get "Sign in to confirm you're not a bot" from YouTube?

Agents run tools on cloud servers, and YouTube trusts data-centre IP addresses less than home connections. Downloads from those IPs often get a sign-in check, a 403 or a 429. Using a download API moves the download off the agent's server.

Should I give my agent my YouTube cookies to fix bot checks?

We don't recommend it. Cookies give the agent access to your Google account, automated downloads from a signed-in session can get the account rate-limited, and cookies expire. An API key with no account access is safer.

Can Claude Code or Cursor download YouTube videos?

Yes, with a tool. Add an MCP server that calls a download API, and the agent can download videos by URL and get back a link, without running yt-dlp on its own machine.

How does an agent know when a download is finished?

It polls the status endpoint with the job's worker_id. The response says queued, downloading, downloaded or error, and includes retry_after, the seconds to wait before checking again.

How much does the VideoDL API cost for an agent?

Starter is $12 a month for 200 videos. Most teams use a custom plan sized to their volume, video length, resolution and rate. There's a free trial.

Give your agent a YouTube tool that works

One API key, no cookies, no bot checks. Videos, audio, captions and metadata from $12/month. Start with 100 free videos.