POST
/
file_convert
import requests

url = "https://api.example.com/api/public/v1/file_convert"
headers = {"Authorization": "<API_KEY>", "accept": "application/json"}

# Option 1: URL
response = requests.post(
    url, 
    headers=headers, 
    data={
        "audio_url": "https://example.com/audio.mp3",
        "target_format": "wav",
        "target_sr": 44100,
        "webhook_url": "http://your-webhook-url.com/callback"
    }
)

# Option 2: File Upload
with open("audio.mp3", "rb") as f:
    files = {"audio_file": f}
    data = {
        "target_format": "wav",
        "target_bit_depth": 24
    }
    response = requests.post(url, headers=headers, files=files, data=data)

print(response.json())
{
  "success": true,
  "task_id": "convert789",
  "conversion_id": "conv456",
  "output_path": "https://storage.example.com/converted/audio.wav",
  "credit_estimate": 100.1
}

Convert audio files to different formats with optional webhook support for asynchronous updates.


๐ŸŽต Endpoint

POST /file_convert

This endpoint processes an uploaded or linked audio file and converts it to a specified output format. You may also define optional parameters like sample rate and bit depth.


๐Ÿ”ข Request Parameters

ParameterTypeRequiredDescription
audio_urlStringOptionalThe URL of an audio file to convert. Either audio_url or audio_file must be provided.
audio_fileUploadFileOptionalUpload the audio file directly. Either audio_url or audio_file must be provided.
target_formatStringYesDesired output format. Supported: mp3, wav, flac, ogg, aac, webm.
target_srIntegerOptionalTarget sample rate in Hz. Defaults to original if not specified.
target_bit_depthIntegerOptionalTarget bit depth. Options: 16, 24, 32. Defaults to 16.
webhook_urlStringOptionalCallback URL to receive the result once conversion is complete.

โ–ถ๏ธ Sample Output

Listen to a real sample output:

Download Audio

๐Ÿงช Try it Yourself

Visit the File Conversion Endpoint Explorer to try your own text samples.

๐Ÿ’ก Tip: Set a webhook_url to receive results automatically when your audio is ready.


๐Ÿ“ค Sample Request

๐Ÿ‘š cURL

curl -X POST \
  -F "audio_file=@input.mp3" \
  -F "target_format=wav" \
  -F "target_sr=44100" \
  -F "webhook_url=https://yourdomain.com/webhook" \
  https://api.musicgpt.com/api/public/v1/convert

๐Ÿ Python

import requests

url = "https://api.musicgpt.com/api/public/v1/convert"

headers = {
    "accept": "application/json",
    "Authorization": "<api_key>"
}

input_audio_file = open("{path_to_your_audio_file}", "rb")

payload = {
    "audio_url": "",
    "target_format": "wav",
    "target_sr": 44100,
    "target_bit_depth": 24,
    "webhook_url": "https://yourdomain.com/webhook"
}

response = requests.post(url=url,
                         headers=headers,
                         data=payload,
                         files={"audio_file": input_audio_file})

print(response.status_code, response.json())

๐Ÿ” Replace {path_to_your_audio_file}, api_key, and webhook_url before executing.


๐Ÿ“ฅ Sample Response

โœ… Success (200 OK)

{
  "success":true,
  "task_id":"7024eac0-02e2-4811-96e3-7031f007f97f",
  "conversion_id":"a1286a84-d886-47d9-a717-77af15894cb9",
  "eta":-1,
  "credit_estimate":19.833,
  "message":"",
  "status":"IN_QUEUE"
}

๐Ÿ“ฅ Webhook Response

โœ… Success (200 OK)

{
  "success": true, 
  "conversion_id": "a1286a84-d886-47d9-a717-77af15894cb9", 
  "output_file_path": "https://lalals.s3.us-east-1.amazonaws.com/FileConversions/059ab1ef-c92d-4be4-b2f3-4fe57d26ae87.mp3", 
  "conversion_type": "File Conversion", 
  "task_id": "7024eac0-02e2-4811-96e3-7031f007f97f"
}

โŒ Common Errors

  • 400 Bad Request: Invalid request. Possibly due to missing parameters or unsupported formats.
  • 500 Internal Server Error: Server encountered an error during processing.

๐Ÿ“ž Webhook Response

Once the file conversion is completed, the webhook receives:

{
  "success": true,
  "conversion_id": "shaswatstagetestapril26",
  "output_file_path": "https://musicgpt.s3.amazonaws.com/conversions/123abc-denoise_no_noise.mp3",
  "conversion_type": "File Conversion"
}

๐Ÿ“‚ Output Fields

  • output_file_path: Direct URL to download the converted audio file.
  • conversion_type: Always File Conversion for this endpoint.
  • conversion_id: A unique ID to track the request status.

Authorizations

Authorization
string
header
required

Body

multipart/form-data

Response

200
application/json

Successfully initiated file conversion

The response is of type object.