crawlfetch

Video download API for browser JavaScript: YouTube, TikTok, Instagram and more

Calling a paid API straight from the browser leaks the key to anyone who opens DevTools. The safe pattern is a tiny server endpoint that holds the CrawlFetch key and returns only what the page needs. This guide shows both halves.

What you need

  • A CrawlFetch API key — create one free (1,000 free credits on signup plus 500 a month, no card).
  • Any frontend (React, Vue, vanilla).
  • A server endpoint you control — Node, a serverless function or an edge worker.
  • The key stored in an environment variable named CRAWLFETCH_KEY, never in source control.

Resolve a video URL in browser JavaScript

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.

// Minimal Node 18+ endpoint: GET /resolve?url=...
import { createServer } from "node:http";
createServer(async (req, res) => {
const url = new URL(req.url, "http://localhost").searchParams.get("url");
const upstream = await fetch("https://api.crawlfetch.com/v1/resolve?" + new URLSearchParams({ url }), {
headers: { Authorization: "Bearer " + process.env.CRAWLFETCH_KEY },
});
const video = await upstream.json();
res.writeHead(upstream.status, { "content-type": "application/json" });
// Return only what the browser needs — never the key.
res.end(JSON.stringify({ title: video.title, downloadUrl: video.downloadUrl }));
}).listen(8787);

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.

async function getDownload(videoUrl) {
const r = await fetch("/resolve?url=" + encodeURIComponent(videoUrl));
if (!r.ok) throw new Error("Could not resolve video (" + r.status + ")");
const { title, downloadUrl } = await r.json();
const a = document.createElement("a");
a.href = downloadUrl;
a.textContent = "Download " + title;
document.body.append(a);
}

Handle errors and rate limits

Map API statuses to user-facing messages in your endpoint: 404 → "This video is private or unavailable", 429 → "Busy, try again in a moment". Rate-limit your own endpoint per user so one visitor cannot spend your quota.

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.
  • Add authentication or a CAPTCHA to your resolve endpoint if it is public.
  • Validate that the submitted URL is a YouTube URL before forwarding it.

FAQ

Why not call the API from the browser directly?

Any key shipped to the browser is public. A server endpoint keeps it secret and lets you add your own limits.

Will the download link work in the browser?

Yes — downloadUrl is a direct HTTPS download link on the CrawlFetch domain, valid for roughly six hours. The browser saves it like any other file.

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