← BPM and Key Finder
Your token

BPM and Key Finder API

Measuring tempo, key and loudness runs free in the browser and needs no API: your audio never leaves your device. The API is for the one metered step: send the measurements of three or more songs (BPM, key, Camelot code, loudness) and the page's table of how each pair fits, get back a DJ mix order with a move for every transition.

Base URL: https://api.skillsafe.ai/v1/app-api. Every response is {"data": ...} or {"error": {"code", "message"}}; read error.code and error.message rather than the HTTP status alone.

The task field

This app has one task. Always send "task": "plan_set".

taskWhat it doesReply
plan_setOrders every song once for a DJ set following your goal, and names one move per transition, chosen by fixed rules from the pair table you send. Never invents a tempo, key or song.One JSON object

Input fields

FieldTypeMeaning
taskstring"plan_set"
tracksstringJSON text: a list of {"id", "name", "bpm", "key", "camelot", "lufs", "busy", "seconds"}, at most 12. busy is sharp hits per second; lufs is integrated loudness.
goalstringYour words about the set, at most 300 characters; may be empty.
factsstringJSON text: count, bpm_min, bpm_max, tracks_total, and pairs: one {"from", "to", "key", "gap"} per ordered pair. key is same, adjacent, relative, diagonal, boost or clash on the Camelot wheel; gap is the tempo change in percent to beat-match, half and double time allowed.

The reply

job.output.output is JSON text: {"task": "plan_set", "order": [ids], "moves": [{"from", "to", "move"}], "peak": id}. Every id appears once in order; there is one move per neighbouring pair. Moves: blend (tempo gap at most 6% and keys same, adjacent, relative or diagonal), energy_lift (gap at most 6% and an energy-boost key), tempo_step (gap over 6% up to 12%, no clash), cut (any clash or a gap over 12%). The page re-checks every move against its own table and replaces any the measurements do not allow. If the balance ran low, truncated is true and the object may stop early.

Worked example

Input (input.json), for the page's five example songs:

{
  "task": "plan_set",
  "tracks": "[{\"id\":\"t1\",\"name\":\"sunrise-groove.wav\",\"bpm\":120,\"key\":\"C major\",\"camelot\":\"8B\",\"lufs\":-24.3,\"busy\":5.95,\"seconds\":14},{\"id\":\"t2\",\"name\":\"night-drive.wav\",\"bpm\":124,\"key\":\"A minor\",\"camelot\":\"8A\",\"lufs\":-21.6,\"busy\":6.16,\"seconds\":14},{\"id\":\"t3\",\"name\":\"big-room.wav\",\"bpm\":128,\"key\":\"E minor\",\"camelot\":\"9A\",\"lufs\":-18.4,\"busy\":6.38,\"seconds\":14},{\"id\":\"t4\",\"name\":\"second-wind.wav\",\"bpm\":126,\"key\":\"G major\",\"camelot\":\"9B\",\"lufs\":-18.5,\"busy\":5.23,\"seconds\":14},{\"id\":\"t5\",\"name\":\"afterglow.wav\",\"bpm\":118,\"key\":\"D minor\",\"camelot\":\"7A\",\"lufs\":-25,\"busy\":5.8,\"seconds\":14}]",
  "goal": "",
  "facts": "{\"count\":5,\"bpm_min\":118,\"bpm_max\":128,\"pairs\":[{\"from\":\"t1\",\"to\":\"t2\",\"key\":\"relative\",\"gap\":3.3},{\"from\":\"t1\",\"to\":\"t3\",\"key\":\"clash\",\"gap\":6.7},{\"from\":\"t1\",\"to\":\"t4\",\"key\":\"adjacent\",\"gap\":5},{\"from\":\"t1\",\"to\":\"t5\",\"key\":\"diagonal\",\"gap\":-1.7},{\"from\":\"t2\",\"to\":\"t1\",\"key\":\"relative\",\"gap\":-3.2},{\"from\":\"t2\",\"to\":\"t3\",\"key\":\"adjacent\",\"gap\":3.2},{\"from\":\"t2\",\"to\":\"t4\",\"key\":\"diagonal\",\"gap\":1.6},{\"from\":\"t2\",\"to\":\"t5\",\"key\":\"adjacent\",\"gap\":-4.8},{\"from\":\"t3\",\"to\":\"t1\",\"key\":\"clash\",\"gap\":-6.2},{\"from\":\"t3\",\"to\":\"t2\",\"key\":\"adjacent\",\"gap\":-3.1},{\"from\":\"t3\",\"to\":\"t4\",\"key\":\"relative\",\"gap\":-1.6},{\"from\":\"t3\",\"to\":\"t5\",\"key\":\"clash\",\"gap\":-7.8},{\"from\":\"t4\",\"to\":\"t1\",\"key\":\"adjacent\",\"gap\":-4.8},{\"from\":\"t4\",\"to\":\"t2\",\"key\":\"diagonal\",\"gap\":-1.6},{\"from\":\"t4\",\"to\":\"t3\",\"key\":\"relative\",\"gap\":1.6},{\"from\":\"t4\",\"to\":\"t5\",\"key\":\"clash\",\"gap\":-6.3},{\"from\":\"t5\",\"to\":\"t1\",\"key\":\"diagonal\",\"gap\":1.7},{\"from\":\"t5\",\"to\":\"t2\",\"key\":\"adjacent\",\"gap\":5.1},{\"from\":\"t5\",\"to\":\"t3\",\"key\":\"boost\",\"gap\":8.5},{\"from\":\"t5\",\"to\":\"t4\",\"key\":\"clash\",\"gap\":6.8}],\"tracks_total\":5}"
}

Reply:

{
  "task": "plan_set",
  "order": [
    "t5",
    "t1",
    "t2",
    "t3",
    "t4"
  ],
  "moves": [
    {
      "from": "t5",
      "to": "t1",
      "move": "blend"
    },
    {
      "from": "t1",
      "to": "t2",
      "move": "blend"
    },
    {
      "from": "t2",
      "to": "t3",
      "move": "blend"
    },
    {
      "from": "t3",
      "to": "t4",
      "move": "blend"
    }
  ],
  "peak": "t3"
}

On the page, each move is checked against the pair table and the order is shown with the tempo change and key relation of every transition.

Errors

HTTPWhat to do
401The token is missing, expired or a guest token on a run. Get a personal token on the token page.
402The balance is below what the run reserves. Top up at skillsafe.ai/account/billing.
400The body is not a JSON object of the fields above.
429Wait and retry with the same Idempotency-Key.

Step 1 — a tiny client helper

One function that sends JSON and unwraps the {data, error} envelope.

BASE="https://api.skillsafe.ai/v1/app-api"
TOKEN="paste-your-token-here"   # from https://bpm-key-finder.skillsafe.ai/tokens.html
api() { # api METHOD PATH [JSON-BODY]
  curl -s -X "$1" "$BASE$2" -H "Content-Type: application/json" \
    ${TOKEN:+-H "Authorization: Bearer $TOKEN"} ${3:+--data "$3"}
}

Step 2 — a token

A guest token is enough for /me and /estimate. A run is metered, so it needs your personal token: sign in on the token page and copy it.

# a guest token (enough for /me and /estimate); a run needs your personal token from /tokens.html
TOKEN=$(curl -s -X POST "$BASE/guest" -H "Content-Type: application/json" -d '{"slug":"bpm-key-finder"}' | jq -r '.data.token')

Step 3 — who am I, and my balance

subject_type is guest or user; credits is the balance (1 credit = $0.0001).

api GET /me | jq '.data | {subject_type, credits}' 

Step 4 — price a run for free

/estimate charges nothing and starts no job. hold_credits is the amount reserved while a run is in flight, not the price; the run is charged what it uses.

# input.json: the run input object - {"task": "plan_set", "tracks": "[...]", "goal": "...", "facts": "{...}"}
api POST /estimate "$(cat input.json)" | jq '.data | {hold_credits, min_credits, model, model_alias, markup_bps, warnings}' 

Step 5 — run it and wait for the job

Send an Idempotency-Key derived from the input: a retry with the same key is never billed twice.

KEY="bpm-key-finder:plan_set:$(shasum -a 256 input.json | cut -c1-16):a1"
JOB=$(curl -s -X POST "$BASE/run" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: $KEY" --data @input.json | jq -r '.data.job_id')
while :; do
  J=$(api GET "/jobs/$JOB"); S=$(echo "$J" | jq -r '.data.status')
  case "$S" in succeeded|failed|cancelled) break;; esac; sleep 2
done
echo "$J" | jq -r '.data.output.output' > reply.json   # one JSON object: order, moves, peak
echo "$J" | jq '.data | {charged_credits, truncated}' 

Step 6 — or stream it

/run-stream sends Server-Sent Events while the job runs and the finished job at the end.

# Server-Sent Events: tick/delta events while the job runs, then a final event with the job
curl -N -s -X POST "$BASE/run-stream" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: bpm-key-finder:plan_set:$(shasum -a 256 input.json | cut -c1-16):a1" --data @input.json