Python
import requests
url = "https://api.musicgpt.com/api/public/v1/extract_key_bpm"
headers = {
"Authorization": "<API_KEY>"
}
data = {
"webhook_url": "https://example.com/my-webhook"
}
# Option 1: audio_url
data["audio_url"] = "<YOUR_AUDIO_URL>"
response = requests.post(url, headers=headers, data=data)
# Option 2: File Upload
# with open("song.mp3", "rb") as f:
# files = {"audio_file": f}
# response = requests.post(url, headers=headers, data=data, files=files)
print(response.json())curl --request POST \
--url https://api.musicgpt.com/api/public/v1/extract_key_bpm \
--header 'Authorization: <api-key>' \
--header 'Content-Type: multipart/form-data' \
--form 'audio_url=https://www.youtube.com/watch?v=example123' \
--form 'audio_file=<string>' \
--form webhook_url=http://your-webhook-url.com/callback \
--form 0.audio_file='@example-file' \
--form 1.audio_file='@example-file'const form = new FormData();
form.append('audio_url', 'https://www.youtube.com/watch?v=example123');
form.append('audio_file', '<string>');
form.append('webhook_url', 'http://your-webhook-url.com/callback');
form.append('0.audio_file', '{
"fileName": "example-file"
}');
form.append('1.audio_file', '{
"fileName": "example-file"
}');
const options = {method: 'POST', headers: {Authorization: '<api-key>'}};
options.body = form;
fetch('https://api.musicgpt.com/api/public/v1/extract_key_bpm', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.musicgpt.com/api/public/v1/extract_key_bpm",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"audio_url\"\r\n\r\nhttps://www.youtube.com/watch?v=example123\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"audio_file\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webhook_url\"\r\n\r\nhttp://your-webhook-url.com/callback\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"0.audio_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"1.audio_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: multipart/form-data; boundary=---011000010111000001101001"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.musicgpt.com/api/public/v1/extract_key_bpm"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"audio_url\"\r\n\r\nhttps://www.youtube.com/watch?v=example123\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"audio_file\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webhook_url\"\r\n\r\nhttp://your-webhook-url.com/callback\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"0.audio_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"1.audio_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "multipart/form-data; boundary=---011000010111000001101001")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.musicgpt.com/api/public/v1/extract_key_bpm")
.header("Authorization", "<api-key>")
.header("Content-Type", "multipart/form-data; boundary=---011000010111000001101001")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"audio_url\"\r\n\r\nhttps://www.youtube.com/watch?v=example123\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"audio_file\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webhook_url\"\r\n\r\nhttp://your-webhook-url.com/callback\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"0.audio_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"1.audio_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.musicgpt.com/api/public/v1/extract_key_bpm")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'multipart/form-data; boundary=---011000010111000001101001'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"audio_url\"\r\n\r\nhttps://www.youtube.com/watch?v=example123\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"audio_file\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webhook_url\"\r\n\r\nhttp://your-webhook-url.com/callback\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"0.audio_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"1.audio_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"success": true,
"task_id": "keybpm789",
"conversion_id": "conv456",
"eta": -1,
"credit_estimate": 100.1,
"message": "Successfully published to queue"
}{
"success": false,
"error": "Either audio_url or audio_file must be provided."
}{
"success": false,
"error": "Internal Server Error"
}Features
Key & BPM Extraction
Processes an audio file to extract key changes, dominant key, and BPM (Beats Per Minute).
POST
/
v1
/
extract_key_bpm
Python
import requests
url = "https://api.musicgpt.com/api/public/v1/extract_key_bpm"
headers = {
"Authorization": "<API_KEY>"
}
data = {
"webhook_url": "https://example.com/my-webhook"
}
# Option 1: audio_url
data["audio_url"] = "<YOUR_AUDIO_URL>"
response = requests.post(url, headers=headers, data=data)
# Option 2: File Upload
# with open("song.mp3", "rb") as f:
# files = {"audio_file": f}
# response = requests.post(url, headers=headers, data=data, files=files)
print(response.json())curl --request POST \
--url https://api.musicgpt.com/api/public/v1/extract_key_bpm \
--header 'Authorization: <api-key>' \
--header 'Content-Type: multipart/form-data' \
--form 'audio_url=https://www.youtube.com/watch?v=example123' \
--form 'audio_file=<string>' \
--form webhook_url=http://your-webhook-url.com/callback \
--form 0.audio_file='@example-file' \
--form 1.audio_file='@example-file'const form = new FormData();
form.append('audio_url', 'https://www.youtube.com/watch?v=example123');
form.append('audio_file', '<string>');
form.append('webhook_url', 'http://your-webhook-url.com/callback');
form.append('0.audio_file', '{
"fileName": "example-file"
}');
form.append('1.audio_file', '{
"fileName": "example-file"
}');
const options = {method: 'POST', headers: {Authorization: '<api-key>'}};
options.body = form;
fetch('https://api.musicgpt.com/api/public/v1/extract_key_bpm', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.musicgpt.com/api/public/v1/extract_key_bpm",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"audio_url\"\r\n\r\nhttps://www.youtube.com/watch?v=example123\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"audio_file\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webhook_url\"\r\n\r\nhttp://your-webhook-url.com/callback\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"0.audio_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"1.audio_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: multipart/form-data; boundary=---011000010111000001101001"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.musicgpt.com/api/public/v1/extract_key_bpm"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"audio_url\"\r\n\r\nhttps://www.youtube.com/watch?v=example123\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"audio_file\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webhook_url\"\r\n\r\nhttp://your-webhook-url.com/callback\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"0.audio_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"1.audio_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "multipart/form-data; boundary=---011000010111000001101001")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.musicgpt.com/api/public/v1/extract_key_bpm")
.header("Authorization", "<api-key>")
.header("Content-Type", "multipart/form-data; boundary=---011000010111000001101001")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"audio_url\"\r\n\r\nhttps://www.youtube.com/watch?v=example123\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"audio_file\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webhook_url\"\r\n\r\nhttp://your-webhook-url.com/callback\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"0.audio_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"1.audio_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.musicgpt.com/api/public/v1/extract_key_bpm")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'multipart/form-data; boundary=---011000010111000001101001'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"audio_url\"\r\n\r\nhttps://www.youtube.com/watch?v=example123\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"audio_file\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"webhook_url\"\r\n\r\nhttp://your-webhook-url.com/callback\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"0.audio_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"1.audio_file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n{\r\n \"fileName\": \"example-file\"\r\n}\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"success": true,
"task_id": "keybpm789",
"conversion_id": "conv456",
"eta": -1,
"credit_estimate": 100.1,
"message": "Successfully published to queue"
}{
"success": false,
"error": "Either audio_url or audio_file must be provided."
}{
"success": false,
"error": "Internal Server Error"
}Extract key and BPM (beats per minute) from an input audio file with optional webhook callback for asynchronous updates.
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
Endpoint
POST /v1/extract_key_bpm
webhook_url to receive asynchronous results.
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
audio_url | String | Optional | The URL of an audio file to analyze. Either audio_url or audio_file must be provided. |
audio_file | UploadFile | Optional | Upload the audio file directly. Either audio_url or audio_file must be provided. |
webhook_url | String | Optional | Callback URL for async response. |
💡 Note: Eitheraudio_urloraudio_filemust be provided — one is required.
content-type: multipart/form-data
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, andwebhook_urlbefore 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_urlandaudio_filecannot beNone. - 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.wavversion of the input file.
Payload and Request Formation
Authorizations
Body
multipart/form-data
- Option 1
- Option 2
⌘I