A free, lightweight API to convert YouTube videos to MP3 and get direct download links. Built to run perfectly on Cloudflare Workers at the edge.
Built by Nimesh Piyumal
Click the button above to instantly deploy your own instance to Cloudflare Workers — no local setup needed!
- 🆓 Free to run — Deployable on Cloudflare Workers free tier (100,000 requests/day).
- ⚡ Edge execution — Runs on Cloudflare's global network for ultra-low latency.
- 🎯 Smart URL Parsing — Supports all YouTube URL formats (watch, shorts, embed, youtu.be, or bare video ID).
- 🌍 CORS enabled — Ready to be integrated into any web browser frontend application.
- 📦 Lightweight — Minimal code footprint with pure ES modules.
- 🔄 Auto Conversion — Automatically triggers conversion if the video isn't already cached.
-
Clone this repo
git clone https://github.com/nimesh-piyumal/ytmp3-api.git cd ytmp3-api -
Install Dependencies & Wrangler CLI
npm install npm install -g wrangler wrangler login
-
Test Locally
npm run dev
-
Deploy to Cloudflare Workers
npm run deploy
-
Done! Your API is live at
https://ytmp3-api.<your-subdomain>.workers.dev
Returns API health status.
Response
{
"status": true,
"creator": "Nimesh Piyumal",
"response": "YouTube to MP3 API"
}Converts a YouTube video to MP3 and returns the direct download link.
Request Parameters
url(required): YouTube URL or video ID.quality(optional): Audio quality (default:4).format(optional):1= MP3,2= MP4 (default:1).
Request Example
GET /api/convert?url=https://www.youtube.com/watch?v=dQw4w9WgXcQ
Supported URL Formats
https://www.youtube.com/watch?v=VIDEO_IDhttps://youtu.be/VIDEO_IDhttps://youtube.com/shorts/VIDEO_IDhttps://youtube.com/embed/VIDEO_ID- Bare video ID:
dQw4w9WgXcQ
Response
{
"status": true,
"creator": "Nimesh Piyumal",
"result": {
"id": "dQw4w9WgXcQ",
"title": "Rick Astley - Never Gonna Give You Up (Official Music Video)",
"quality": 4,
"format": "mp3",
"dl_link": "https://apio11dlp.cnvmp3.online/downloads/download.php?file=/Rick Astley - Never Gonna Give You Up (Official Music Video) 4.mp3"
}
}const url = "https://ytmp3-api.<your-subdomain>.workers.dev/api/convert?url=https://www.youtube.com/watch?v=dQw4w9WgXcQ";
const response = await fetch(url);
const data = await response.json();
if (data.status) {
console.log("Title:", data.title);
console.log("Download:", data.response);
} else {
console.error("Error:", data.error);
}import requests
api_url = "https://ytmp3-api.<your-subdomain>.workers.dev/api/convert"
youtube_url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
response = requests.get(api_url, params={"url": youtube_url})
data = response.json()
if data.get("status"):
print("Title:", data["title"])
print("Download:", data["response"])
else:
print("Error:", data.get("error"))curl "https://ytmp3-api.<your-subdomain>.workers.dev/api/convert?url=https://www.youtube.com/watch?v=dQw4w9WgXcQ"MIT — free to use, modify, and deploy.
Made with ❤️ by Nimesh Piyumal