You’ve got a media feature to ship: given a YouTube link or ID, return a downloadable MP3 and surface basic metadata (title, duration, size). By the end of this guide, you’ll call the Youtube to Audio API from Zyla API Hub to fetch a direct audio link and wire it into your app’s pipeline with a minimal, production-friendly workflow.
What the Youtube to Audio API does
The Youtube to Audio API converts a YouTube video into an audio file and returns a direct download link along with useful fields like title, duration, and file size. Teams use it to power podcasting tools, audio note capture, offline playback features, and media ingestion pipelines where the audio track is the only asset required.
On Zyla API Hub, this API is available under a single subscription-and-quota model (no pay-per-call). The first API you subscribe to on the Hub typically offers a 7-day trial or 50 requests; check the listing for the current trial. Every API you use on Zyla is accessed with the same account and API key.
Getting started on Zyla API Hub
Open the Youtube to Audio API listing on Zyla, click Subscribe or start the available trial, and grab your key. Your key goes in the Authorization header as a Bearer token. Calls are made through Zyla’s Hub URLs, not a third-party domain.
Start 7-day trial on Youtube to Audio API
Endpoints you can ship this week
The API exposes two GET endpoints via Zyla’s Hub URLs. Authentication is header-based with Authorization: Bearer YOUR_API_KEY.
1) Get Audio
- Method: GET
- URL: https://zylalabs.com/api/381/youtube-to-audio-api/8884/get-audio
- What it does: Takes a YouTube video ID and returns a direct MP3 download link and metadata.
- Required query params:
- id (string): YouTube video ID. Example: xFYQQPAOz7Y
Official curl (copy/paste):
curl -s -X GET "https://zylalabs.com/api/381/youtube-to-audio-api/8884/get-audio?id=xFYQQPAOz7Y" \
-H "Authorization: Bearer YOUR_API_KEY"
Official example response:
{
"msg": "success",
"link": "https://theta.123tokyo.xyz/get.php/d/fa/xFYQQPAOz7Y.mp3?n=Eminem%20-%20Lose%20Yourself&uT=R&uN=QWxlam9aeWxhTGFicw%3D%3D&h=TcO7xrzRPZ9cGbw2wXP93w&s=1784312338&uT=R&uN=QWxlam9aeWxhTGFicw%3D%3D",
"status": "ok",
"duration": 327.49718169275,
"title": "Eminem - Lose Yourself",
"progress": 100,
"pc": 0,
"filesize": 4181397
}
What you’ll actually use:
- link: Direct URL to the generated MP3 file. Use this to download or stream.
- title: Human-readable video title.
- duration: Audio duration in seconds (floating point).
- filesize: File size in bytes.
- status and msg: Quick health check fields; expect "ok" and "success" on success.
- progress and pc: Progress indicators you can log or ignore once progress is 100.
2) Download Audio
- Method: GET
- URL: https://zylalabs.com/api/381/youtube-to-audio-api/22174/download-audio
- What it does: Takes a full YouTube video URL and returns a downloadable audio link.
- Required query params:
- url (string): Full YouTube watch URL. Example: https://www.youtube.com/watch?v=_Yhyp-_hX2s
This is the easiest path when your UI already has a full YouTube URL. If you only have the video ID, use Get Audio.
Production-focused notes that save time
- Authentication: All requests require Authorization: Bearer YOUR_API_KEY.
- Transport: Use HTTPS Hub URLs exactly as shown. Do not call an origin host.
- Caching: If you cache responses, store the final link, title, duration, and filesize. Duration is in seconds; filesize is in bytes.
- Retries: For transient network errors, a short exponential backoff is reasonable. If status or msg indicate a non-success, surface it to the user.
- Quotas: The Hub uses subscription + quota, not pay-per-call. The first API commonly includes a 7-day trial or 50 requests. See the listing for current access options and pricing.
Minimal Python example using Get Audio
This snippet requests audio for a given video ID and streams the MP3 to disk. It uses the official Get Audio endpoint so you can paste-and-run after adding your key.
import os
import sys
import json
import time
import urllib.parse
import requests
API_KEY = os.environ.get("ZYLA_API_KEY", "YOUR_API_KEY")
VIDEO_ID = "xFYQQPAOz7Y" # Replace with your target YouTube ID
HUB_URL = "https://zylalabs.com/api/381/youtube-to-audio-api/8884/get-audio"
def get_audio_info(video_id: str):
params = {"id": video_id}
headers = {"Authorization": f"Bearer {API_KEY}"}
r = requests.get(HUB_URL, params=params, headers=headers, timeout=30)
r.raise_for_status()
return r.json()
def download_file(url: str, out_path: str):
with requests.get(url, stream=True, timeout=60) as r:
r.raise_for_status()
with open(out_path, "wb") as f:
for chunk in r.iter_content(chunk_size=8192):
if chunk:
f.write(chunk)
return out_path
def main():
info = get_audio_info(VIDEO_ID)
# Expected fields based on official sample
if info.get("status") != "ok" or info.get("msg") != "success":
print("Conversion not ready or failed:", json.dumps(info, indent=2))
sys.exit(1)
link = info["link"]
title = info.get("title", f"{VIDEO_ID}.mp3")
duration = info.get("duration") # seconds (float)
filesize = info.get("filesize") # bytes (int)
# Build a simple filename from title
safe_title = "".join(c for c in title if c.isalnum() or c in (" ", "-", "_")).rstrip()
filename = f"{safe_title}.mp3"
print(f"Downloading: {title}")
print(f"Duration (s): {duration}")
print(f"Reported size (bytes): {filesize}")
print(f"Source link: {link}")
path = download_file(link, filename)
print(f"Saved to: {path}")
if __name__ == "__main__":
main()
Picking the right endpoint for your flow
- If your UI captures a full YouTube link (watch URL), call Download Audio to get a download URL directly with the url parameter.
- If you only have the video ID (e.g., parsed elsewhere or stored in your DB), use Get Audio with the id parameter to also retrieve metadata like duration and filesize.
Calling from an AI agent with MCP
You can trigger the same Hub endpoints from any MCP-compatible client (Claude Code, Cursor, Windsurf, etc.) using the Zyla MCP service. Configure your client to point to MCP, pass your Zyla API key, and invoke the Hub paths shown above. For setup details, see the MCP page.
End-to-end example task
Task: given a YouTube link, store an MP3 and log basic metadata for a media library.
- Parse the input. If it contains a full watch URL, call Download Audio with the url parameter. If you only have the video ID, call Get Audio with id.
- On success, persist:
- Title (title)
- Duration in seconds (duration)
- File size in bytes (filesize)
- Source and download URL (link)
- Download the MP3 from link and store in your object storage or local media folder.
- Record a checksum if you need duplicate detection. Use filesize as a quick heuristic for changes.
Operational considerations
- Timeouts: Network variability is a reality when transferring media. Use reasonable timeouts and retries for the final link download step.
- Backpressure: If your queue spikes (e.g., many conversions), process in batches and respect your subscription quota on Zyla.
- Observability: Log status, msg, and progress from Get Audio to quickly identify intermittent issues.
- Security: Keep your API key in a secure store or environment variable; never hardcode it in client-side code.
- Resilience: If you cache the response, store both title and duration so you can render metadata even if you wait to download the file later.
Quick reference
- Hub base for this listing: https://zylalabs.com/api/381/youtube-to-audio-api/
- Get Audio: GET /8884/get-audio?id=VIDEO_ID
- Download Audio: GET /22174/download-audio?url=YOUTUBE_WATCH_URL
- Auth header: Authorization: Bearer YOUR_API_KEY
- Response fields you’ll likely persist: link, title, duration (seconds), filesize (bytes)
Why use Zyla API Hub for media tasks
Zyla centralizes more than 10,000 public APIs under one account and one key, so you can add adjacent features without redoing authentication or billing. The Youtube to Audio API slots into that workflow with the same Authorization header you already use elsewhere on the Hub. Explore more media capabilities later, but ship this conversion path first.
Browse the catalog on Zyla API Hub and add APIs with consistent subscription + quota billing (no per-call surprises).
FAQ
Q: What’s the difference between Get Audio and Download Audio?
A: Get Audio accepts a video ID and returns the direct link plus metadata (title, duration, filesize). Download Audio accepts a full YouTube URL and returns a downloadable audio link.
Q: Which fields should I store for a media library?
A: Store link (download URL), title, duration (in seconds), and filesize (in bytes). These are returned by Get Audio in the official sample.
Q: How do I authenticate?
A: Add Authorization: Bearer YOUR_API_KEY to every request you send to the Hub URLs.
Q: Is there a free plan?
A: The Hub uses subscription + quota. The first API typically offers a 7-day trial or 50 requests—check the API page for current access options and pricing.
Q: Can I trigger this from an AI coding agent?
A: Yes. Configure your MCP-compatible client to use Zyla’s MCP service and call the Hub endpoints. See the MCP page for setup.
Ready to wire this into your media workflow? Subscribe and grab your key on the Youtube to Audio API listing, start the 7-day trial, and ship the conversion feature today.