Upload audio file

February 17, 2025

Table of contents

  1. Request Headers
  2. Query Parameters
  3. Responses
  4. Model
  5. Examples
  6. Try It

You can upload the mp3, m4a and wav file types. Although there isn’t a file size limit, we recommend uploading files less than 50 MB.

POST raw content using Make.com and similar nocode tools.

https://api.useapi.net/v1/riffusion/music/upload-audio/?…

Request Headers
Authorization: Bearer {API token}
Content-Type: select from the table below
  • API token is required, see Setup useapi.net for details.
  • Content-Type is required, select from the table below:
Content-Type File Extension
audio/mp4 m4a
audio/mpeg mp3
audio/wav wav
audio/wave wav
Query Parameters
  • user_id is optional when only one account configured. However, if you have multiple accounts configured, this parameter becomes required.

  • file_name is required. Specify your file name without the extension.

Responses
  • 200 OK

    Use the returned job_id as the parameter id in GET music/upload-audio to retrieve the status of your upload. Once the response’s status field returns completed, you can provide this job_id as the parameter audio_upload_id in POST music/create-compose.

    {
        "job_id": "a5d2d4a4-6bca-501a-9c53-2f18a7a4eb00"
    }
    
  • 400 Bad Request

    {
        "error": "<Error message>",
        "code": 400
    }
    
  • 401 Unauthorized

    {
      "error": "Unauthorized",
      "code": 401
    }
    
  • 596 Pending error

    API was unable to refresh your cookie. Please resolve this issue by using the POST accounts endpoint before making any new API calls.

    {
      "error": "Your Riffusion account has pending error. Please address this issue at https://useapi.net/docs/api-riffusion-v1/post-riffusion-accounts before making any new API calls."
    }
    
Model
{ // TypeScript, all fields are optional
  job_id: string
  error: string
  code: number
}
Examples
  • curl "https://api.useapi.net/v1/riffusion/music/upload-audio/?file_name=<file_name>&user_id=<user_id>" \
      -H "Authorization: Bearer …" \
      -H "Content-Type: audio/mpeg" \
      --data-binary /path/to/your/my-music-track.mp3
    
  • const token = "API token";
    const user_id = "Previously configured account"; 
    const file_name = "Your file name"; 
    const apiUrl = `https://api.useapi.net/v1/riffusion/music/upload-audio/?file_name=${file_name}&user_id=${user_id}`; 
    let blob;
    /*
        // Example 1: Fetch audio from URL
        const audioUrl = "https://upload.wikimedia.org/wikipedia/commons/my-music-track.mp3";
        const responseAudio = await fetch(audioUrl);
        blob = await responseAudio.blob();
    */
    /* 
        // Example 2: Load audio from local file (Blob)
        const fsp = require('fs').promises;
        const audioFileName = "./my-music-track.mp3";
        blob = new Blob([await fsp.readFile(audioFileName)]);
    */
    /*
        // Example 3: Load from input file html element
        // <input id="audio-file" type="file"> 
        const audioFile = document.getElementById(`audio-file`);
        if (audioFile.files[0])
            blob = audioFile.files[0]);
    */
    const response = await fetch(apiUrl, {
      method: "POST"
      headers: {
        "Authorization": `Bearer ${token}`,
      },
      body: blob
    });
    const result = await response.json();
    console.log("response", {response, result});
    
  • import requests
    token = "API token"
    user_id = "Previously configured account"
    file_name = "Your file name"
    apiUrl = f"https://api.useapi.net/v1/riffusion/music/upload-audio/?file_name={file_name}&user_id={user_id}"
    headers = {
        'Authorization': f'Bearer {token}',
        'Content-Type': 'audio/mpeg'
    }
    
    # # Example 1: Fetch audio from URL
    # audio_url = "https://upload.wikimedia.org/wikipedia/commons/my-music-track.mp3"
    # response_audio = requests.get(audio_url)
    # file_content = response_audio.content
    
    # # Example 2: Load audio from local file
    # audio_file_path = "./my-music-track.mp3"
    # with open(audio_file_path, 'rb') as audio_file:
    #     file_content = audio_file.read()
    
    response = requests.post(api_url, headers=headers, data=file_content)
    print(response, response.json())
    
Try It