You need to turn specific YouTube videos into downloadable audio this week—no browser hacks, no reverse engineering, just a stable API you can ship to production. By the end of this guide, you’ll be able to programmatically convert a YouTube video (≈5 minutes or shorter) to an audio file, retrieve the direct MP3 link, and integrate it into your media workflow using the Youtube Video to Audio API on Zyla API Hub.
What this API does and when to use it
The Youtube Video to Audio API converts a YouTube video (identified by its video ID) into an audio file and returns a direct URL you can download. Typical uses include:
- Extracting audio for transcription or NLP pipelines.
- Creating audio previews for content moderation or internal review tools.
- Powering media workflows where the audio track is needed independently of the video.
The API returns a JSON payload with the audio link, video title, file size, and conversion status, making it straightforward to automate post-processing such as storage, tagging, or downstream ingestion.
Getting started on Zyla API Hub
Zyla API Hub is a marketplace with more than 10,000 public APIs under one account, one API key, and a single subscription model. For this API, you authenticate with an Authorization: Bearer YOUR_API_KEY header. Billing is subscription + quota, not pay-per-call. No Free Plan. The Youtube Video to Audio API offers a 7-day trial you can start directly from the listing page.
Open the listing and start your trial here: Start 7-day trial on Youtube Video to Audio API.
Endpoint overview
The API exposes a single endpoint for converting a YouTube video to audio. Keep videos around 5 minutes or less to ensure successful conversion.
- Endpoint: Get Audio
- Method: GET
- URL: https://zylalabs.com/api/1812/youtube-video-to-audio-api/5870/get-audio
- Required query parameter:
- id (string): The YouTube video ID (e.g., p-Z3YrHJ1sU)
Important: Pass your API key in the Authorization header. The response returns a JSON object containing the direct link to the generated MP3, the original title, the file size in bytes, the conversion progress, duration in seconds, and status/message fields.
Quick start: cURL request
Use this exact request to test the flow. Replace YOUR_API_KEY with your live key from the Zyla API Hub listing.
curl -s -X GET "https://zylalabs.com/api/1812/youtube-video-to-audio-api/5870/get-audio?id=p-Z3YrHJ1sU" \
-H "Authorization: Bearer YOUR_API_KEY"
Official sample response
{
"link": "https://eta.123tokyo.xyz/get.php/9/9e/ty7nkwYqodA.mp3?cid=MmEwMTo0Zjg6YzAxMjozMmVlOjoxfE5BfERF&h=FwrcvY5cIfOO0jyXh5C-6Q&s=1737705748&n=%E2%82%B91%2C07%2C000%20_iPhone%2016%20Pro%20Max_%20USA%20to%20INDIA_%20%23shorts%20%23youtubeshorts&uT=R&uN=QWxlam9aeWxhTGFicw%3D%3D",
"title": "₹1,07,000 *iPhone 16 Pro Max* USA to INDIA! #shorts #youtubeshorts",
"filesize": 417480,
"progress": 100,
"duration": 22.896054233758,
"status": "ok",
"msg": "success"
}
What you’ll typically read from this payload:
- link: Direct MP3 URL you can download or stream.
- title: Original YouTube title (useful for naming or metadata).
- filesize: Size in bytes (validate against storage limits).
- progress: Percent completion. Expect 100 when ready.
- duration: Length in seconds (float), useful for validation/UX.
- status/msg: Operational status and message. Check for "ok" and "success" before downloading.
Python example: convert and download the MP3
This example calls the endpoint, validates the response, and downloads the MP3 to local storage. Replace YOUR_API_KEY with your key and change the video_id as needed.
import os
import sys
import time
import requests
API_KEY = os.getenv("ZYLALABS_API_KEY", "YOUR_API_KEY")
VIDEO_ID = "p-Z3YrHJ1sU" # YouTube video ID
BASE_URL = "https://zylalabs.com/api/1812/youtube-video-to-audio-api/5870/get-audio"
headers = {"Authorization": f"Bearer {API_KEY}"}
def get_audio_json(video_id: str) -> dict:
params = {"id": video_id}
r = requests.get(BASE_URL, headers=headers, params=params, timeout=30)
r.raise_for_status()
return r.json()
def download_file(url: str, dest_path: str):
with requests.get(url, stream=True, timeout=60) as r:
r.raise_for_status()
with open(dest_path, "wb") as f:
for chunk in r.iter_content(chunk_size=8192):
if chunk:
f.write(chunk)
def main():
try:
data = get_audio_json(VIDEO_ID)
except requests.HTTPError as e:
print(f"HTTP error: {e}", file=sys.stderr)
sys.exit(1)
status = data.get("status")
msg = data.get("msg")
progress = data.get("progress")
link = data.get("link")
title = data.get("title")
filesize = data.get("filesize")
duration = data.get("duration")
if status != "ok" or msg != "success" or progress != 100 or not link:
print(f"Conversion not ready or failed. status={status} msg={msg} progress={progress}", file=sys.stderr)
sys.exit(2)
# Basic filename: sanitize title to avoid path issues
safe_title = "".join(c for c in title if c.isalnum() or c in (" ", "-", "_")).rstrip()
filename = f"{safe_title or VIDEO_ID}.mp3"
print(f"Title: {title}")
print(f"Duration (s): {duration}")
print(f"File size (bytes): {filesize}")
print(f"Downloading to: {filename}")
try:
download_file(link, filename)
print("Download complete.")
except requests.HTTPError as e:
print(f"Failed to download file: {e}", file=sys.stderr)
sys.exit(3)
if __name__ == "__main__":
main()
Notes:
- id expects only the YouTube video ID (the short token in a watch URL). For example, from https://www.youtube.com/watch?v=p-Z3YrHJ1sU, pass p-Z3YrHJ1sU.
- Check progress == 100, status == "ok", and msg == "success" before downloading.
- Use the returned filesize and duration to validate business rules (e.g., reject long files, enforce storage quotas).
Practical integration details that save time
- YouTube length guidance: Use videos around 5 minutes or less; longer videos may not process successfully.
- Retry logic: If your first call returns a status that isn’t ready, implement a short backoff and retry, respecting your subscription quota.
- File handling: The link is a direct MP3 URL. Download it immediately or hand it to your storage layer (S3, GCS, etc.). Avoid hotlinking in production—cache or store the audio for reliability.
- Metadata: Use title for filenames, but always sanitize for filesystem compatibility.
- Durations and UX: Show remaining time or an ETA by approximating filesize/bitrate if you also manage streaming UI.
- Security: Keep your API key server-side. Never expose it in client-side code.
- Quota awareness: The marketplace uses a subscription + quota model. Monitor usage to prevent unexpected 429/limit scenarios.
Common workflows and use cases
Speech-to-text pipeline
Convert a short YouTube explainer into MP3, then feed the file into your transcription service. Use duration to reject uploads over your speech recognition limit before you pay compute costs downstream.
Podcast clipping and previews
Fetch short clips’ audio for editorial review. Store filename as a slug derived from title, and use filesize to estimate transfer times when rendering previews.
Compliance or moderation tools
Generate audio-only assets for ML-based classification. Keep the title as a label and store the link retrieval timestamp for audit trails.
Media backup for CMS ingestion
For articles that embed a video, store the audio alongside the post for accessibility features (audio-only versions). Validate duration against your CMS’s max length policy.
MCP: call this API from AI agents
If you build with AI coding agents or IDE-integrated copilots, you can route calls through Zyla’s MCP endpoint, which works with clients such as Claude Code, Cursor, and Windsurf. Configure your agent to call the marketplace endpoint via MCP using your API key. For reference, see: MCP. The agent should issue a GET request to the Youtube Video to Audio API’s Get Audio endpoint with the required id parameter and the Authorization: Bearer YOUR_API_KEY header. Your tool can then parse link, title, filesize, and duration to decide whether to download or pass the URL forward.
Error handling and resiliency
- Parameter validation: Ensure id is present and is a valid YouTube video ID. Strip whitespace and URL query leftovers before sending.
- Status checks: Do not assume success—confirm status, msg, and progress. Handle non-200 HTTP responses with retries where appropriate.
- Timeouts: Network requests to both the JSON endpoint and the returned MP3 link should have sane timeouts (e.g., 30–60 seconds).
- Caching: Store the JSON response alongside your downloaded file so you can display accurate title and duration without re-calling the API for the same video ID.
- Throughput: If you’re batch-processing, stagger requests to respect subscription quotas and to avoid stressing downstream storage.
Testing tips
- Use a known short video: Keep the test video under 1 minute to speed up end-to-end checks.
- Filesystem hygiene: Replace characters like slashes, colons, or emoji in the returned title to avoid errors on Windows/macOS filesystems.
- Assertions: Verify progress == 100 and that filesize is greater than zero before writing to disk.
- Observability: Log id, status, msg, duration, and filesize for triage if users report missing or corrupted audio.
Reference: Endpoint details
Get Audio
- Method: GET
- URL: https://zylalabs.com/api/1812/youtube-video-to-audio-api/5870/get-audio
- Query parameters:
- id (string, required): YouTube video ID (example: p-Z3YrHJ1sU)
- Headers:
- Authorization: Bearer YOUR_API_KEY
- Description: Converts the given YouTube video (≈5 minutes or less recommended) to audio and returns JSON with a direct MP3 link and metadata.
End-to-end checklist for production
- Obtain your API key from the Zyla listing and store it securely (env var or secret manager).
- Implement the GET call with the id parameter and Authorization header.
- Check status/msg/progress before attempting to download the file.
- Sanitize and persist title, duration, and filesize along with the audio asset.
- Add retries with backoff; monitor your subscription quota.
- Write integration tests against a stable short video ID.
- Hook up logs and alarms for HTTP errors and unexpected response shapes.
FAQ
What do I pass as the id parameter?
Pass the YouTube video ID, not the full URL. From https://www.youtube.com/watch?v=p-Z3YrHJ1sU, use p-Z3YrHJ1sU.
How long can the video be?
The endpoint notes that videos should be approximately 5 minutes or less in length.
How do I authenticate?
Use the header: Authorization: Bearer YOUR_API_KEY. Keys are issued after you subscribe to the API on Zyla API Hub.
What fields confirm a successful conversion?
Check status == "ok", msg == "success", progress == 100, and that link is present before attempting to download.
Is this pay-per-call?
No. Zyla API Hub uses a subscription + quota model. Check the API page for current access options and pricing details.
Ready to ship? Start your 7-day trial and get your API key from the listing: Start 7-day trial on Youtube Video to Audio API. Build your media pipeline with a single subscription across thousands of APIs on Zyla API Hub.