Skip to main content
Use the prompt parameter to define the music’s style, mood, and scenario, and the lyrics parameter to provide the vocal content.
This feature is ideal for quickly generating unique theme songs for videos, games, or applications.

Example: Text-to-Music Creation

import requests
import os

url = "https://api.minimax.io/v1/music_generation"
api_key = os.environ["MINIMAX_API_KEY"]
headers = {"Authorization": f"Bearer {api_key}"}

payload = {
"model": "music-1.5",
"prompt": "blues, melancholic, raw, lonely bar, heartbreak",
"lyrics": "[verse]\nDim lights on a dusty floor\nAnother night I walk through this door\nEmpty stool next to my hand\nJust me and this glass in this lonesome land\n[chorus]\nOh these barroom blues they fill my soul\nBroken heart taking its toll\nEvery note the jukebox cries\nJust echoes of your goodbye",
"audio_setting": {
"sample_rate": 44100,
"bitrate": 256000,
"format": "mp3"
},
}

response = requests.post(url, headers=headers, json=payload)
response.raise_for_status()
audio_hex = response.json()["data"]["audio"]

with open("output.mp3", "wb") as f:
f.write(bytes.fromhex(audio_hex))

The generated audio