TutorialAudio2026

🎵 Lyria 2 Music API in JavaScript — Quick Start Guide 2026

Build production-ready AI music generation with full instrumental tracks in minutes using Lyria 2 Music via NexaAPI on RapidAPI.

Introduction

Lyria 2 Music is one of the most powerful audio AI models available today, offering AI music generation with full instrumental tracks at scale. Whether you're building a creative app, automating content production, or integrating AI into your workflow, Lyria 2 Music delivers exceptional quality and reliability.

In this guide, we'll use NexaAPI — the most cost-effective way to access Lyria 2 Music. At just $0.02 per request, NexaAPI is 2.5x cheaper vs the official API ($0.05/request), making it the smart choice for production workloads.

Prerequisites

  • Node.js 18+ (includes native fetch support)
  • npm or yarn package manager
  • A RapidAPI account (free to sign up)
  • Basic JavaScript/TypeScript knowledge

Installation

No special SDK needed — Lyria 2 Music API works with native fetch (Node.js 18+) or any HTTP client.

# Node.js 18+ has fetch built-in
# For older versions, install node-fetch:
npm install node-fetch

# Optional: TypeScript support
npm install -D typescript @types/node

Quick Start

Here's a complete working example to get you started with Lyria 2 Music in under 5 minutes:

const generateAudio = async () => {
  const response = await fetch('https://lyria-2-music.p.rapidapi.com/generate', {
    method: 'POST',
    headers: {
      'x-rapidapi-key': 'YOUR_RAPIDAPI_KEY',
      'x-rapidapi-host': 'lyria-2-music.p.rapidapi.com',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      text: 'Hello, this is a test of the text-to-speech API.',
      voice: 'en-US-Neural2-A'
    })
  });
  
  const data = await response.json();
  console.log('Audio URL:', data.url);
  return data;
};

generateAudio();

Replace YOUR_RAPIDAPI_KEY with your key fromRapidAPI.

Advanced Usage

For production applications, add error handling, TypeScript types, and environment variables:

const generateWithOptions = async (text: string, voice: string = 'en-US-Neural2-A') => {
  const response = await fetch('https://lyria-2-music.p.rapidapi.com/generate', {
    method: 'POST',
    headers: {
      'x-rapidapi-key': process.env.RAPIDAPI_KEY!,
      'x-rapidapi-host': 'lyria-2-music.p.rapidapi.com',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      text,
      voice,
      speed: 1.0,
      pitch: 0,
      format: 'mp3'
    })
  });
  
  if (!response.ok) throw new Error(`API error: ${response.status}`);
  const data = await response.json();
  return data.url;
};

Pricing Comparison

NexaAPI offers the most competitive pricing for Lyria 2 Music API access:

ProviderPrice per Request100 Requests1,000 Requests
NexaAPI (RapidAPI)$0.02$2.00$20.00
Official API$0.05$5.00$50.00

💰 Save 2.5x cheaper with NexaAPI — same quality, fraction of the cost.

Frequently Asked Questions

What audio formats does Lyria 2 Music API output?

Lyria 2 Music supports MP3, WAV, and OGG output formats. MP3 is recommended for web use due to smaller file sizes. Specify the format in your API request.

How do I stream audio output from Lyria 2 Music?

For real-time streaming, use the streaming endpoint if available. Otherwise, generate the full audio file and stream it from your server or CDN to end users.

What languages does Lyria 2 Music support?

Lyria 2 Music supports 30+ languages including English, Spanish, French, German, Japanese, Chinese, and more. Check the RapidAPI documentation for the full language list.

Start Building with Lyria 2 Music

Get instant API access at $0.02/request — 2.5x cheaper vs official pricing.

Get Lyria 2 Music API on RapidAPI

No credit card required to start • Instant access