
# AI Music Generation

## Music from a prompt

Describe the music in `prompt` and set `model` to `elevenlabs-music`. The model must be named: an audio prompt without
one is read aloud as speech. The clip `length` sets the length of the track.

```json
{
    "asset": {
        "type": "audio",
        "prompt": "Warm 1970s soul instrumental, Rhodes piano and brushed drums, 92 BPM, tape saturation",
        "model": "elevenlabs-music"
    },
    "start": 0,
    "length": 30
}
```

## Writing the prompt

A prompt settles genre, mood, instrumentation, tempo and production era whether you mean it to or not. Whatever you leave
out, the model chooses, so name what you care about and let it decide the rest.

Production vocabulary changes the sound, not just the description: `dusty`, `vinyl crackle`, `sparse` and `ethereal` all
do real work. Give a BPM when timing matters, as the model holds a stated tempo closely. Naming a key helps less reliably.
The order of the ingredients doesn't matter.

**Naming a musician or band fails the generation, and so does quoting copyrighted lyrics.** Describe the era and
production style instead: `1990s trip-hop with detuned Rhodes and a heavy swung break` gets close to where a band name
would. Failed generations aren't charged.

### Instrumental only

Add `instrumental only` to the prompt, or set `forceInstrumental` to guarantee it:

```json
{
    "asset": {
        "type": "audio",
        "prompt": "Tense orchestral build, low strings and timpani",
        "model": "elevenlabs-music",
        "options": {
            "forceInstrumental": true
        }
    },
    "start": 0,
    "length": 20
}
```

`forceInstrumental` is ignored when a composition plan is set. The plan has its own way to keep a section instrumental,
described below.

## Composition plans

A prompt describes a whole track at once. A composition plan describes it section by section, so you can put a quiet
intro before a loud chorus, land a change on a cut, or place particular lyrics in a particular section. For short beds and
stings, a prompt is usually enough.

```json
{
    "asset": {
        "type": "audio",
        "prompt": "Advertisement bed",
        "model": "elevenlabs-music",
        "options": {
            "compositionPlan": {
                "positiveGlobalStyles": ["indie pop", "bright", "acoustic guitar", "hand claps", "120 BPM"],
                "negativeGlobalStyles": ["distorted", "aggressive", "lo-fi"],
                "sections": [
                    {
                        "sectionName": "Intro",
                        "positiveLocalStyles": ["sparse", "single guitar", "building"],
                        "negativeLocalStyles": ["full drums", "vocals"],
                        "durationMs": 5000,
                        "lines": []
                    },
                    {
                        "sectionName": "Chorus",
                        "positiveLocalStyles": ["full band", "layered vocal harmony", "hand claps"],
                        "negativeLocalStyles": ["sparse"],
                        "durationMs": 15000,
                        "lines": [
                            "Every morning starts the same",
                            "Until the day it doesn't"
                        ]
                    },
                    {
                        "sectionName": "Outro",
                        "positiveLocalStyles": ["fading", "single guitar", "reverb tail"],
                        "negativeLocalStyles": ["drums"],
                        "durationMs": 10000,
                        "lines": []
                    }
                ]
            }
        }
    },
    "start": 0,
    "length": 30
}
```

Every field in the plan and in each section is required. Use an empty list where there is nothing to say.

### Global and local styles

`positiveGlobalStyles` and `negativeGlobalStyles` apply to the whole track. `positiveLocalStyles` and
`negativeLocalStyles` apply to their own section only.

Put what should never change in the global lists: genre, tempo, core instruments and production character. Put what sets
one section apart from the next in the local lists: density, energy, and which instruments drop out.

Pair each positive list with a negative one. Excluding `sparse` from a chorus does as much as asking for a full band, and
an exclusion keeps something out of one section without banning it from the whole track. Keep entries to short tags, not
sentences.

### Section names and durations

Use conventional names for `sectionName`: `Intro`, `Verse`, `Chorus`, `Bridge`, `Outro`. Music models understand them as
descriptions of what a section does, so a section called `Chorus` is more likely to sound like one than a section called
`Part 2`.

`durationMs` is exact. Each section runs for the time you give it, from 3,000 to 120,000 milliseconds, and the track is
the sum of its sections. Round numbers such as multiples of five seconds are easy to line up with a timeline.

### Keeping a section instrumental

Leave the section's `lines` empty and add `vocals` to its `negativeLocalStyles`. The `Intro` and `Outro` above do this.

## Length and price

Music is charged by the clip's length, per started minute, for tracks from 3 seconds to 10 minutes. With
`"length": "auto"` and no plan, the model makes a 30-second track. With a composition plan, set the clip `length` to the
total of the section durations, since that length is what is priced. See
[pricing](/docs/guide/generating-assets/ai-generation-pricing).
