Integrate ElevenLabs Eleven Music into your applications using the fal API. This guide covers authentication, implementation patterns in Python and JavaScript, error handling with retry logic, and performance optimization for production deployment.
Integrating AI Music Generation
Text-to-music generation enables developers to programmatically create original compositions from natural language descriptions. Transformer-based architectures can generate coherent audio that maintains musical structure across extended durations by casting conditional music generation as a hierarchical sequence-to-sequence modeling task.1 Elevenlabs Music on fal provides API access to generate complete musical compositions from text prompts with durations ranging from 10 seconds to 5 minutes.
Eleven Music understands both casual descriptions and precise musical terminology. You can describe a mood ("melancholic ambient soundscape") or specify technical parameters ("120 BPM synthwave with arpeggiated bassline"). The model was developed in collaboration with labels, publishers, and artists, and is cleared for commercial uses spanning film, television, podcasts, social media, advertisements, and gaming.2
Authentication and Setup
Setting up the Elevenlabs Music API through fal requires minimal configuration. Install the client library and configure your API key.
# JavaScript/TypeScript
npm install @fal-ai/client
# Python
pip install fal-client
Set your API key as an environment variable:
export FAL_KEY="YOUR_FAL_API_KEY"
Store API keys using environment variables or secrets management services rather than hardcoding them in source files.
falMODEL APIs
The fastest, cheapest and most reliable way to run genAI models. 1 API, 100s of models
Core Implementation
The fal API uses a subscribe pattern that handles queue management and returns results when generation completes.
JavaScript
import { fal } from "@fal-ai/client";
const result = await fal.subscribe("fal-ai/elevenlabs/music", {
input: {
prompt: "Cinematic orchestral piece with soaring strings",
},
});
console.log(result.data.audio.url);
Python
import fal_client
result = fal_client.subscribe(
"fal-ai/elevenlabs/music",
arguments={
"prompt": "Energetic electronic music with pulsing synths"
}
)
print(result["audio"]["url"])
Request Parameters
The API accepts parameters that control generation output:
| Parameter | Type | Description |
|---|---|---|
| prompt | string | Natural language description of desired music. Accepts casual descriptions and technical terminology. |
| composition_plan | object | Advanced control with positive/negative global styles and section definitions. |
| instrumental | boolean | When true, generates purely instrumental tracks. |
Prompt Construction
Effective prompts can specify multiple musical attributes:
- Genre and style: "jazz fusion", "synthwave", "lo-fi hip hop"
- Tempo: "120 BPM", "slow tempo", "uptempo"
- Instrumentation: "acoustic guitar and piano", "synthesizers and drum machines"
- Mood: "melancholic", "energetic", "contemplative"
- Structure: "verse-chorus structure", "ambient soundscape", "build to crescendo"
You can also describe use cases directly: "Background music for a tech product demo, modern and professional but not distracting."
Composition Plans
For fine-grained control, use a composition plan instead of a simple prompt. Composition plans allow you to define positive and negative global styles, as well as individual sections with specific characteristics. This is useful for longer compositions requiring distinct movements or mood transitions.
Response Handling
Successful requests return a result object containing the generated audio:
{
"audio": {
"url": "https://fal.media/files/...",
"content_type": "audio/mpeg",
"file_name": "music_generated.mp3"
}
}
The audio URL provides access to the generated MP3 file. URLs remain accessible for a limited time, so download files promptly for persistent storage.
Downloading Audio
import requests
def download_audio(audio_url, filepath):
response = requests.get(audio_url, stream=True)
response.raise_for_status()
with open(filepath, 'wb') as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)
return filepath
Error Handling
Production applications should handle common error scenarios:
- HTTP 401: Invalid or missing API key
- HTTP 429: Rate limit exceeded
- HTTP 400: Invalid request parameters
- HTTP 5xx: Server errors
Implement retry logic with exponential backoff for transient failures:
import time
def generate_with_retry(prompt, max_retries=3, **kwargs):
for attempt in range(max_retries):
try:
return fal_client.subscribe(
"fal-ai/elevenlabs/music",
arguments={"prompt": prompt, **kwargs}
)
except Exception as e:
if "400" in str(e):
raise # Don't retry validation errors
if attempt < max_retries - 1:
time.sleep((2 ** attempt) * 2)
else:
raise
Performance Optimization
For applications generating multiple tracks, implement concurrent processing:
async function generateBatch(prompts) {
const promises = prompts.map((prompt) =>
fal
.subscribe("fal-ai/elevenlabs/music", {
input: { prompt },
})
.catch((err) => ({ error: err.message, prompt }))
);
return Promise.all(promises);
}
Caching
Implement caching to avoid regenerating identical requests. Use a hash of the prompt and parameters as the cache key, and store results in Redis or a similar system for production workloads. This reduces API costs and improves response times for repeated requests.
Pricing
The Elevenlabs Music API on fal is priced at $0.80 per minute of generated audio. Factor this into your application's cost model, particularly for high-volume use cases.
Production Checklist
Before deploying, verify these elements:
- Security: API keys stored in environment variables or secrets management
- Error handling: Comprehensive handling with appropriate user feedback
- Rate limiting: Request queuing or throttling within API limits
- Monitoring: Logging and alerting for API failures
- Storage: Automated download with backup strategies
- Cost controls: Budget alerts and usage monitoring
Next Steps
You now have the foundation for integrating Elevenlabs Music into your applications. Start with simple integrations generating single tracks, then test different prompt styles to understand model behavior. Add complexity incrementally with caching, request queuing, and monitoring for your specific use case.
The model's natural language understanding enables users to describe what they want conversationally, making it accessible for consumer-facing applications across content creation tools, automated video production, and dynamic game soundtracks.
Recently Added
References
-
Agostinelli, A., et al. "MusicLM: Generating Music From Text." arXiv preprint arXiv:2301.11325, 2023. https://arxiv.org/abs/2301.11325 ↩
-
ElevenLabs. "Eleven Music Documentation." ElevenLabs.io, 2025. https://elevenlabs.io/docs/overview/capabilities/music ↩

![Image-to-image editing with LoRA support for FLUX.2 [klein] 9B from Black Forest Labs. Specialized style transfer and domain-specific modifications.](/_next/image?url=https%3A%2F%2Fv3b.fal.media%2Ffiles%2Fb%2F0a8aaeb2%2FFZOclk1jcZaVZAP_C12Qe_edbbb28567484c48bd205f24bafd6225.jpg&w=3840&q=75)
![Image-to-image editing with LoRA support for FLUX.2 [klein] 4B from Black Forest Labs. Specialized style transfer and domain-specific modifications.](/_next/image?url=https%3A%2F%2Fv3b.fal.media%2Ffiles%2Fb%2F0a8aae07%2FWKhXnfsA7BNpDGwCXarGn_52f0f2fdac2c4fc78b2765b6c662222b.jpg&w=3840&q=75)
![Image-to-image editing with Flux 2 [klein] 4B Base from Black Forest Labs. Precise modifications using natural language descriptions and hex color control.](/_next/image?url=https%3A%2F%2Fv3b.fal.media%2Ffiles%2Fb%2F0a8a7f49%2FnKsGN6UMAi6IjaYdkmILC_e20d2097bb984ad589518cf915fe54b4.jpg&w=3840&q=75)
![Text-to-image generation with FLUX.2 [klein] 9B Base from Black Forest Labs. Enhanced realism, crisper text generation, and native editing capabilities.](/_next/image?url=https%3A%2F%2Fv3b.fal.media%2Ffiles%2Fb%2F0a8a7f3c%2F90FKDpwtSCZTqOu0jUI-V_64c1a6ec0f9343908d9efa61b7f2444b.jpg&w=3840&q=75)
![Image-to-image editing with Flux 2 [klein] 9B Base from Black Forest Labs. Precise modifications using natural language descriptions and hex color control.](/_next/image?url=https%3A%2F%2Fv3b.fal.media%2Ffiles%2Fb%2F0a8a7f50%2FX8ffS5h55gcigsNZoNC7O_52e6b383ac214d2abe0a2e023f03de88.jpg&w=3840&q=75)
![Text-to-image generation with Flux 2 [klein] 4B Base from Black Forest Labs. Enhanced realism, crisper text generation, and native editing capabilities.](/_next/image?url=https%3A%2F%2Fv3b.fal.media%2Ffiles%2Fb%2F0a8a7f36%2FbYUAh_nzYUAUa_yCBkrP1_2dd84022eeda49e99db95e13fc588e47.jpg&w=3840&q=75)
![Image-to-image editing with Flux 2 [klein] 4B from Black Forest Labs. Precise modifications using natural language descriptions and hex color control.](/_next/image?url=https%3A%2F%2Fv3b.fal.media%2Ffiles%2Fb%2F0a8a7f40%2F-9rbLPCsz36IFb-4t3J2L_76750002c0db4ce899b77e98321ffe30.jpg&w=3840&q=75)
![Text-to-image generation with Flux 2 [klein] 4B from Black Forest Labs. Enhanced realism, crisper text generation, and native editing capabilities.](/_next/image?url=https%3A%2F%2Fv3b.fal.media%2Ffiles%2Fb%2F0a8a7f30%2FUwGq5qBE9zqd4r6QI7En0_082c2d0376a646378870218b6c0589f9.jpg&w=3840&q=75)








