For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Connect
BlogHelp CenterAPI PricingSign up
OverviewElevenCreativeElevenAgentsElevenAPIReception AIAPI referenceChangelog
OverviewElevenCreativeElevenAgentsElevenAPIReception AIAPI referenceChangelog
  • Get started
    • Quickstart
    • Agents Quickstart
    • Choosing the right model
  • Tutorials
    • Text to Speech
    • Speech to Text
    • Speech Engine
    • Music
    • Text to Dialogue
    • Voice Changer
    • Voice Isolator
    • Dubbing
    • Sound effects
    • Forced Alignment
  • Concepts
    • Understanding audio streaming
    • Understanding latency
    • Voice cloning
  • How-to guides
  • Reference
    • Libraries & SDKs
    • Errors
    • Agent tooling
    • Webhooks
    • Zero Retention Mode
    • Breaking changes policy
    • UI components
    • Example projects
    • Next.js template
    • Showcase
  • Private deployment
    • Overview
LogoLogo
Login
Login
Connect
BlogHelp CenterAPI PricingSign up
On this page
  • Using the Eleven Music API
  • Composition plans
  • Generating a composition plan
  • Using a composition plan
  • Generating music with details
  • Copyrighted material
  • Prompts with copyrighted material
  • Composition plans with copyrighted material
  • Next steps
Tutorials

Music quickstart

Learn how to generate music with Eleven Music.
Was this page helpful?
Previous

Text to Dialogue quickstart

Learn how to generate immersive dialogue from text.
Next
Built with

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

Use the ElevenLabs music skill to generate music tracks from your AI coding assistant:

$npx skills add elevenlabs/skills --skill 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.play 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
17# Save the track to a file
18with open("path/to/music.mp3", "wb") as f:
19 for chunk in track:
20 f.write(chunk)
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. Use text prompts for quick prototyping and composition plans when you need specific section structure, precise lyrics timing, or complex arrangements.

Composition plans guide

Learn how to structure songs with sections, styles, and lyrics for precise control.

Generating a composition plan

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

1from elevenlabs.client import ElevenLabs
2from elevenlabs.play 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

Copyrighted material

Attempting to generate music or a composition plan that contains copyrighted material will result in an error. This includes mentioning a band or musician by name or using copyrighted lyrics.

Prompts with copyrighted material

In these cases, the API will return a bad_prompt error that contains a suggestion of what prompt you could use instead.

1try:
2 # This will result in a bad_prompt error
3 track = elevenlabs.music.compose(
4 prompt="A song that sounds like 'Bohemian Rhapsody'",
5 music_length_ms=10000,
6 )
7 except Exception as e:
8 if e.body['detail']['status'] == 'bad_prompt':
9 prompt_suggestion = e.body['detail']['data']['prompt_suggestion']
10 print(prompt_suggestion) # Prints: An epic rock ballad with dramatic tempo changes, operatic harmonies, and a narrative structure that blends melancholy with bursts of theatrical intensity.
11
12 # Use the prompt suggestion to generate the track instead

Composition plans with copyrighted material

If styles using copyrighted material are used when generating a composition plan, a bad_composition_plan error will be returned. Similar to music prompts, a suggested composition plan composition_plan_suggestion will be returned within the error.

In the case of a composition plan or prompt that contains harmful material, no suggested prompt will be returned.

Next steps

Stream music

Stream generated music in real time rather than waiting for the full file

Music inpainting

Modify or extend specific sections of an existing music track

API reference

Explore all Music API parameters and response formats