Upload audio (Minimax Music)

API Reference

post

/v2/generate/audio/minimax/upload

Authorizations
Body
purposeenumrequired
  1. If purpose is song:
  • You need to upload a music file containing both acapella (vocals) and accompaniment.
  • The acapella must be in singing form; normal speech is not supported.
  • Outputs: voice_id and instrumental_id.
  1. If purpose is voice:
  • You need to upload a file containing only acapella in singing form (normal speech audio is not supported).
  • Output: voice_id.
  1. If purpose is instrumental:
  • You need to upload a file containing only accompaniment.
  • Output: instrumental_id.
Options: song, voice, instrumental
Responses
curl -L \
  --request POST \
  --url 'https://api.aimlapi.com/v2/generate/audio/minimax/upload' \
  --header 'Authorization: Bearer JWT' \
  --header 'Content-Type: application/json' \
  --data '{"purpose":"song"}'
{
  "voice_id": "vocal-2025011003141025-d5ZEMxmp",
  "instrumental_id": "instrumental-2025011003141125-Akz9eWnD",
  "base_resp": {
    "status_code": 1,
    "status_msg": "text"
  }
}

Examples

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

const upload = async () => {
  const url = "https://api.aimlapi.com/v2/generate/audio/minimax/upload";
  const fileName = "filename.mp3";
  const filePath = path.resolve(fileName); // Path to your file

  const purpose = "song"; // Possible values: "song", "voice", "instrumental"

  const formData = new FormData();
  formData.append("purpose", purpose);
  formData.append("file", fs.createReadStream(filePath), {
    filename: fileName,
    contentType: "audio/mpeg",
  });

  const apiKey = "<YOUR_API_KEY>"; 

  try {
    const response = await fetch(url, {
      method: "POST",
      headers: {
        Authorization: `Bearer ${apiKey}`,
        ...formData.getHeaders(),
      },
      body: formData,
    });

    if (response.ok) {
      const data = await response.json();
      console.log("Upload successful:", data);
    } else {
      console.error("Upload failed:", response.status, await response.text());
    }
  } catch (error) {
    console.error("Error during upload:", error.message);
  }
}

upload();
// npm install node-fetch form-data
import fs from "fs";
import path from "path";
import fetch from "node-fetch";
import FormData from "form-data";

const upload = async () => {
  const url = "https://api.aimlapi.com/v2/generate/audio/minimax/upload";
  const audioUrl = "url_to_file.mp3";  // Replace with the actual URL of the file
  const fileName = "filename.mp3";  // The name you want to give to the uploaded file
  const purpose = "song"; // Possible values: "song", "voice", "instrumental"

  const apiKey = "<YOUR_API_KEY>";  // Replace with your actual API key

  try {
  // Download the file from the URL
  const response = await fetch(audioUrl);
  if (!response.ok) {
    throw new Error(`Failed to fetch file from URL: ${audioUrl}`);
  }
  
  const fileBuffer = await response.arrayBuffer(); // Get the file as a buffer

  // Upload the file to the server using FormData
  const formData = new FormData();
  formData.append("purpose", purpose);
  formData.append("file", Buffer.from(fileBuffer), {
    filename: fileName,
    contentType: "audio/mpeg",
  });

  const uploadResponse = await fetch(url, {
    method: "POST",
    headers: {
    Authorization: `Bearer ${apiKey}`,
    ...formData.getHeaders(),
    },
    body: formData,
  });

  if (uploadResponse.ok) {
    const data = await uploadResponse.json();
    console.log("Upload successful:", data);
  } else {
    console.error("Upload failed:", uploadResponse.status, await uploadResponse.text());
  }
  } catch (error) {
  console.error("Error during upload:", error);
  }
};

upload();

Last updated

Was this helpful?