Skip to main content
ai-music-api/generate-midi-from-audio turns the stems of a vocal and instrument separation (ai-music-api/separate-vocals) into structured MIDI data: it detects the instruments (drums, bass, guitar, keyboards and more) and gives every note’s pitch (MIDI note number), start and end time (seconds) and velocity (0–1). It suits transcription, notation, rearranging, remixing and music education. First separate the audio with the stem separation endpoint, then pass the separation task’s task_id and the audio_id of one of its stems. Clean, well-separated stems with clear instrument parts give the best results; which instruments are detected depends on the audio.

Setup

The Suno endpoints use an asynchronous task protocol: every endpoint creates its task with POST /api/v1/jobs/createTask (model selects the endpoint and the parameters go in input) and is queried with GET /api/v1/jobs/recordInfo?taskId=; with callBackUrl the result is pushed to that URL when the task finishes. See the Suno introduction for the flow, chaining tasks and how long files are kept. The base URL is https://api.dreamto.ai; send the API Key in the Authorization: Bearer header. Every response has HTTP status 200; the code in the body tells the outcome: 200 is success, anything else an error (see the response examples of each endpoint).

Parameters

model is ai-music-api/generate-midi-from-audio; the parameters go in input. Requests that break a rule return code: 422; no task is created or charged.

Pricing

Billed per request: each succeeded task is charged once at the model price shown in the console. The balance is checked for that price when the task is created (code: 402 when insufficient); invalid requests and failed tasks are not charged. This endpoint is free (the separation task is billed at its own price).

Quick start

Create a task to get data.taskId, poll about every 10 seconds and read response once state is success; or pass callBackUrl to be called back when the task finishes. $DREAMTO_API_KEY is your API Key.

Callback

Pass callBackUrl (a public http / https URL) when creating the task; when the task succeeds or fails DreamTo POSTs the result there once (callback format): on success the body is {"code": 200, "msg": "success", "data": {"taskId", "instruments"}}, with data.taskId the task ID and instruments the detected instruments and their notes (name, notes[].pitch/start/end/velocity); on failure code is the failure code (not 200), msg the reason and data holds only taskId. The request carries X-DreamTo-Event: task.completed, X-DreamTo-Timestamp (UTC, RFC 3339) and X-DreamTo-Signature:
status is success when the task succeeded and failed when it failed. The secret is generated in the DreamTo console; without one no signature header is sent. Answer with any 2xx to acknowledge; otherwise the callback is retried.

Notes

  • Pass both task_id and audio_id: in our tests a task with only task_id (no stem) may fail. Convert the stems of one separation one by one if you need several.
  • response.resultObject of the query endpoint is a summary (state and instrument_count, the number of detected instruments); the notes are delivered in the success callback as data.instruments[].notes[], so pass callBackUrl when creating the task.
  • A note’s start / end are seconds from the beginning of the audio; pitch is the MIDI note number (0–127, middle C is 60); velocity is 0–1, with 1 the maximum. Some instruments may have no notes.
  • taskId is issued by DreamTo (32 hex digits) and can only be queried with an API Key of the same account; an unknown or expired task returns code: 422 with msg: recordInfo is null.
  • The body accepts only model, callBackUrl and input; undeclared input fields, wrong types and values that break a rule return code: 422 with an English reason in msg; no task is created or charged.
  • Every file link in a result (audio, cover image, video and so on) is a DreamTo download link (/v1/tasks/{task_id}/artifacts/...) that works without an API Key and supports Range; files are kept for 14 days after the task is created, so download them promptly.
  • param echoes the create request, with input as a JSON string that needs a second parse; the credits used are not returned, and the charge is shown in the DreamTo console bills.
  • failCode / failMsg of a failed task come from the model service (content moderation, a source audio that cannot be downloaded and so on); internal errors are reported as failCode: "500" with failMsg: "Internal Error, Please try again later.".