# videodl API reference

Human-readable version with examples in Python, curl and JavaScript: https://videodl.app/docs

Base URL: https://api.videodl.app
Format: JSON over HTTPS.
Authentication: send the API key in the `X-API-Key` header on every request. Read it from the environment variable `VIDEODL_API_KEY`; never hard-code it or send it to a browser.

## Flow
1. POST /api/start-download with {"url": "..."} -> 202 {"worker_id": "...", "status": "queued", "applied": {...}}
2. GET /api/download-status?worker_id=ID until `status` is `downloaded` or `error`. While running, wait at least `retry_after` seconds (3) between polls; 5-30 seconds is typical.
3. Download `download_url` (and any links in `extras`) before `expires_at`. File links need no API key.

## Quick example
```bash
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=dQw4w9WgXcQ", "resolution": "720"}'
# -> {"worker_id": "d5bddfc8f915", "status": "queued", "applied": {...}}

curl "https://api.videodl.app/api/download-status?worker_id=d5bddfc8f915" -H "X-API-Key: $VIDEODL_API_KEY"
# repeat until "status" is "downloaded" (use download_url) or "error"
```

## POST /api/start-download
Body fields (only `url` is required; omitted fields use the user's saved dashboard settings; plan limits always apply):
- url (string, required): YouTube URL (watch?v=, youtu.be/, /shorts/, /embed/, /v/) or 11-char video ID. Playlist parameters are ignored.
- resolution (string): 240, 360, 480, 720, 1080, 2160 or "4k", 4320 or "8k". Max height; lowered to the plan maximum.
- audio_only (bool): audio only; MP3 unless audio_format is set.
- audio_format (string): with audio_only: mp3, m4a, opus, flac, wav, original.
- video_only (bool): no audio track; not with audio_only.
- container (string): mp4, mkv, webm, mov.
- video_codec (array of string): preference order from vp9, av1, avc1/h264; optional "any" last.
- format (string): raw yt-dlp selector; needs the Custom formats plan feature.
- info_json (bool): metadata .info.json; all plans.
- captions (bool), caption_langs (string, 1 to 5 language codes, e.g. "en" or "en,es"; "all" is not accepted; default "en"), caption_format (srt, vtt, ass; default srt): needs Captions feature. Each language is fetched separately; original languages are most reliable, auto-translated ones are often refused by YouTube.
- comments (bool), comments_decoded (bool, needs comments), live_chat (bool): need Comments feature.
- skip_download (bool): metadata files only.
- embed_metadata (bool), embed_thumbnail (bool), thumbnail_format (jpg, png, webp; needs embed_thumbnail), voice_boost (bool).
- max_video_size_gb, max_audio_size_gb (integer GB), max_duration_minutes (integer): cannot exceed plan limits.
- filename (string, max 150): placeholders {id} {title} {uploader} {channel} {channel_id} {upload_date} {duration} {view_count} {like_count} {resolution} {ext} {lang}; no / \ : * ? " < > | %.
- fallbacks (array of up to 5 objects, or false): each may set resolution, video_codec, audio_only, video_only, max_video_size_gb, max_audio_size_gb, voice_boost.
Unknown fields or wrong types -> 400 ERR_INVALID_PARAMETER (65) with `field`. Above plan -> 403 ERR_PLAN_LIMIT (66). Feature not on plan -> 403 ERR_FEATURE_LOCKED (58).

## GET /api/download-status?worker_id=ID
Returns 200 with a Job (also when the job failed). 400 ERR_INVALID_PARAMETER if worker_id is missing or malformed (it is 12 hex characters). 404 ERR_NOT_FOUND (67) if the job is unknown, its record was deleted after the retention period, or it belongs to another account (any key of the same account can read it). Expired links still return 200 with expires_in "expired".
Job fields:
- worker_id, status (queued | assigned | downloading | downloaded | error), updated_at, title
- progress: {stage (queued|starting|downloading|processing|uploading|retrying|done|failed), percent (0-100 or null), downloaded_bytes, total_bytes, speed_bps, eta_seconds (or null), attempt, message}
- retry_after (int, while running)
- when downloaded: download_url (empty for metadata-only), type (video|audio|metadata), container, codecs {video, audio}, resolution, size, size_human, expires_at, expires_in, extras {info_json, captions[], comments, comments_decoded, live_chat, transcript} (links only for what worked; transcript comes only from the dashboard's "transcript when there are no captions" setting, not from a request field), extras_status {per extra: status ok|failed (+error_code, error_label, error); captions: status ok|partial|failed + languages {code: {status, url | error_code, error_label, error}}, plus a combined error_code/error_label/error when every language failed}, partial (sent with extras_status; true when some extras failed, false when all were delivered), warnings[] (user-facing messages, only when partial), metadata_only. For S3, GCS and S3-compatible storage, download_url is a signed link valid for 7 days and expires_at is when it stops working (the file stays in your bucket; if the job also has extras, which we host, expires_at is the earlier of the two); for Google Drive, expires_at is absent and expires_in is "".
- extra file errors don't fail a video/audio job (it stays downloaded, partial true); with skip_download the metadata file is the download, so if it can't be fetched the job fails: 70 CAPTIONS_RATE_LIMITED (YouTube answered "too many requests" for that language, mostly auto-translated ones; try later or another language; may suggest original-language tracks), 71 CAPTIONS_NOT_AVAILABLE (no subtitles in that language; lists original-language tracks when any), 72 COMMENTS_UNAVAILABLE (no comments or turned off), 73 LIVE_CHAT_UNAVAILABLE (no chat replay), 74 EXTRA_FAILED (temporary problem; try later)
- when error: error (user-facing text), error_code, error_label, error_type (video_unavailable | video_error | download_error = anything else, usually temporary)
Temporary failures are retried automatically; stage is "retrying" between attempts and `attempt` increases.

## GET /api/usage
200 {plan, video_limit (0 = unlimited), videos_used (completed downloads; running jobs also count toward video_limit), bandwidth_gb (0 = unlimited), bandwidth_used_bytes, rate_per_min (0 = no limit), period_start}

## Errors
Error body: {"error": "...", "error_code": N, "error_label": "...", optional field, hint, plan_limit, retry_after}. Branch on error_code / error_label, not on the text.
HTTP: 400 invalid request, 401 missing key, 403 invalid key / suspended / expired / over plan, 404 job or endpoint not found (67), 405 wrong method on start-download, download-status or usage (68, see `allowed`), 413 body over 64 KB (65, field "body"), 429 rate limited or quota used (respect retry_after), 503 API paused for maintenance. Every API error, including file links, has error, error_code and error_label. File links: 410 ERR_LINK_EXPIRED (69) once expired, 404 if the file isn't there, 400 if the link is malformed, 429 with Retry-After when downloading too much at once. GET /api returns an index of the endpoints.
Codes:
- 1 VIDEO_DELETED: Video has been removed
- 2 VIDEO_UNAVAILABLE: Video is unavailable
- 3 VIDEO_PRIVATE: Video is private
- 4 VIDEO_GEO_RESTRICTED: Video is geo-restricted
- 5 VIDEO_LIVE: Video is currently live
- 6 VIDEO_AGE_RESTRICTED: Video is age-restricted
- 7 VIDEO_MEMBER_ONLY: Channel members only
- 8 VIDEO_PREMIUM_ONLY: Requires YouTube Premium
- 9 VIDEO_UPCOMING: Scheduled live not started
- 10 VIDEO_TOO_LONG: Too long to download
- 11 VIDEO_SIGN_IN: Sign-in required
- 12 VIDEO_EMBED_DISABLED: Playback on other websites has been disabled
- 13 VIDEO_LIVE_ENDED: This live event has ended
- 30 ERR_RESOLUTION: Resolution below minimum
- 31 ERR_DURATION_EXCEEDED: Longer than plan's duration limit
- 40 ERR_AUTH_MISSING: Missing API key
- 41 ERR_AUTH_INVALID: Invalid API key
- 51 ERR_QUOTA_EXCEEDED: Monthly download quota exceeded
- 52 ERR_FORMAT_UNAVAILABLE: Requested format not available — check your Download settings and plan limits (resolution, max file size, codec, container)
- 53 ERR_INVALID_URL: Invalid YouTube URL
- 54 ERR_BANDWIDTH_EXCEEDED: Monthly bandwidth limit reached
- 55 ERR_RATE_LIMITED: Too many requests
- 56 ERR_NO_WORKERS: Service is busy right now — please retry shortly
- 57 ERR_API_PAUSED: API temporarily on hold
- 58 ERR_FEATURE_LOCKED: Feature not available on your plan
- 59 ERR_SUSPENDED: Account suspended
- 60 ERR_NO_REGION: This video is geo-restricted by the uploader or rights holder and is not available from any region we can reach. Retrying will not help.
- 64 ERR_PLAN_EXPIRED: Your plan has expired — renew to keep downloading
- 65 ERR_INVALID_PARAMETER: A request parameter is not valid
- 66 ERR_PLAN_LIMIT: This request goes beyond your plan's limits
- 67 ERR_NOT_FOUND: Not found
- 68 ERR_METHOD_NOT_ALLOWED: This HTTP method isn't supported here
- 69 ERR_LINK_EXPIRED: This download link has expired. Download the video again to get a new link
- 22 ERR_DOWNLOAD_FAILED: temporary problem on our side; retry later. If a code that isn't listed ever appears, handle it by error_type.

## Rate limits
start-download: plan requests/min per key. download-status: 300/min per key. usage: 60/min per key. Over the limit: 429 ERR_RATE_LIMITED (55) with retry_after.