Generate an audio (Minimax Music)

Overview

  • High-Quality Music Generation: Create music tracks based on descriptive prompts.

  • Flexible Integration: Compatible with various programming languages and frameworks.

Consumption

1 audio file will be generated for each request, consuming a total of 63 000 AI/ML Tokens.

API Reference

Examples

// npm install node-fetch form-data
import fs from "fs";
import fetch from "node-fetch";

const generateMusic = async () => {
  const url = "https://api.aimlapi.com/v2/generate/audio/minimax/generate";
  const voiceId = "vocal-2025010100000000-a0AAAaaa";
  const referInstrumental = "instrumental-2025010100000000-Aaa0aAaA";

  // Sample lyrics
  const lyrics = `
  ##
  I see a skyline painted in dreams,
  The colors shift, nothing's as it seems.
  You’re the whisper in a crowded night,
  The only constant in a world of flight.

  And I wonder, where the road will go,
  Through the chaos, you’re the one I know.

  In the future, there’s a place for us,
  Where time will fade, but not our trust.
  Through the echoes of what’s yet to be,
  You’re my forever, my destiny.
  ##
  `;

  const payload = {
    refer_voice: voiceId,
    refer_instrumental: referInstrumental,
    lyrics: lyrics,
    model: "music-01",
  };

  const apiKey = "<YOUR_API_KEY>"; 

  const headers = {
    "Content-Type": "application/json",
    "Authorization": `Bearer ${apiKey}`,
  };

  try {
    const response = await fetch(url, {
      method: "POST",
      headers: headers,
      body: JSON.stringify(payload),
    });

    const data = await response.json();

    if (response.ok) {
      const audioHex = data.data.audio;
      const decodedHex = Buffer.from(audioHex, "hex");

      // Convert to mp3
      fs.writeFileSync("generated_audio.mp3", decodedHex);
      console.log("Audio file saved as generated_audio.mp3");
    } else {
      console.error("Failed to generate music:", data);
    }
  } catch (error) {
    console.error("Error during API request:", error);
  }
}

generateMusic();

Last updated