> This is a page from the ElevenLabs documentation. For a complete page index, fetch https://elevenlabs.io/docs/llms.txt. For the full documentation in a single file, fetch https://elevenlabs.io/docs/llms-full.txt.

# Snelstartgids voor Music

In deze gids lees je hoe je muziek genereert met onze Music API.

> **Tip**
>
> Gebruik de [ElevenLabs-muziekskill](https://github.com/elevenlabs/skills/tree/main/music) om muziektracks te genereren vanuit je AI-codeerassistent:
>
> ```bash
> npx skills add elevenlabs/skills --skill music
> ```

> **Info**
>
> De Music API is alleen beschikbaar voor betalende gebruikers.

## De Music API gebruiken

#### Een API-sleutel maken

[Maak hier een API-sleutel in het dashboard](https://elevenlabs.io/app/settings/api-keys), die je gebruikt voor veilige [toegang tot de API](/docs/nl/api-reference/authentication).

Sla de sleutel op als beheerd geheim en geef deze aan de SDK's door als omgevingsvariabele via een `.env`-bestand, of rechtstreeks in de configuratie van je app, afhankelijk van je voorkeur.

**`.env`**

```js title=".env"
ELEVENLABS_API_KEY=<your_api_key_here>
```

#### De SDK installeren

#### SDK

We gebruiken ook de `dotenv`-bibliotheek om onze API-sleutel uit een omgevingsvariabele te laden.

```python
pip install elevenlabs
pip install python-dotenv
```

```typescript
npm install @elevenlabs/elevenlabs-js
npm install dotenv
```

#### CLI

Installeer de ElevenLabs CLI. Homebrew (macOS) en Scoop (Windows) worden aanbevolen.

**`Homebrew (macOS)`**

```bash title="Homebrew (macOS)"
brew install elevenlabs/tap/elevenlabs
```

**`Scoop (Windows)`**

```powershell title="Scoop (Windows)"
scoop bucket add elevenlabs https://github.com/elevenlabs/scoop-bucket
scoop install elevenlabs
```

**`npm`**

```bash title="npm"
npm install -g @elevenlabs/cli
```

**`curl`**

```bash title="curl"
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/elevenlabs/cli/releases/latest/download/elevenlabs-cli-installer.sh | sh
```

> **Tip**
>
> Werk je met een AI-code-assistent? Voer `elevenlabs generate-skills` uit in je project om voor elke
> commandogroep een `SKILL.md` naar `skills/` te schrijven, zodat je assistent alle mogelijkheden van de CLI kent
> zonder dat je documentatie hoeft te plakken. Gebruik `--output-dir` om ze ergens anders te plaatsen. Dit leest de eigen
> ingebouwde API-definitie van de CLI, dus er is geen API-sleutel nodig en het werkt offline — en het blijft afgestemd op
> de versie van de CLI die je hebt geïnstalleerd.

Verifieer je daarna — hiermee wordt je browser geopend om de CLI te autoriseren:

```bash
elevenlabs auth login
```

#### De API-request uitvoeren

#### SDK

Maak een nieuw bestand met de naam `example.py` of `example.mts`, afhankelijk van de taal die je kiest, en voeg de volgende code toe:

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

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

track = elevenlabs.music.compose(
    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",
)

# Save the track to a file
with open("path/to/music.mp3", "wb") as f:
    for chunk in track:
        f.write(chunk)
```

```typescript
// example.mts
import { ElevenLabsClient } from "@elevenlabs/elevenlabs-js";
import { Readable } from "stream";
import { createWriteStream } from "fs";
import { pipeline } from "stream/promises";
import "dotenv/config";

const elevenlabs = new ElevenLabsClient();

const track = await elevenlabs.music.compose({
  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",
});

// Save the track to a file
await pipeline(Readable.from(track), createWriteStream("path/to/music.mp3"));
```

Voer het vervolgens uit:

```python
python example.py
```

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

Je zou de gegenereerde muziek moeten horen afspelen.

#### CLI

Genereer een track en sla deze op in een bestand:

```bash
elevenlabs music compose \
  --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 \
  --output music.mp3
```

Open `music.mp3` om het resultaat te horen.

## Compositieplannen

Een compositieplan is een JSON-object dat de muziek die je wilt genereren gedetailleerder beschrijft. Gebruik tekstprompts om snel prototypes te maken en compositieplannen wanneer je een specifieke chunkstructuur, nauwkeurige timing van songteksten of complexe arrangementen nodig hebt.

#### [Gids voor compositieplannen](/docs/nl/eleven-api/guides/how-to/music/composition-plans)

Leer hoe je nummers structureert met chunks, stijlen en songteksten voor nauwkeurige controle.

### Een compositieplan genereren

Je kunt met de API een compositieplan uit een prompt genereren.

```python
from elevenlabs.client import ElevenLabs
from elevenlabs.play import play
import os
from dotenv import load_dotenv
load_dotenv()

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

composition_plan = elevenlabs.music.composition_plan.create(
    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",
)

print(composition_plan)
```

```typescript
import { ElevenLabsClient } from "@elevenlabs/elevenlabs-js";
import "dotenv/config";

const elevenlabs = new ElevenLabsClient();

const compositionPlan = await elevenlabs.music.compositionPlan.create({
  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",
});

console.log(JSON.stringify(compositionPlan, null, 2));
```

Hiermee wordt een compositieplan gegenereerd dat vergelijkbaar is met het volgende:

```json
{
  "chunks": [
    {
      "text": "[Intro]",
      "durationMs": 3000,
      "positiveStyles": [
        "electronic",
        "fast-paced",
        "rising synth arpeggio",
        "glitch fx",
        "filtered noise sweep",
        "soft punchy kick building tension",
        "high adrenaline"
      ],
      "negativeStyles": ["soft pads", "melodic vocals", "ambient textures"],
      "contextAdherence": "high"
    },
    {
      "text": "[Peak Drop]",
      "durationMs": 4000,
      "positiveStyles": [
        "full punchy drums",
        "distorted bass stab",
        "aggressive rhythmic hits",
        "rapid arpeggio sequences"
      ],
      "negativeStyles": ["smooth transitions", "clean bass", "slow buildup"],
      "contextAdherence": "high"
    },
    {
      "text": "[Final Burst]",
      "durationMs": 3000,
      "positiveStyles": [
        "glitch stutter",
        "energy burst vox chopped sample",
        "quick transitions",
        "snare rolls"
      ],
      "negativeStyles": ["long reverb tails", "fadeout", "gentle melodies"],
      "contextAdherence": "high"
    }
  ]
}
```

### Een compositieplan gebruiken

Je kunt een compositieplan gebruiken om muziek te genereren door het door te geven aan de methode `compose`.

```python
# You can pass in composition_plan or prompt, but not both.
composition = elevenlabs.music.compose(
    composition_plan=composition_plan,
    model_id="music_v2_5",
)

play(composition)
```

```typescript
// You can pass in compositionPlan or prompt, but not both.
const composition = await elevenlabs.music.compose({
    compositionPlan,
    modelId: "music_v2_5",
});

await play(composition);
```

## Muziek met details genereren

Voor elke muziekgeneratie wordt op basis van de prompt een compositieplan gemaakt. Je kunt ervoor kiezen dit plan op te halen via het endpoint voor gedetailleerde responses.

```python
track_details = elevenlabs.music.compose_detailed(
    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",
)

print(track_details.json) # json contains composition_plan and song_metadata. The composition plan will include lyrics (if applicable)
print(track_details.filename)
# track_details.audio contains the audio bytes
```

```typescript
const trackDetails = await elevenlabs.music.composeDetailed({
  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, 30–150 bpm, with rising tension, quick transitions, and dynamic energy bursts.',
  musicLengthMs: 10000,
  modelId: "music_v2_5",
});

console.log(JSON.stringify(trackDetails.json, null, 2)); // json contains composition_plan and song_metadata. The composition plan will include lyrics (if applicable)
console.log(trackDetails.filename);
// trackDetails.audio contains the audio bytes
```

## Auteursrechtelijk beschermd materiaal

Een poging om muziek of een compositieplan te genereren dat auteursrechtelijk beschermd materiaal bevat, leidt tot een fout. Dit geldt ook voor het noemen van een band of muzikant bij naam of het gebruiken van auteursrechtelijk beschermde songteksten.

### Prompts met auteursrechtelijk beschermd materiaal

In deze gevallen retourneert de API een `bad_prompt`-fout met een suggestie voor een prompt die je in plaats daarvan kunt gebruiken.

```python
try:
    # This will result in a bad_prompt error
    track = elevenlabs.music.compose(
        prompt="A song that sounds like 'Bohemian Rhapsody'",
        music_length_ms=10000,
        model_id="music_v2_5",
    )
  except Exception as e:
      if e.body['detail']['status'] == 'bad_prompt':
          prompt_suggestion = e.body['detail']['data']['prompt_suggestion']
          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.

          # Use the prompt suggestion to generate the track instead
```

```typescript
try {
  // This will result in a bad_prompt error
  const track = await elevenlabs.music.compose({
    prompt: "A song that sounds like 'Bohemian Rhapsody'",
    musicLengthMs: 10000,
    modelId: "music_v2_5",
  });
} catch (error) {
  if (error.body.detail.status === 'bad_prompt') {
    const promptSuggestion = error.body.detail.data.prompt_suggestion;
    console.log(promptSuggestion); // Logs: An epic rock ballad with dramatic tempo changes, operatic harmonies, and a narrative structure that blends melancholy with bursts of theatrical intensity.

    // Use the prompt suggestion to generate the track instead
  }
}
```

### Compositieplannen met auteursrechtelijk beschermd materiaal

Als bij het genereren van een compositieplan stijlen met auteursrechtelijk beschermd materiaal worden gebruikt, wordt een `bad_composition_plan`-fout geretourneerd. Net als bij muziekprompts wordt binnen de fout een voorgesteld compositieplan `composition_plan_suggestion` geretourneerd.

> **Warning**
>
> Bij een compositieplan of prompt met schadelijk materiaal wordt geen voorgestelde prompt
> geretourneerd.

## Volgende stappen

#### [Muziek streamen](/docs/nl/eleven-api/guides/how-to/music/streaming)

Stream gegenereerde muziek realtime in plaats van op het volledige bestand te wachten

#### [Muziek inpainten](/docs/nl/eleven-api/guides/how-to/music/inpainting)

Wijzig of verleng specifieke delen van een bestaande muziektrack

#### [API-referentie](/docs/nl/api-reference/music/compose)

Bekijk alle parameters en responseformaten van de Music API