You have a feature to ship this week: turn a YouTube video into an audio file your app can download, stream, or process. By the end of this article, you’ll be able to call the Youtube to Audio API from Zyla API Hub to resolve a YouTube video into an MP3 download URL or trigger a download flow from a YouTube URL, then integrate the resulting audio into your pipeline.
What the Youtube to Audio API provides
The Youtube to Audio API exposes two simple GET endpoints that convert a YouTube video into audio. One endpoint accepts a YouTube video ID and returns a ready-to-download MP3 link plus useful metadata (title, duration, file size). The other accepts a full YouTube URL and returns a download URL you can fetch to obtain the audio.
Typical consumers include:
- Podcast clipping tools that convert long-form videos into audio highlights.
- Transcription and speech analytics services that need an MP3 before sending audio to a speech-to-text engine.
- Knowledge-base builders that index spoken content from YouTube.
- Content automation or AI agents that batch-convert video playlists into audio for downstream processing.
Getting started on Zyla API Hub
To use the endpoints, open the API’s listing on Zyla API Hub, subscribe, and get your API key. Authentication is a single HTTP header on every request: Authorization: Bearer YOUR_API_KEY. Zyla uses a subscription + quota model (not pay-per-call). The first API on your account offers a 7-day trial or 50 requests; check the API page for current access options and pricing. Start here:
Start 7-day trial on Youtube to Audio API
Endpoints you’ll use
Base: All calls are made directly to the Zyla API Hub URLs shown below. Do not add extra query parameters beyond those documented.
1) Get Audio (by YouTube video ID)
Method: GET
URL: https://zylalabs.com/api/381/youtube-to-audio-api/8884/get-audio
Description: Provide a YouTube video ID and receive an object containing a direct MP3 link and metadata. Required parameter:
- id (string): the YouTube video ID.
Official curl example:
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 JSON 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
}
How to use these fields:
- link: Direct, time-sensitive MP3 URL. Perform a second GET to download the audio bytes.
- title: Human-readable title. Useful for file naming or UI.
- duration: Video/audio length as a floating-point number (seconds).
- filesize: File size in bytes (useful for pre-allocating storage or showing progress bars).
- status/msg/progress/pc: Operational status indicators you can log or surface for debugging.
2) Download Audio (by full YouTube URL)
Method: GET
URL: https://zylalabs.com/api/381/youtube-to-audio-api/22174/download-audio
Description: Provide a full YouTube URL and receive a URL you can fetch to download the audio. Required parameter:
- url (string): full YouTube video URL.
Official curl example:
Official JSON response:
How to use this field:
- downloadUrl: Fetch this URL to retrieve the audio binary. In most apps you’ll stream the bytes to disk or to cloud storage.
Python example: resolving a YouTube ID and downloading MP3
This example shows how to call Get Audio, read the metadata, and download the MP3 file. It uses the exact endpoint and parameters shown above.
import os
import sys
import requests
API_KEY = os.getenv("ZYLALABS_API_KEY", "YOUR_API_KEY")
VIDEO_ID = "xFYQQPAOz7Y" # Provided in the official sample
OUTFILE = "audio.mp3"
session = requests.Session()
headers = {"Authorization": f"Bearer {API_KEY}"}
# 1) Resolve the YouTube ID to an MP3 link + metadata
meta_url = "https://zylalabs.com/api/381/youtube-to-audio-api/8884/get-audio"
resp = session.get(meta_url, headers=headers, params={"id": VIDEO_ID}, timeout=60)
resp.raise_for_status()
data = resp.json()
if data.get("status") != "ok" or not data.get("link"):
print("Failed to resolve audio.", file=sys.stderr)
print(data, file=sys.stderr)
sys.exit(1)
mp3_url = data["link"]
title = data.get("title")
duration = data.get("duration")
filesize = data.get("filesize")
print(f"Resolved: title={title}, duration_s={duration}, bytes={filesize}")
print("Downloading audio...")
# 2) Download the MP3 stream
with session.get(mp3_url, stream=True, timeout=120) as r:
r.raise_for_status()
with open(OUTFILE, "wb") as f:
for chunk in r.iter_content(chunk_size=1024 * 128):
if chunk:
f.write(chunk)
# 3) Optional: rename using title if provided
if title:
safe = "".join(c for c in title if c.isalnum() or c in (" ", "-", "_")).rstrip()
new_name = f"{safe}.mp3"
try:
os.replace(OUTFILE, new_name)
print(f"Saved: {new_name}")
except Exception:
print(f"Saved: {OUTFILE} (rename failed, check filesystem permissions)")
print("Done.")
Notes:
- The first request retrieves metadata and a direct MP3 link. The second request downloads the binary stream.
- Use streaming downloads for large files to avoid loading the entire file into memory.
- Use the filesize field (bytes) to pre-size progress bars. Duration is in seconds, which can help estimate transcription or processing costs.
Practical use cases you can ship this week
- Automatic transcription pipeline: Convert a YouTube video to MP3 and feed the audio into your speech-to-text service. Store the transcript for search, summarization, or QA.
- Audio clipper for newsletters: Extract audio highlights for your weekly newsletter without writing your own downloader or maintaining scrapers.
- Knowledge indexing: Convert lectures or talks to audio, then split into chunks for embedding and retrieval in your RAG stack.
- AI content enrichment: Use the MP3 as input for diarization or keyword extraction to improve content recommendations.
- Batch processing with queues: Push YouTube IDs or URLs into a queue; workers call the API, persist the audio, and emit events with the resulting file path and metadata.
Implementation details that save time
- Authentication: Always send Authorization: Bearer YOUR_API_KEY on each GET request to the Zyla endpoints.
- Two-step flow: The API returns a link or downloadUrl. Perform a second GET to that URL to retrieve the audio bytes. Handle standard HTTP behaviors (redirects, timeouts).
- File naming: Use the title field for human-friendly file names. Consider adding the YouTube ID for idempotency (e.g., "{title}-{id}.mp3").
- Storage: For cloud uploads, stream directly to your object storage SDK to avoid temporary local files. Use filesize to set Content-Length when available.
- Retries: Network hops to the download URL are outside your VPC. Implement retry with backoff on transient 5xx/connection errors.
- Sanitization: Clean user-provided URLs before passing them to the Download Audio endpoint, but do not alter the expected query parameter name (url).
- Rate and quotas: Zyla uses a subscription + quota model. Track your usage and implement circuit breakers if your workload spikes. For current options, check the API’s Marketplace page.
Choosing between the two endpoints
- If you already have a YouTube video ID, use Get Audio. You’ll get a direct MP3 link and useful metadata (duration, filesize, title) in one call.
- If your workflow starts from a pasted or discovered YouTube URL, use Download Audio. It returns a downloadUrl you can fetch to obtain the audio.
You can even combine them: normalize input into IDs where possible (for deduplication and caching), but fall back to the URL flow when users paste a full link.
Calling the API from AI agents via MCP
Every API on Zyla can also be called from AI agents through the MCP-compatible endpoint at https://mcp.zylalabs.com/mcp?apikey=YOUR_API_KEY. This works with agents in Claude Code, Cursor, Windsurf, and other MCP clients. You configure the MCP tool to issue the same HTTP GET requests shown above, with the Authorization header and the exact Zyla URLs. For details on using MCP-compatible clients with Zyla tools, start here:
Typical agent patterns:
- “Given a video ID, fetch audio and send to my transcription tool.”
- “When a YouTube link appears in a task, resolve to MP3, store to S3, and return the storage URL.”
Minimal end-to-end workflow (ID-based)
- Resolve audio:
- GET https://zylalabs.com/api/381/youtube-to-audio-api/8884/get-audio?id=YOUR_VIDEO_ID with Authorization header.
- Persist metadata:
- Store title, duration (seconds), filesize (bytes) alongside the original YouTube ID for later reference.
- Download:
- GET the link field to stream the MP3. Save to disk or object storage.
- Downstream processing:
- Kick off transcription, chunking, or embedding jobs as needed.
Operational tips
- Timeouts: Set conservative timeouts (e.g., 60s for metadata, 120s+ for large downloads) and retries with exponential backoff.
- Observability: Log request IDs and the YouTube ID/URL to trace issues. Also log filesize and duration for capacity planning.
- Caching: Cache successful resolutions keyed by YouTube ID. If a link expires, call the API again to refresh it.
- Security: Do not expose your API key client-side. Route calls through your backend service.
FAQ
Q: What authentication does the API require?
A: Send Authorization: Bearer YOUR_API_KEY on every request to the Zyla endpoints.
Q: Which parameters are required for each endpoint?
A: Get Audio requires id (YouTube video ID). Download Audio requires url (full YouTube URL). Do not add other parameters.
Q: What do duration and filesize represent?
A: duration is a floating-point number representing seconds. filesize is the audio file size in bytes.
Q: Can I stream the result directly to cloud storage?
A: Yes. Fetch the link (or downloadUrl) with streaming enabled and write chunks directly to your storage SDK.
Q: How do I try the API?
A: Subscribe on the API’s Marketplace page to get an API key. The first API on your account includes a 7-day trial or 50 requests; see the API page for current details.
If you’re ready to build, subscribe on the Marketplace item page for the Youtube to Audio API to get your key, copy the curl above, and wire it into your downloader or transcription pipeline. The 7-day trial starts on the item page, and the endpoints are ready when you are.