Video download API for Deno: YouTube, TikTok, Instagram and more
Deno has fetch, web streams and file APIs built in, so a CrawlFetch script needs zero dependencies. It runs the same locally and on Deno Deploy.
What you need
- A CrawlFetch API key — create one free (1,000 free credits on signup plus 500 a month, no card).
- Deno 1.40+ or Deno 2.
- The key stored in an environment variable named
CRAWLFETCH_KEY, never in source control.
Resolve a video URL in Deno
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.
const API = "https://api.crawlfetch.com";export async function resolve(url: string, format = "mp4", res = "1080p") {const qs = new URLSearchParams({ url, format, res });const r = await fetch(API + "/v1/resolve?" + qs, {headers: { Authorization: "Bearer " + Deno.env.get("CRAWLFETCH_KEY") },signal: AbortSignal.timeout(15_000),});if (!r.ok) throw new Error("resolve failed: " + r.status);return await r.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.
const video = await resolve("https://youtu.be/aqz-KE-bpKQ");const r = await fetch(video.downloadUrl);const file = await Deno.open(video.id + ".mp4", { write: true, create: true });await r.body!.pipeTo(file.writable);// run: deno run --allow-net --allow-env --allow-write download.ts
Handle errors and rate limits
Check r.ok and r.status; read r.headers.get("retry-after") for 429. Deno's permission flags mean the script can only reach the network and files you allow.
| Status | Meaning | What to do |
|---|---|---|
| 400 | Missing or malformed url parameter | Validate the URL before calling; don't retry |
| 401 | Missing, invalid or revoked API key | Check the key and the env var it is read from |
| 404 | Video is private, removed or region-locked | Tell the user; retrying will not help |
| 429 | Quota or rate limit exceeded | Wait for the Retry-After header, then retry |
| 500 | Upstream manifest fetch failed | Safe 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 —
downloadUrlstays valid for roughly six. - On Deno Deploy there is no writable disk — stream to object storage instead.
FAQ
Does the Node.js code work in Deno?
Mostly — swap process.env for Deno.env.get and Node streams for web streams.
Related
Last updated 2026-10-25