Click to run and edit this dialog:

Run in SolveIt

ElevenLabs Music v2 Installation & Setup

First, let's install the Eleven Labs Music v2 API Python lib. Uncomment the code message below and run. This only needs doing once, so you can comment it out again afterwards to prevent accidental (re)running.

# !pip install elevenlabs
Collecting elevenlabs
  Downloading elevenlabs-2.53.0-py3-none-any.whl.metadata (13 kB)
Requirement already satisfied: httpx>=0.21.2 in /usr/local/lib/python3.12/site-packages (from elevenlabs) (0.28.1)
Requirement already satisfied: pydantic>=1.9.2 in /usr/local/lib/python3.12/site-packages (from elevenlabs) (2.13.4)
Requirement already satisfied: pydantic-core>=2.18.2 in /usr/local/lib/python3.12/site-packages (from elevenlabs) (2.46.4)
Requirement already satisfied: requests>=2.20 in /usr/local/lib/python3.12/site-packages (from elevenlabs) (2.34.2)
Requirement already satisfied: typing_extensions>=4.0.0 in /usr/local/lib/python3.12/site-packages (from elevenlabs) (4.15.0)
Requirement already satisfied: websockets>=11.0 in /usr/local/lib/python3.12/site-packages (from elevenlabs) (16.0)
Requirement already satisfied: anyio in /usr/local/lib/python3.12/site-packages (from httpx>=0.21.2->elevenlabs) (4.13.0)
Requirement already satisfied: certifi in /usr/local/lib/python3.12/site-packages (from httpx>=0.21.2->elevenlabs) (2026.5.20)
Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.12/site-packages (from httpx>=0.21.2->elevenlabs) (1.0.9)
Requirement already satisfied: idna in /usr/local/lib/python3.12/site-packages (from httpx>=0.21.2->elevenlabs) (3.18)
Requirement already satisfied: h11>=0.16 in /usr/local/lib/python3.12/site-packages (from httpcore==1.*->httpx>=0.21.2->elevenlabs) (0.16.0)
Requirement already satisfied: annotated-types>=0.6.0 in /usr/local/lib/python3.12/site-packages (from pydantic>=1.9.2->elevenlabs) (0.7.0)
Requirement already satisfied: typing-inspection>=0.4.2 in /usr/local/lib/python3.12/site-packages (from pydantic>=1.9.2->elevenlabs) (0.4.2)
Requirement already satisfied: charset_normalizer<4,>=2 in /usr/local/lib/python3.12/site-packages (from requests>=2.20->elevenlabs) (3.4.7)
Requirement already satisfied: urllib3<3,>=1.26 in /usr/local/lib/python3.12/site-packages (from requests>=2.20->elevenlabs) (2.7.0)
Downloading elevenlabs-2.53.0-py3-none-any.whl (1.8 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0.0/1.8 MB ? eta -:--:--
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 MB 10.3 MB/s  0:00:00
Installing collected packages: elevenlabs
Successfully installed elevenlabs-2.53.0

Confirm package(s) are installed.

!pip list | rg eleven
elevenlabs            2.53.0

You'll also need to generate an Eleven Labs account and API key (with Music level permissions) to access the Music v2 API.

Add your API key as a new ELEVENLABS_API_KEY secret in your SolveIt dashboard. You don't need to manually import the API key as it is automatically read from your environment via the Eleven Labs API.

image.png

One-Shot Music Generation

Create music from a single prompt. This is the easiest way to generate a music clip/track. See the API docs for the full range of compose() settings.

import os
from elevenlabs.client import ElevenLabs
elevenlabs = ElevenLabs(api_key=os.getenv("ELEVENLABS_API_KEY"))
track = elevenlabs.music.compose(
    prompt="A gentle electronic ambient soundscape for studying",
    music_length_ms=30_000,
    model_id="music_v2",
)
track
<generator object MusicClient.compose at 0x78ad65fba2c0>
audio = b"".join(track)
open("study_soundscape.mp3", "wb").write(audio)
720621
from IPython.display import Audio
Audio("study_soundscape.mp3")

Composition Plan

Rather than trying to come up with the perfect text prompt to generate music, you can also specify a JSON composition plan. This is a detailed specification to help you guide the model to produce more finely-grained compositions. This can be a little tedious to create from scratch so you can use the compositionPlan.create() method to create an initial full JSON composition, which you can then refine as required.

composition_plan = elevenlabs.music.composition_plan.create(
  prompt="Create a mellow, bluesy rainy-night jazz track for focused studying. Use warm Rhodes piano chords, soft brushed drums, upright bass with a relaxed walking groove, subtle blues guitar licks, smoky saxophone or muted trumpet accents, and gentle rain-on-window ambience. Keep it instrumental, cozy, and unobtrusive, with a relaxed 70-85 bpm swing feel, rich minor-7 and dominant-7 harmonies, smooth transitions, restrained dynamics, and no big drops or distracting solos. The mood should feel like a quiet late-night café during steady rain: calm, reflective, slightly melancholic, intimate, and loop-friendly, with warm tape saturation, soft room reverb, and a soothing study-friendly atmosphere.",
  music_length_ms=30000,
  model_id="music_v2",
)

This produces a detailed composition plan that you can edit and tweak to your own specifications.

print(composition_plan.model_dump_json(indent=2))
{
  "chunks": [
    {
      "text": "[Acoustic Rain Intro]",
      "duration_ms": 10000,
      "positive_styles": [
        "mellow jazz",
        "rainy night jazz",
        "bluesy jazz",
        " Rhodes piano",
        "brushed drums",
        "upright bass walking groove",
        "relaxed swing",
        "75 bpm",
        "rain ambience",
        "cozy study music",
        "soft rain drops sound",
        "gentle Rhodes chords",
        "warm tape saturation",
        "subtle room reverb",
        "introductory mood"
      ],
      "negative_styles": [
        "vocals",
        "loud trumpet",
        "fast tempo",
        "distorting synth",
        "heavy drops",
        "shouting",
        "high energy",
        "drums",
        "bass guitar",
        "solos"
      ],
      "context_adherence": "high",
      "conditioning_ref": null,
      "condition_strength": null
    },
    {
      "text": "[Main Relaxed Groove]",
      "duration_ms": 12000,
      "positive_styles": [
        "soft brushed snare",
        "warm upright bass walking line",
        "subtle blues guitar licks",
        "muted trumpet accents",
        "calm reflective mood"
      ],
      "negative_styles": [
        "loud horns",
        "climax",
        "fast drumming"
      ],
      "context_adherence": "high",
      "conditioning_ref": null,
      "condition_strength": null
    },
    {
      "text": "[Muted Outro]",
      "duration_ms": 8000,
      "positive_styles": [
        "gentle fade out",
        "rain ambience lingering",
        "soft Rhodes chords decay",
        "peaceful resolution",
        "loop-friendly ending"
      ],
      "negative_styles": [
        "abrupt ending",
        "percussion hits"
      ],
      "context_adherence": "high",
      "conditioning_ref": null,
      "condition_strength": null
    }
  ]
}
track1 = elevenlabs.music.compose(composition_plan=composition_plan, model_id="music_v2")
track1
<generator object MusicClient.compose at 0x79ea5fa4c770>
audio = b"".join(track1)
open("rainy_blues.mp3", "wb").write(audio)
720621
from IPython.display import Audio
Audio("rainy_blues.mp3")