POST
/
extract_key_bpm
Python
import requests

url = "https://api.musicgpt.com/api/public/v1/extract_key_bpm"
headers = {
    "Authorization": "<<<api key>>>"
}

# Option 1: URL
payload = {
    "audio_url": "https://example.com/audio.m4a",
    "webhook_url": ""
}
response = requests.post(url, headers=headers, data=payload)
print(response.json())

# Option 2: File Upload
# payload = {
#     "webhook_url": "https://www.test.requestcatcher.com/test"
# }
# with open("audio.m4a", "rb") as f:
#     files = {"audio_file": f}
#     response = requests.post(url, headers=headers, data=payload, files=files)
# print(response.json())
{
  "success": true,
  "task_id": "keybpm789",
  "conversion_id": "conv456",
  "eta": -1,
  "credit_estimate": 100.1,
  "message": "Successfully published to queue"
}

Extract key and BPM (beats per minute) from an input audio file with optional webhook callback for asynchronous updates.


Endpoint

POST /extract_key_bpm

This endpoint analyzes an audio file to determine its musical key and BPM. You can upload the audio file or provide a URL. Optionally, supply a webhook_url to receive asynchronous results.


Request Parameters

ParameterTypeRequiredDescription
audio_urlStringOptionalThe URL of an audio file to analyze. Either audio_url or audio_file must be provided.
audio_fileUploadFileOptionalUpload the audio file directly. Either audio_url or audio_file must be provided.
webhook_urlStringOptionalCallback URL for async response.

šŸ’” Note: Either audio_url or audio_file must be provided — one is required.


Sample Request

cURL

curl -X POST "https://api.musicgpt.com/api/public/v1/KeyBpmExtract" \
-H "accept: application/json" \
-H "Authorization: <api_key>" \
-F "audio_url=https://www.youtube.com/watch?v=jGflUbPQfW8" \
-F "webhook_url=http://webhook.musicgpt.com"

Python

import requests

url = "https://api.musicgpt.com/api/public/v1/extract_key_bpm"
headers = {
    "Authorization": "<<<api key>>>"
}

# Option 1: URL
payload = {
    "audio_url": "https://example.com/audio.m4a",
    "webhook_url": ""
}
response = requests.post(url, headers=headers, data=payload)
print(response.json())

# Option 2: File Upload
# payload = {
#     "webhook_url": "https://www.test.requestcatcher.com/test"
# }
# with open("audio.m4a", "rb") as f:
#     files = {"audio_file": f}
#     response = requests.post(url, headers=headers, data=payload, files=files)
# print(response.json())

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


Sample Response

Success (200 OK)

{
  "success":true,
  "task_id":"69ec90f0-a00a-48f8-bdb3-8728a635e057",
  "conversion_id":"8be8c439-dbc9-4ae6-8fe3-3fcb95f5a60a",
  "eta":-1,
  "credit_estimate":0.48,
  "message":"Successfully Published to Queue",
  "status":"IN_QUEUE"
}

Common Errors

  • 422 Unprocessable Entity: Both audio_url and audio_file cannot be None.
  • 500 Internal Server Error: A server error occurred during processing.

Webhook Response

Once key and BPM extraction is completed, the webhook receives:

{
  "success": true, 
  "task_id": "69ec90f0-a00a-48f8-bdb3-8728a635e057", 
  "conversion_id": "8be8c439-dbc9-4ae6-8fe3-3fcb95f5a60a", 
  "conversion_path": "files/a4037db1-d163-48b3-b1ba-cb93c2045228.wav", 
  "conversion_duration": "0", 
  "key_changes": {"0-120": ["A# major"], "120-140": ["D# major", "G minor"], "140-220": ["A# major", "A# minor"]}, 
  "dominant_key": "A# major", 
  "bpm": 162, 
  "conversion_type": "Key BPM Extraction"
}

Output Fields

  • key_changes: A mapping of time ranges to identified keys.
  • dominant_key: The most prominent key throughout the audio.
  • bpm: Estimated beats per minute.
  • conversion_path: Path to the original input audio file.
  • conversion_path_wav: Path to the .wav version of the input file.

Payload and Request Formation

Authorizations

Authorization
string
header
required

Body

multipart/form-data

Response

200
application/json

Successfully initiated key/bpm extraction

The response is of type object.