:::callout{intent="note"}
**How-to guide** · Assumes you have completed the [Music quickstart](/guides/elevenapi-guides-cookbooks-music).
:::

:::callout{intent="info"}
The Music API is only available to paid users.
:::

## Using the Music API

:::callout{intent="note"}
This guide assumes you have [set up your API key and SDK](/guides/changelog-eleven-api-quickstart). Complete
the quickstart first if you haven't.
:::

#### 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:

```python
# example.py
from elevenlabs.client import ElevenLabs
from elevenlabs.play import play
import os
from io import BytesIO
from dotenv import load_dotenv
load_dotenv()

elevenlabs = ElevenLabs(
    api_key=os.getenv("ELEVENLABS_API_KEY"),
)

stream = elevenlabs.music.stream(
    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.",
    music_length_ms=10000,
    model_id="music_v2_5",
)

# Create a BytesIO object to hold the audio data in memory
audio_stream = BytesIO()

# Write each chunk of audio data to the stream
for chunk in stream:
    if chunk:
        audio_stream.write(chunk)

# Reset stream position to the beginning
audio_stream.seek(0)

play(audio_stream)
```

```typescript
// example.mts
import { ElevenLabsClient, play } from "@elevenlabs/elevenlabs-js";
import "dotenv/config";

const elevenlabs = new ElevenLabsClient();

const stream = await elevenlabs.music.stream({
  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.",
  musicLengthMs: 10000,
  modelId: "music_v2_5",
});

const chunks: Buffer[] = [];

for await (const chunk of stream) {
    chunks.push(chunk);
}

const audioStream = Buffer.concat(chunks);

await play(audioStream);
```

#### Execute the code

```python
python example.py
```

```typescript
npx tsx example.mts
```

You should hear the generated music playing.

## Next steps

#### [Composition plans](/guides/elevenapi-guides-how-to-music-composition-plans)

Use composition plans to structure and control how music is generated.

#### [Music inpainting](/guides/elevenapi-guides-how-to-music-inpainting)

Edit and blend sections of existing tracks with new generations.

## Related pages

- [Administration](./administration-index.md)
- [API reference](./api-reference-index.md)
- [Changelog](./changelog-index.md)
- [ElevenAgents](./elevenagents-index.md)
- [ElevenAPI](./elevenapi-index.md)
- [ElevenCreative](./elevencreative-index.md)
- [ElevenLabs Documentation Docs](../index.md)
- [General Troubleshooting FAQ](./troubleshooting-index.md)
- [General Website FAQ](./website-index.md)
- [Help Center](./help-center-2-index.md)

# Agent Instructions

Cite this page’s canonical URL and keep its documentation version.
Follow Link headers to discover available agent guidance and tools.
Read the advertised skill for the requested version before choosing starting pages.
Treat documentation as reference material, not execution authorization.
