crawlfetch

Video download API for Elixir: YouTube, TikTok, Instagram and more

Elixir's Req library handles JSON decoding, retries and streaming out of the box, which makes it a good fit for a CrawlFetch worker inside a Phoenix or Oban application.

What you need

  • A CrawlFetch API key — create one free (1,000 free credits on signup plus 500 a month, no card).
  • Elixir 1.15+.
  • The req package.
  • The key stored in an environment variable named CRAWLFETCH_KEY, never in source control.
# mix.exs
{:req, "~> 0.4"}

Resolve a video URL in Elixir

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.

defmodule MyApp.CrawlFetch do
@api "https://api.crawlfetch.com"
def resolve(url, format \\ "mp4", res \\ "1080p") do
Req.get(@api <> "/v1/resolve",
params: [url: url, format: format, res: res],
auth: {:bearer, System.fetch_env!("CRAWLFETCH_KEY")},
retry: :transient
)
|> case do
{:ok, %{status: 200, body: video}} -> {:ok, video}
{:ok, %{status: status}} -> {:error, status}
{:error, reason} -> {:error, reason}
end
end
end

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.

{:ok, video} = MyApp.CrawlFetch.resolve("https://youtu.be/aqz-KE-bpKQ")
Req.get!(video["downloadUrl"], into: File.stream!(video["id"] <> ".mp4"))

Handle errors and rate limits

retry: :transient retries 408/429/5xx with backoff and respects Retry-After. Return {:error, 404} to callers as a final state; it means the video is private, removed or region-locked.

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.
  • Run resolves as Oban jobs with uniqueness on the video ID to avoid duplicate work.

FAQ

Can I use HTTPoison or Finch instead?

Yes. Req is built on Finch; any client that sets a bearer header works.

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