Music quickstart

Learn how to generate music with Eleven Music.

This guide will show you how to generate music with Eleven Music.

The Eleven Music API is only available to paid users.

Using the Eleven Music API

1

Create an API key

Create an API key in the dashboard here, which you’ll use to securely access the API.

Store the key as a managed secret and pass it to the SDKs either as a environment variable via an .env file, or directly in your app’s configuration depending on your preference.

.env
1ELEVENLABS_API_KEY=<your_api_key_here>
2

Install the SDK

We’ll also use the dotenv library to load our API key from an environment variable.

1pip install elevenlabs
2pip install python-dotenv
3

Make the API request

Create a new file named example.py or example.mts, depending on your language of choice and add the following code:

1# example.py
2from elevenlabs.client import ElevenLabs
3from elevenlabs import play
4import os
5from dotenv import load_dotenv
6load_dotenv()
7
8elevenlabs = ElevenLabs(
9 api_key=os.getenv("ELEVENLABS_API_KEY"),
10)
11
12track = elevenlabs.music.compose(
13 prompt="Create an intense, fast-paced electronic track for a high-adrenaline video game scene. Use driving synth arpeggios, punchy drums, distorted bass, glitch effects, and aggressive rhythmic textures. The tempo should be fast, 130–150 bpm, with rising tension, quick transitions, and dynamic energy bursts.",
14 music_length_ms=10000,
15)
16
17play(track)
4

Execute the code

1python example.py

You should hear the generated music playing.

Composition plans

A composition plan is a JSON object that describes the music you want to generate in finer detail. It can then be used to generate music with Eleven Music.

Using a plan is optional, but it can be used to generate more complex music by giving you more granular control over each section of the generation.

Generating a composition plan

A composition plan can be generated from a prompt by using the API.

1from elevenlabs.client import ElevenLabs
2from elevenlabs import play
3import os
4from dotenv import load_dotenv
5load_dotenv()
6
7elevenlabs = ElevenLabs(
8api_key=os.getenv("ELEVENLABS_API_KEY"),
9)
10
11composition_plan = elevenlabs.music.composition_plan.create(
12 prompt="Create an intense, fast-paced electronic track for a high-adrenaline video game scene. Use driving synth arpeggios, punchy drums, distorted bass, glitch effects, and aggressive rhythmic textures. The tempo should be fast, 130–150 bpm, with rising tension, quick transitions, and dynamic energy bursts.",
13 music_length_ms=10000,
14)
15
16print(composition_plan)

The above will generate a composition plan similar to the following:

1{
2 "positiveGlobalStyles": [
3 "electronic",
4 "fast-paced",
5 "driving synth arpeggios",
6 "punchy drums",
7 "distorted bass",
8 "glitch effects",
9 "aggressive rhythmic textures",
10 "high adrenaline"
11 ],
12 "negativeGlobalStyles": ["acoustic", "slow", "minimalist", "ambient", "lo-fi"],
13 "sections": [
14 {
15 "sectionName": "Intro",
16 "positiveLocalStyles": [
17 "rising synth arpeggio",
18 "glitch fx",
19 "filtered noise sweep",
20 "soft punchy kick building tension"
21 ],
22 "negativeLocalStyles": ["soft pads", "melodic vocals", "ambient textures"],
23 "durationMs": 3000,
24 "lines": []
25 },
26 {
27 "sectionName": "Peak Drop",
28 "positiveLocalStyles": [
29 "full punchy drums",
30 "distorted bass stab",
31 "aggressive rhythmic hits",
32 "rapid arpeggio sequences"
33 ],
34 "negativeLocalStyles": ["smooth transitions", "clean bass", "slow buildup"],
35 "durationMs": 4000,
36 "lines": []
37 },
38 {
39 "sectionName": "Final Burst",
40 "positiveLocalStyles": [
41 "glitch stutter",
42 "energy burst vox chopped sample",
43 "quick transitions",
44 "snare rolls"
45 ],
46 "negativeLocalStyles": ["long reverb tails", "fadeout", "gentle melodies"],
47 "durationMs": 3000,
48 "lines": []
49 }
50 ]
51}

Using a composition plan

A composition plan can be used to generate music by passing it to the compose method.

1# You can pass in composition_plan or prompt, but not both.
2composition = elevenlabs.music.compose(
3 composition_plan=composition_plan,
4)
5
6play(composition)

Generating music with details

For each music generation a composition plan is created from the prompt. You can opt to retrieve this plan by using the detailed response endpoint.

1track_details = elevenlabs.music.compose_detailed(
2 prompt="Create an intense, fast-paced electronic track for a high-adrenaline video game scene. Use driving synth arpeggios, punchy drums, distorted bass, glitch effects, and aggressive rhythmic textures. The tempo should be fast, 130–150 bpm, with rising tension, quick transitions, and dynamic energy bursts.",
3 music_length_ms=10000,
4)
5
6print(track_details.json) # json contains composition_plan and song_metadata. The composition plan will include lyrics (if applicable)
7print(track_details.filename)
8# track_details.audio contains the audio bytes

Next steps

Explore the API reference for more information on the Music API and its options.