Generate music using ElevenLabs Music API - instrumental tracks, songs with lyrics, and fine-grained composition plans
95
93%
Does it follow best practices?
Impact
99%
2.30xAverage score across 5 eval scenarios
Passed
No known issues
npm install @elevenlabs/elevenlabs-jsImportant: Always use
@elevenlabs/elevenlabs-js. The oldelevenlabsnpm package (v1.x) is deprecated and should not be used.
import { ElevenLabsClient } from "@elevenlabs/elevenlabs-js";
// Option 1: Environment variable (recommended)
// Set ELEVENLABS_API_KEY in your environment
const client = new ElevenLabsClient();
// Option 2: Pass directly
const client = new ElevenLabsClient({ apiKey: "your-api-key" });pip install elevenlabsfrom elevenlabs import ElevenLabs
# Option 1: Environment variable (recommended)
# Set ELEVENLABS_API_KEY in your environment
client = ElevenLabs()
# Option 2: Pass directly
client = ElevenLabs(api_key="your-api-key")Set your API key as an environment variable:
export ELEVENLABS_API_KEY="your-api-key"Include in requests via the xi-api-key header:
curl -X POST "https://api.elevenlabs.io/v1/music" \
-H "xi-api-key: $ELEVENLABS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"prompt": "A chill lo-fi beat", "music_length_ms": 30000}'Or use the setup-api-key skill for guided setup.
Note: Music generation requires a paid ElevenLabs plan.