A text to music API turns a sentence into an audio file. With Mubert API v3, one POST with a text prompt of up to 255 characters and a duration of at least 5 seconds becomes a music track, which you collect by polling or through a webhook. This post is for developers and product teams putting generated music into an app, a game or a video tool. It covers the request, the wait, the formats and the licence. Plus the gotchas, because there are some.
The first surprise is the receipt. Your POST returns a track whose download URL is still empty. Generation is asynchronous. Everything below turns that receipt into an MP3 before the link expires.


Every text to music API call needs two kinds of credentials
Every call to this text to music API needs a customer-id and an access-token header. You get both by creating a customer with your company’s company-id and license-token, as the v3 reference describes. All four go in headers. Never put them in the query string, because URLs end up in logs.
So there are two layers. The service layer is your company and your licence. The public layer is one customer, usually one user of your product. You create it like this:
curl -X POST https://music-api.mubert.com/api/v3/service/customers \
-H "company-id: $MUBERT_COMPANY_ID" \
-H "license-token: $MUBERT_LICENSE_TOKEN" \
-d '{"custom_id": "user12345"}' -H "Content-Type: application/json"
The custom_id must be unique and alphanumeric, up to 255 characters. The response holds the customer_id and access_token for every generation call. Keep the licence token on your server. It is the master key, and a mobile app bundle is a fine place to lose it.
Keep IDs stable, too. The MCP connection page warns that every new customer consumes a seat. Create one on every app launch and you get a very large customer list, then a very awkward call with whoever pays the bill.
The request is one POST with a prompt and a duration
You generate with POST /api/v3/public/tracks, and duration is the only required field. Most apps add a text prompt to tell the API what music to make, though an image or a playlist_index also works. The OpenAPI spec lists the fields:
prompt: text, up to 255 charactersduration: seconds, minimum 5mode: track, jingle, loop or mixformat: mp3 or wavbitrate: 32, 96, 128, 192, 256 or 320intensity: low, medium or highplaylist_indexorimageinstead of a prompt
Then a full call looks like this:
curl -X POST https://music-api.mubert.com/api/v3/public/tracks \
-H "customer-id: $CUSTOMER_ID" \
-H "access-token: $ACCESS_TOKEN" \
-d '{
"prompt": "warm lo-fi hip hop with soft piano for a study timer",
"duration": 60,
"mode": "track",
"format": "mp3",
"bitrate": 320,
"intensity": "medium"
}' -H "Content-Type: application/json"
One rule catches nearly everyone. prompt cannot be combined with bpm or key, and bpm only works with playlist_index. If your product needs an exact tempo (a running app at 160 steps a minute, say), generate from a playlist and pass bpm there. The text field is for describing the music. What a model does with adjectives is its own topic, and we covered it in which words in a music prompt actually change the track.
The spec allows a bpm of up to 500. We have not yet seen a 500 BPM meditation app, and we are not sure the world is ready for one. Anyway.
Polling every 5 seconds is the simplest text to music API loop
The simplest way to get the file is to call GET /api/v3/public/tracks/{id} about every 5 seconds and stop after a few minutes. That is the advice in the generate skill. Each track carries a generations array. Every generation has a status of processing, done or failed, plus a url that stays null until it is ready. Asynchronous is normal for any text to music API, because rendering audio takes longer than a web request should.
A trimmed response, showing only the fields from the spec:
{
"data": {
"id": "…",
"generations": [
{
"session_id": "…",
"format": "mp3",
"bitrate": 320,
"status": "done",
"url": "https://…",
"expired_at": "…"
}
]
}
}
And the loop, in the plainest JavaScript we could write:
async function waitForTrack(id, headers, timeoutMs = 180000) {
const start = Date.now();
while (Date.now() - start < timeoutMs) {
const res = await fetch(`https://music-api.mubert.com/api/v3/public/tracks/${id}`, { headers });
const gen = (await res.json()).data.generations[0];
if (gen.status === "done") return gen;
if (gen.status === "failed") throw new Error("generation failed");
await new Promise(r => setTimeout(r, 5000));
}
throw new Error("timed out");
}
Confession: our first prototype polled every 200 milliseconds, because waiting felt rude. It wasn’t rude. It just made the logs longer while the track took exactly as long as it was always going to take. Five seconds is plenty.
There is also a lookup by session: GET /api/v3/public/tracks/session/{session_id}. Still, don’t mix the two up. Pass a session_id to the UUID route and the skill says you get a 404, plus an hour of debugging.
A webhook replaces the polling loop, mostly
If you would rather be told than keep asking, set webhook_url (up to 255 characters) and webhook_enabled on PUT /api/v3/service/licenses/{license}. Then, per the v3 reference, webhooks “receive track models when generation completes”. Three trade-offs come with it. Know them before you delete your polling code.
First, the webhook belongs to the licence, not to a single request. Every customer’s finished tracks land on the same URL. So your handler has to match the track id to the user who asked, and you store that mapping when you send the POST.
Second, the spec says the payload is a track model but publishes no separate schema for it. So parse it defensively. Then fetch the track by id before you trust the url, which costs one request and saves a guess.
Third, webhooks get missed. Servers restart, deploys land at the worst moment, and firewalls have opinions. Keep the polling function as a fallback for any track still sitting in processing after a few minutes, because a missed webhook otherwise looks exactly like a slow render. Most teams running a text to music API in production end up with both, and that is fine.
Stored durations come back instantly, fresh renders take the wait
Not every request to a text to music API needs a fresh render. The MCP connection guide recommends rounding durations to stocked values (5, 6, 8, 10, 15, 20, 30, 40, 60, 180, 240 and 300 seconds) “so a track can come back instantly”. It also prefers a playlist_index over a text prompt when speed matters.
The REST API has two neighbours of the main endpoint for this. POST /api/v3/public/tracks/stored returns a cached track matching the requested parameters. POST /api/v3/public/tracks/record skips the track-store cache and records a new one. The trade-off is plain. Stored answers fast but only matches stocked parameters, while a fresh render follows your exact prompt and duration and makes you wait.
Product-wise, the split is easy, since users want two different things. A user scrolling preview moods needs something now, so serve stocked durations. A user who typed a description of their video and set it to 47 seconds wants their own track. Render it and show a progress state.
Duration is the field people actually touch. In Mubert’s own data, last 28 days, 28.2% of tracks made with Render, our generator for creators, were re-cut to another duration afterwards. If your UI lets users change the length, expect more than one in four to use it.


Text to music API formats: modes, MP3 or WAV, and a 15-minute link
The POST supports four generation modes (track, jingle, loop and mix), and the file comes as MP3 at 32 to 320 kbps or as WAV. The company’s product summary counts five formats, because the neverending stream lives on its own endpoints.
Only track returns exactly the duration you asked the text to music API for. Loops and jingles come back slightly short, says the generate skill. So if your game engine expects a loop of exactly 30.000 seconds, read the real length from the file. Do that instead of trusting the number you sent. One more quiet behaviour: with wav, the API drops your bitrate and reports 1411, which is simply what uncompressed CD-quality audio is.
Your licence’s max_track_duration sets the ceiling. The skill’s example licence allows 1800 seconds, and anything longer comes back as a 403 LicenseForbiddenDuration. Check yours with GET /service/licenses before you build a slider that goes to an hour.
Then there is the clock. Download links expire at generations[].expired_at. On the common licence that window is track_expiration_time, 900 seconds, or 15 minutes. So when the status flips to done, copy the file to wherever your app serves audio from, within your licence terms. A URL saved in a database for tomorrow is a URL that returns nothing tomorrow.
The licence covers commercial use, with exceptions you should read
Tracks generated through the API are royalty-free and cleared for commercial use, says the skills repository, and the exact scope depends on the plan. Read it, because a text to music API is only as useful as the licence behind the file. Generated music is owned by Mubert Inc. The product summary lists what is not covered unless a plan explicitly allows it: artist releases on Spotify or Apple Music, Content ID monetization, and stock music marketplaces.
That matters most if your product hands the file to end users. A video editor exporting a clip with a generated soundtrack is one thing. A “make a song and distribute it” button is another, and it probably needs a conversation about the licence before it needs a frontend. (Lawyers love a button.)
The supply chain matters too. The tracks come from more than 3 million samples by over 10,000 producers, and the musicians who upload them get paid. Each track is composed for your request rather than picked off a shelf, so a thousand other apps are not playing it. If you are comparing this with per-track licensing, we did the maths in what a stock music licence actually buys.
Plans and their limits live on the API plans page. Check the live pricing there, because we won’t quote it here.
Error codes tell you which part of the request was wrong
Error codes from this text to music API are short and honest. Auth problems return 401, which covers a missing or invalid customer-id or access-token, or a deleted customer. When the licence refuses something, you get a 403. A 404 means an unknown track id, or a session id on the wrong route. Validation errors return 422 with a message and an errors object keyed by field. Send those to your logs, not to your users.
The odd one, though, is 413. The spec accepts images from 50 KB up to 10 MB, but the generate skill says images above about 1 MiB hit an nginx limit. That limit returns an HTML page instead of JSON. Your resp.json() then throws, and the stack trace points at your parser instead of the image. Resize images under a megabyte before upload, and check the content type before you parse.
The v3 reference documents no rate limits. Sensible polling and a webhook keep you from finding them by accident.
A checklist for your first text to music API integration
- Create one customer per end user with a stable
custom_id, and keep the licence token on the server. - Send
durationplus one source (prompt,imageorplaylist_index), neverprompttogether withbpm. - Poll the track by id every 5 seconds with a timeout of a few minutes.
- Set
webhook_urlandwebhook_enabledon the licence, and keep polling as the fallback. - Round preview durations to stocked values and render fresh only when the user asks for exact ones.
- Copy the file to your own storage within 15 minutes of
done. - Read
max_track_durationandtrack_expiration_timefrom your licence before you build the UI. - Check the licence exceptions before adding any export-to-streaming feature.
Ten lines of code, and the receipt from the text to music API turns into a song. The full reference lives in the Mubert API docs.



