crawlfetch

Video download API for cURL & Bash: YouTube, TikTok, Instagram and more

Sometimes a shell script is all you need — a cron job, a CI step, a quick archive. CrawlFetch works with plain curl and jq: one call to resolve, one call to download.

What you need

  • A CrawlFetch API key — create one free (1,000 free credits on signup plus 500 a month, no card).
  • curl 7.68+ and jq.
  • The key stored in an environment variable named CRAWLFETCH_KEY, never in source control.

Resolve a video URL in cURL & Bash

Call GET /v1/resolve with the video URL. Watch, Shorts, youtu.be and embed URLs are all accepted. Optional format (mp4, webm, m4a, opus) and res (360p–2160p) parameters pick the file; the API falls back to the closest available resolution.

#!/usr/bin/env bash
set -euo pipefail
VIDEO_URL="${1:-https://youtu.be/aqz-KE-bpKQ}"
curl -sfG "https://api.crawlfetch.com/v1/resolve" \
--data-urlencode "url=$VIDEO_URL" \
--data-urlencode "format=mp4" \
--data-urlencode "res=1080p" \
-H "Authorization: Bearer $CRAWLFETCH_KEY" > video.json
jq -r '.title, .bestQuality, (.formats | length | tostring) + " formats"' video.json

Download the file

downloadUrl is a direct download link on the CrawlFetch domain — a plain file URL, not a stream manifest or player page. Fetch it like any other file and stream the body to disk (or to your own storage) rather than buffering whole videos in memory.

ID=$(jq -r .id video.json)
curl -fL --retry 3 -o "$ID.mp4" "$(jq -r .downloadUrl video.json)"
# list every format with its size
jq -r '.formats[] | [.label, .container, .kind, (.sizeMb|tostring)+" MB"] | @tsv' video.json

Handle errors and rate limits

-f makes curl exit non-zero on HTTP errors so set -e stops the script. Add --retry 3 --retry-all-errors for transient 500s; to honour 429 delays, capture headers with -D headers.txt and sleep for the retry-after value.

StatusMeaningWhat to do
400Missing or malformed url parameterValidate the URL before calling; don't retry
401Missing, invalid or revoked API keyCheck the key and the env var it is read from
404Video is private, removed or region-lockedTell the user; retrying will not help
429Quota or rate limit exceededWait for the Retry-After header, then retry
500Upstream manifest fetch failedSafe to retry with exponential backoff

Production checklist

  • Call the API from your server, not from browser or mobile code that would expose the key.
  • Cache the resolve response for up to a few hours — downloadUrl stays valid for roughly six.
  • Use -G --data-urlencode so URLs with & or ? are encoded correctly.

FAQ

How do I download a whole list of URLs?

Loop over a file: while read -r u; do ./resolve.sh "$u"; done < urls.txt, and stay within your rate limit. See bulk downloads.

Does this work on Windows?

Windows 10+ ships curl.exe. For a native approach see the PowerShell guide.

Related

Last updated 2026-10-25

Add video downloads to your product today.

1,000 credits on signup plus 500 every month. That is roughly 180 YouTube clips to start, with no card.

Create free account