> 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.

# Musik-Schnellstart

In diesem Leitfaden erfahren Sie, wie Sie mit unserer Music API Musik generieren.

> **Tip**
>
> Verwenden Sie den [ElevenLabs-Musik-Skill](https://github.com/elevenlabs/skills/tree/main/music), um Musikstücke mit Ihrem KI-Coding-Assistenten zu generieren:
>
> ```bash
> npx skills add elevenlabs/skills --skill music
> ```

> **Info**
>
> Die Music API ist nur für zahlende Nutzer verfügbar.

## Music API verwenden

#### API-Schlüssel erstellen

[Erstellen Sie hier im Dashboard einen API-Schlüssel](https://elevenlabs.io/app/settings/api-keys), den Sie für den sicheren [Zugriff auf die API](/docs/de/api-reference/authentication) verwenden.

Speichern Sie den Schlüssel als verwaltetes Secret und übergeben Sie ihn den SDKs – je nach Wunsch entweder als Umgebungsvariable über eine `.env`-Datei oder direkt in der Konfiguration Ihrer App.

**`.env`**

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

#### SDK installieren

#### SDK

Wir verwenden außerdem die Bibliothek `dotenv`, um unseren API-Schlüssel aus einer Umgebungsvariable zu laden.

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

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

#### CLI

Installieren Sie die ElevenLabs CLI. Homebrew (macOS) und Scoop (Windows) werden empfohlen.

**`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**
>
> Arbeiten Sie mit einem KI-Coding-Assistenten? Führen Sie in Ihrem Projekt `elevenlabs generate-skills` aus, um für jede Befehlsgruppe eine
> `SKILL.md` in `skills/` zu schreiben. So kennt Ihr Assistent den gesamten Funktionsumfang der CLI,
> ohne dass Sie Dokumentation einfügen müssen. Mit `--output-dir` können Sie sie an einem anderen Ort ablegen. Dies liest die eigene
> eingebettete API-Definition der CLI, benötigt also keinen API-Schlüssel und funktioniert offline — und bleibt mit
> der von Ihnen installierten CLI-Version synchron.

Authentifizieren Sie sich anschließend — dadurch wird Ihr Browser geöffnet, um die CLI zu autorisieren:

```bash
elevenlabs auth login
```

#### API-Anfrage stellen

#### SDK

Erstellen Sie eine neue Datei mit dem Namen `example.py` oder `example.mts`, je nach verwendeter Sprache, und fügen Sie den folgenden Code hinzu:

```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"));
```

Führen Sie die Datei anschließend aus:

```python
python example.py
```

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

Sie sollten die generierte Musik hören.

#### CLI

Generieren Sie ein Stück und speichern Sie es in einer Datei:

```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
```

Öffnen Sie `music.mp3`, um das Ergebnis anzuhören.

## Kompositionspläne

Ein Kompositionsplan ist ein JSON-Objekt, das die Musik, die Sie generieren möchten, detaillierter beschreibt. Verwenden Sie Text-Prompts für schnelle Prototypen und Kompositionspläne, wenn Sie eine bestimmte Chunk-Struktur, präzises Lyrics-Timing oder komplexe Arrangements benötigen.

#### [Leitfaden für Kompositionspläne](/docs/de/eleven-api/guides/how-to/music/composition-plans)

Erfahren Sie, wie Sie Songs mit Chunks, Stilen und Lyrics für präzise Kontrolle strukturieren.

### Kompositionsplan generieren

Sie können einen Kompositionsplan mithilfe der API aus einem Prompt generieren.

```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));
```

Dadurch wird ein Kompositionsplan generiert, der etwa wie folgt aussieht:

```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"
    }
  ]
}
```

### Kompositionsplan verwenden

Sie können mit einem Kompositionsplan Musik generieren, indem Sie ihn an die Methode `compose` übergeben.

```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);
```

## Musik mit Details generieren

Bei jeder Musikgenerierung wird aus dem Prompt ein Kompositionsplan erstellt. Sie können diesen Plan über den Endpunkt für detaillierte Antworten abrufen.

```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
```

## Urheberrechtlich geschütztes Material

Der Versuch, Musik oder einen Kompositionsplan mit urheberrechtlich geschütztem Material zu generieren, führt zu einem Fehler. Dazu gehört, eine Band oder einen Musiker namentlich zu erwähnen oder urheberrechtlich geschützte Lyrics zu verwenden.

### Prompts mit urheberrechtlich geschütztem Material

In diesen Fällen gibt die API einen `bad_prompt`-Fehler zurück, der einen Vorschlag für einen alternativen Prompt enthält.

```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
  }
}
```

### Kompositionspläne mit urheberrechtlich geschütztem Material

Wenn beim Generieren eines Kompositionsplans Stile mit urheberrechtlich geschütztem Material verwendet werden, wird ein `bad_composition_plan`-Fehler zurückgegeben. Wie bei Musik-Prompts wird innerhalb des Fehlers ein vorgeschlagener Kompositionsplan `composition_plan_suggestion` zurückgegeben.

> **Warning**
>
> Bei einem Kompositionsplan oder Prompt mit schädlichem Material wird kein vorgeschlagener Prompt
> zurückgegeben.

## Nächste Schritte

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

Streamen Sie generierte Musik in Echtzeit, statt auf die vollständige Datei zu warten

#### [Musik-Inpainting](/docs/de/eleven-api/guides/how-to/music/inpainting)

Bearbeiten oder erweitern Sie bestimmte Abschnitte eines bestehenden Musikstücks

#### [API-Referenz](/docs/de/api-reference/music/compose)

Entdecken Sie alle Parameter und Antwortformate der Music API