Rewrite a section of a song
https://api.mozartai.com/v1/inpaintsStarts a job that rewrites one section of a song or an uploaded audio file, 3 to 60 seconds long, and blends it into the music on each side, as two new songs.
- Cost
- Depends on audio length, see Cost
- Rate limit
- Write
- Idempotency key
- Required
- Runs as a job
- Poll or wait on job.id
- MCP tool
inpaint_song- CLI (coming soon)
mozart inpaint create
When to use: The user wants to change part of a song: new words, a new style or no vocals for a few bars. Pass source_song_id or source_upload_id, the section as start_seconds and end_seconds, and a prompt, lyrics or both. Then call POST /v1/jobs/wait with job.id; the two new songs are in song_ids.
When not to use: To remake the whole song in a new style, use POST /v1/covers. For a new song from a prompt, use POST /v1/songs.
Side effects: Creates one job and two new songs in the user's library, linked to the source; the source is not changed. Repeating the call with the same idempotency key returns the first job and spends nothing; a new key starts and charges a second job. Never create again while the job is running.
Authentication
Send your API key as Authorization: Bearer <key>. The key needs these scopes:
generatecredits:spend
Headers
idempotency-keystringRequired1 to 255 charactersA unique string per intended action. Repeating a call with the same key returns the first answer instead of doing the work twice: a key is bound to its first request for 90 days; its response is replayed for 24 hours; use a new key for a new request.
Request body
source_song_idstringOptionalA song in your library to edit. Send this or source_upload_id.
source_upload_idstringOptionalAn uploaded audio file to edit, once its upload is
ready. Send this or source_song_id.start_secondsnumberRequiredat least 0Where the section to rewrite starts, in seconds from the start.
end_secondsnumberRequiredgreater than 0Where the section to rewrite ends, in seconds. The section is 3 to 60 seconds long and ends inside the song; the music on each side is kept and the new section blends into it.
promptstringOptionalat most 1000 charactersHow the section should change: style, mood, instruments. Send a prompt, lyrics, or both.
lyricsstringOptionalat most 3000 charactersThe song's lyrics with the new words for the section. Leave out to keep the source's lyrics; an upload needs lyrics or instrumental: true.
instrumentalbooleanOptionalDefaults tofalseMake the rewritten section without vocals. Not allowed with lyrics.
titlestringOptional1 to 200 charactersmodelenumOptionalproject_idstringOptionaldry_runbooleanOptionalDefaults tofalseReturn the price and balance without starting a job or spending credits.
dry_run still needs an idempotency-key header, like every write. Use a different key from the real request.
Response 202
The job started (or, with dry_run, the price it would cost).
dry_runbooleanRequiredestimateobjector nullRequiredThe price check. Always filled on a dry run. On a real start some operations fill it and others leave it null (song and cover starts do), so read it only on a dry run and read the charge from
job.credits_charged.Show 3 properties
credits_requirednumberRequiredbalancenumberRequiredThe credits available now: the balance minus credits held by jobs that have not finished, the same number as
availablein the credits read.balance_afternumberRequired
jobobjector nullRequiredShow 14 properties
idstringRequiredobjectconstantRequiredkindenumRequiredShow 9 values
songcoverinpaintstemstemsmidimastercover_artpersona
statusenumRequiredAllowed valuesqueuedrunningsucceededfailedcancelled
playablebooleanRequiredproject_idstringor nullRequiredsong_idslist of stringRequiredoutputslist of objectRequiredShow 8 properties
typeenumRequiredAllowed valuesaudiostemmidiimagepersona
song_idstringor nullRequiredpersona_idstringor nullRequiredlabelstringor nullRequiredurlstringor nullRequiredurl_expires_atstringor nullRequiredcontent_typestringor nullRequiredduration_secondsnumberor nullRequired
credits_chargednumberor nullRequirednull while the job is pending; the settled ledger debit once it finishes; 0 for free operations, test keys and released or refunded holds
credits_refundedbooleanRequirederrorobjector nullRequiredShow 3 properties
codestringRequiredmessagestringRequirednext_stepstringor nullRequired
poll_after_secondsnumberor nullRequiredcreated_atstringRequiredcompleted_atstringor nullRequired
balance_afternumberor nullRequiredThe balance after this call's hold, when the operation reports it; null on song and cover starts. Read
GET /v1/creditsfor the current balance.
Response headers
x-request-idThe id of this request; quote it when asking for help.x-mozart-api-versionThe API version that answered.x-ratelimit-limitRequests allowed in the current window for this caller.x-ratelimit-remainingRequests left in the current window.x-ratelimit-resetWhen the window resets, in Unix seconds.idempotent-replayedtruewhen this answer is the stored answer to an earlier call with the same idempotency key; the work was not done again.
Errors
What to do: INSUFFICIENT_CREDITS (type insufficient_credits): stop, tell the user (with plans_url if set); never retry. PUBLIC_API_RATE_LIMITED: wait retry_after_seconds, then retry once with the same idempotency key. PUBLIC_API_INPUT_INVALID: send one source, a 3 to 60 second section inside the song, and a prompt or lyrics.
| Status | Type | Meaning |
|---|---|---|
| 400 | invalid_request | The request is malformed or an input is invalid. |
| 401 | authentication | The key or token is missing, invalid or revoked. |
| 402 | insufficient_credits | The account has too few credits for this call. A REST key also needs an API plan (Starter, Build, Scale or Growth) or API credits; with neither, every call is refused with PUBLIC_API_CREDITS_REQUIRED. payment_required: The account's plan does not include this; it needs an upgrade. |
| 403 | permission | The caller may not do this: a missing scope, a Mozart CLI sign-in whose account is below Pro, or access not enabled. |
| 404 | not_found | The resource or route does not exist for this caller. |
| 409 | conflict | The request conflicts with the current state, or an idempotency key was reused with a different body. |
| 422 | content_refused | The input was refused by content screening. |
| 429 | rate_limited | Too many requests; retry after Retry-After seconds. limit_reached: A daily, concurrent or total limit was reached. |
| 500 | internal | Mozart failed to answer; retry later. |
| 503 | provider_unavailable | A generation provider is unavailable; retry later. service_unavailable: A Mozart check the request needs, such as content screening, is temporarily unavailable; retry after retry_after_seconds. |