Manage your API keys
Code examples
Convert to MIDI
Model settings
#!/bin/bash
# Needs only curl, grep and sed
API=https://api.musictomidi.com/v1
KEY="YOUR_API_KEY"
AUDIOFILE_NAME="song.wav"
OPERATION="midi"
MODEL="v2"
# Job parameters, in JSON (MIDI options go in "options", e.g. "options":{"noteThreshold":0.5})
PARAMS="{\"operation\":\"$OPERATION\",\"model\":\"$MODEL\"}"
# Value of a JSON string field: echo "$JSON" | field name
field() { sed -n "s/.*\"$1\":\"\([^\"]*\)\".*/\1/p"; }
# Log line, with the elapsed time: log "text"
log() { echo "[${SECONDS}s] $*"; }
# Download a URL to a file: download "$URL" "name"
download() { log "Downloading $2..."; curl -s "$1" > "$2"; log "Saved $2"; }
# JSON string of a text, non-ASCII characters as \uXXXX: curl in Git Bash (Windows) reads only ASCII arguments
json() {
local LC_ALL=C s="$1" out="" i=0 b n k c
while ((i < ${#s})); do
c="${s:i:1}"; printf -v b '%d' "'$c"; i=$((i + 1))
if ((b >= 128)); then
# UTF-8: 2 to 4 bytes per character
if ((b >= 240)); then n=$((b & 7)); k=3; elif ((b >= 224)); then n=$((b & 15)); k=2; else n=$((b & 31)); k=1; fi
for ((; k > 0; k--)); do printf -v b '%d' "'${s:i:1}"; i=$((i + 1)); n=$(((n << 6) | (b & 63))); done
if ((n > 65535)); then n=$((n - 65536)); printf -v c '\\u%04x\\u%04x' $((0xD800 + (n >> 10))) $((0xDC00 + (n & 1023)))
else printf -v c '\\u%04x' "$n"; fi
elif ((b < 32)); then printf -v c '\\u%04x' "$b"
elif [[ $c == '"' || $c == "\\" ]]; then c="\\$c"
fi
out+="$c"
done
printf '"%s"' "$out"
}
# File name in the parameters, in any language (Chinese, Thai, Arabic...)
PARAMS="{\"name\":$(json "$AUDIOFILE_NAME"),${PARAMS#\{}"
# 1. Send the audio file and its parameters in one request (multipart/form-data): the file in the
# "file" part, the parameters in the "params" part (credits are reserved, debited only on success)
log "Uploading $AUDIOFILE_NAME (operation: $OPERATION, model: $MODEL)..."
# The file is read by bash and sent on stdin (any file name)
JOB=$(curl -# -X POST "$API/jobs" \
-H "Authorization: Bearer $KEY" -H "Idempotency-Key: midi-$(date +%s)-$RANDOM" \
-F "file=@-;filename=audio.${AUDIOFILE_NAME##*.}" -F "params=$PARAMS" < "$AUDIOFILE_NAME")
JOBID=$(echo "$JOB" | field jobId)
[ -z "$JOBID" ] && { echo "$JOB"; exit 1; }
log "Job created: $JOBID (status: $(echo "$JOB" | field status))"
# 2. Poll until done ("validating", "starting" and "running" are not final)
POLLING_URL=$API/jobs/$JOBID
while :; do
RESULT=$(curl -s "$POLLING_URL" -H "Authorization: Bearer $KEY")
STATUS=$(echo "$RESULT" | field status)
PROGRESS=$(echo "$RESULT" | sed -n "s/.*\"progress\":\([0-9.]*\).*/\1/p")
[ -n "$PROGRESS" ] && PROGRESS=" $(LC_ALL=C printf "%.0f" "${PROGRESS}e2")%"
STAGE=$(echo "$RESULT" | field stage)
# Why a job is waiting to start: gpu_capacity (all GPUs busy) or maintenance
REASON=$(echo "$RESULT" | field queuedReason)
log "Status: $STATUS$PROGRESS${STAGE:+ ($STAGE)}${REASON:+ ($REASON)}"
case "$STATUS" in
done) break ;;
validating|starting|running) sleep 3 ;;
*) echo "$RESULT"; exit 1 ;;
esac
done
# 3. Download the results (signed URLs, valid 24 h), named after the audio file
# Smart MIDI: notes quantized on the tempo detected automatically ("bpm")
download "$(echo "$RESULT" | field midiUrl)" "${AUDIOFILE_NAME%.*}.mid"
# Raw MIDI: output of the model, before filtering and quantization
download "$(echo "$RESULT" | field rawMidiUrl)" "${AUDIOFILE_NAME%.*}.raw.mid"
# Original audio: the file you sent ("audioUrl")
download "$(echo "$RESULT" | field audioUrl)" "${AUDIOFILE_NAME%.*}.original.${AUDIOFILE_NAME##*.}"Separate into stems
Stems
#!/bin/bash
# Needs only curl, grep and sed
API=https://api.musictomidi.com/v1
KEY="YOUR_API_KEY"
AUDIOFILE_NAME="song.wav"
# Job parameters, in JSON
PARAMS='{"operation":"separation","model":"separation","stems":["vocals","drums"],"mp3":true}'
# Value of a JSON string field: echo "$JSON" | field name
field() { sed -n "s/.*\"$1\":\"\([^\"]*\)\".*/\1/p"; }
# Log line, with the elapsed time: log "text"
log() { echo "[${SECONDS}s] $*"; }
# Download a URL to a file: download "$URL" "name"
download() { log "Downloading $2..."; curl -s "$1" > "$2"; log "Saved $2"; }
# JSON string of a text, non-ASCII characters as \uXXXX: curl in Git Bash (Windows) reads only ASCII arguments
json() {
local LC_ALL=C s="$1" out="" i=0 b n k c
while ((i < ${#s})); do
c="${s:i:1}"; printf -v b '%d' "'$c"; i=$((i + 1))
if ((b >= 128)); then
# UTF-8: 2 to 4 bytes per character
if ((b >= 240)); then n=$((b & 7)); k=3; elif ((b >= 224)); then n=$((b & 15)); k=2; else n=$((b & 31)); k=1; fi
for ((; k > 0; k--)); do printf -v b '%d' "'${s:i:1}"; i=$((i + 1)); n=$(((n << 6) | (b & 63))); done
if ((n > 65535)); then n=$((n - 65536)); printf -v c '\\u%04x\\u%04x' $((0xD800 + (n >> 10))) $((0xDC00 + (n & 1023)))
else printf -v c '\\u%04x' "$n"; fi
elif ((b < 32)); then printf -v c '\\u%04x' "$b"
elif [[ $c == '"' || $c == "\\" ]]; then c="\\$c"
fi
out+="$c"
done
printf '"%s"' "$out"
}
# File name in the parameters, in any language (Chinese, Thai, Arabic...)
PARAMS="{\"name\":$(json "$AUDIOFILE_NAME"),${PARAMS#\{}"
# 1. Send the audio file and its parameters in one request (multipart/form-data): the file in the
# "file" part, the parameters in the "params" part (credits are reserved, debited only on success)
log "Uploading $AUDIOFILE_NAME (operation: separation)..."
# The file is read by bash and sent on stdin (any file name)
JOB=$(curl -# -X POST "$API/jobs" \
-H "Authorization: Bearer $KEY" -H "Idempotency-Key: stems-$(date +%s)-$RANDOM" \
-F "file=@-;filename=audio.${AUDIOFILE_NAME##*.}" -F "params=$PARAMS" < "$AUDIOFILE_NAME")
JOBID=$(echo "$JOB" | field jobId)
[ -z "$JOBID" ] && { echo "$JOB"; exit 1; }
log "Job created: $JOBID (status: $(echo "$JOB" | field status))"
# 2. Poll until done ("validating", "starting" and "running" are not final)
POLLING_URL=$API/jobs/$JOBID
while :; do
RESULT=$(curl -s "$POLLING_URL" -H "Authorization: Bearer $KEY")
STATUS=$(echo "$RESULT" | field status)
PROGRESS=$(echo "$RESULT" | sed -n "s/.*\"progress\":\([0-9.]*\).*/\1/p")
[ -n "$PROGRESS" ] && PROGRESS=" $(LC_ALL=C printf "%.0f" "${PROGRESS}e2")%"
STAGE=$(echo "$RESULT" | field stage)
# Why a job is waiting to start: gpu_capacity (all GPUs busy) or maintenance
REASON=$(echo "$RESULT" | field queuedReason)
log "Status: $STATUS$PROGRESS${STAGE:+ ($STAGE)}${REASON:+ ($REASON)}"
case "$STATUS" in
done) break ;;
validating|starting|running) sleep 3 ;;
*) echo "$RESULT"; exit 1 ;;
esac
done
# 3. Download each stem: FLAC, and MP3 with mp3=true (signed URLs, valid 24 h)
echo "$RESULT" | grep -o '{[^{}]*"url":"[^{}]*}' | while read -r STEM; do
NAME=$(echo "$STEM" | field name)
download "$(echo "$STEM" | field url)" "$NAME.flac"
MP3=$(echo "$STEM" | field mp3Url)
[ -n "$MP3" ] && download "$MP3" "$NAME.mp3"
done
# Original audio: the file you sent ("audioUrl")
download "$(echo "$RESULT" | field audioUrl)" "${AUDIOFILE_NAME%.*}.original.${AUDIOFILE_NAME##*.}"Wait for a job (HTTP polling)
#!/bin/bash
# Needs only curl, grep and sed
# Usage: ./poll-job.sh <jobId> (the jobId returned by POST /v1/jobs)
API=https://api.musictomidi.com/v1
KEY="YOUR_API_KEY"
# Value of a JSON string field: echo "$JSON" | field name
field() { sed -n "s/.*\"$1\":\"\([^\"]*\)\".*/\1/p"; }
# Log line, with the elapsed time: log "text"
log() { echo "[${SECONDS}s] $*"; }
# Each GET may wait up to ~20 s; "validating", "starting" and "running" are not final
while :; do
RESULT=$(curl -s "$API/jobs/$1" -H "Authorization: Bearer $KEY")
STATUS=$(echo "$RESULT" | field status)
PROGRESS=$(echo "$RESULT" | sed -n "s/.*\"progress\":\([0-9.]*\).*/\1/p")
[ -n "$PROGRESS" ] && PROGRESS=" $(LC_ALL=C printf "%.0f" "${PROGRESS}e2")%"
STAGE=$(echo "$RESULT" | field stage)
# Why a job is waiting to start: gpu_capacity (all GPUs busy) or maintenance
REASON=$(echo "$RESULT" | field queuedReason)
log "Status: $STATUS$PROGRESS${STAGE:+ ($STAGE)}${REASON:+ ($REASON)}"
case "$STATUS" in
done) echo "$RESULT"; break ;;
validating|starting|running) sleep 3 ;;
*) echo "$RESULT"; exit 1 ;;
esac
donePricing, quotas and limits
Cost = 1 credit per started segment of the model duration, computed on the true duration measured by the service (a 100 s file in v2 costs 2 credits: one full minute + one started minute).
| Model | Operation | Credits / segment | Segment |
|---|---|---|---|
v1 | MIDI | 1 | 60 s |
v2 | MIDI | 1 | 60 s |
v3 | MIDI (GPU) | 1 | 45 s |
multitrack_transformer | MIDI multi-instruments | 1 | 20 s |
vocal_transformer | MIDI (singing voice) | 1 | 20 s |
multitrack | separation + MIDI per stem | 1 | 20 s |
separation | stems | 1 | 30 s |
Credit packs: PRO 500 credits for $4.99, PRO+ 1000 credits for $8.99, STUDIO 10000 credits for $84.99
- Free credits: included with the account at signup, no card required.
- Debit: only when the job succeeds; failed and expired jobs are refunded.
- Concurrency: the total cost of your running jobs can never be more than your credits.
- GPU capacity:
v3,multitrack_transformer,vocal_transformer,multitrackandseparationrun on shared GPUs. When they are all busy, the job waits withstatus: startingandqueuedReason: gpu_capacity, then starts by itself; keep polling the samejobId. - Job creation:
POST /v1/jobsanswers as soon as the file is uploaded: 202{jobId, status: "validating", operation, model, credits}. The file is checked after that: an unreadable file, a selection outside the file or not enough credits make the jobfailed, witherror.codeinput_file_error,invalid_requestorinsufficient_credits. ThejobIdnever changes, fromPOSTto the result. - Rate limit: 60 requests/min/key (429
rate_limited). - Keys: up to 5 active keys per account.
- Retention: 24 h for uploaded files, results and download URLs.
- Formats: audio MP3, WAV, WAVE, OGG, OGA, OPUS, FLAC, M4A, AAC, ALAC, WMA, AIF, AIFF, AIFC, CAF, AMR, AC3, MKA, WEBA, MP2, AU; video MP4, M4V, MOV, WEBM, MKV, AVI, WMV, FLV, 3GP, 3G2, MPG, MPEG, TS, MTS, M2TS, OGV, VOB (its audio track). The paid duration never exceeds the measured one.
- MP3: generated by the service (separation
mp3:true); the API never transcodes on your device. - Polling:
GET /v1/jobs/{id}. A request can take up to 20 s: it answers as soon as the job is done. No webhook in v1.
Machine-readable errors
{ "error": { "code": "insufficient_credits",
"message": "You need 2 credits, but you have only 1.",
"details": { "cost": 2, "credits": 1 } } }| Code | HTTP | Meaning |
|---|---|---|
missing_api_key / invalid_api_key | 401 | Send Authorization: Bearer mtm_prod_… (or mtm_test_…); the key is unknown |
revoked_api_key | 401 | The key has been revoked |
rate_limited | 429 | Retry later (per-minute limit) |
unknown_model / option_not_supported / option_out_of_range | 400 | Bad request body |
file_not_found / file_forbidden / file_expired | 404 / 403 / 410 | Unknown, foreign or elapsed-for-24-h file |
input_file_error | 200, status failed | Unreadable or missing audio (found while the job is checked) |
invalid_request | 200, status failed | Selection outside the audio file (found while the job is checked) |
insufficient_credits | 200, status failed | Not enough credits for this job (found while the job is checked) |
idempotency_conflict / idempotency_in_progress | 409 | Same Idempotency-Key, different body / first call still starting |
job_not_found | 404 | Job unknown for this account |
result_expired | 200, status expired | Results are only kept 24 h |
upstream_error / storage_unavailable | 502 | Conversion or storage temporarily unavailable (never exposes upstream bodies) |
paused | GET /ready 503 | Update in progress: POST /v1/jobs is still accepted, the job waits (status starting, queuedReason: maintenance); /ready answers 503 for load balancers. Queued jobs are launched by another server or after the update; nothing is lost or double-billed |