crawlfetch

Video download API for Dart & Flutter: YouTube, TikTok, Instagram and more

Flutter apps that download YouTube media typically bundle youtube_explode_dart, which must be updated whenever YouTube changes. With CrawlFetch, your Dart backend (or a server you control) resolves the URL and the app only handles a normal HTTPS download.

What you need

  • A CrawlFetch API key — create one free (1,000 free credits on signup plus 500 a month, no card).
  • Dart 3 / Flutter 3.
  • The http package.
  • The key stored in an environment variable named CRAWLFETCH_KEY, never in source control.
dart pub add http

Resolve a video URL in Dart & Flutter

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.

import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;
Future<Map<String, dynamic>> resolve(String url, {String format = 'mp4', String res = '1080p'}) async {
final uri = Uri.parse('https://api.crawlfetch.com/v1/resolve')
.replace(queryParameters: {'url': url, 'format': format, 'res': res});
final resp = await http.get(uri, headers: {
'Authorization': 'Bearer ' + Platform.environment['CRAWLFETCH_KEY']!,
});
if (resp.statusCode != 200) {
throw HttpException('resolve failed: ' + resp.statusCode.toString());
}
return jsonDecode(resp.body) as Map<String, dynamic>;
}

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.

Future<void> download(Map<String, dynamic> video, String path) async {
final req = http.Request('GET', Uri.parse(video['downloadUrl'] as String));
final resp = await http.Client().send(req);
await resp.stream.pipe(File(path).openWrite());
}

Handle errors and rate limits

Branch on resp.statusCode; resp.headers['retry-after'] holds the 429 delay. In Flutter, surface 404 (private or removed video) as a user-facing message rather than a retry.

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.
  • In a Flutter app, fetch the resolved URL from your backend — Platform.environment is for server-side Dart.

FAQ

Is this an alternative to youtube_explode_dart?

Yes, for resolving download URLs. The extraction runs as a hosted API, so app releases are not tied to YouTube changes.

Where should the API key live in a Flutter project?

On a server. Anything compiled into the app can be extracted.

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