API Endpoints
Replace Section
Replace Section API
https://udioapi.pro/api/v2/replace-sectionRegenerate one part of a song you already created, such as a few seconds with a glitch or a line you want sung differently, and get the full song back with that part re-rendered.
How it works
- Choose a time window in a completed song. The song is re-rendered around that window and returned as full-length tracks, usually two variations, through the same task flow as music generation.
- About 10 seconds on each side of the window are re-rendered too, so the new part blends in. Everything outside that range stays as it was, apart from a fresh audio encode.
- Window rules, checked before any credits are charged: at least 10 seconds long, at most 50% of the song and at most 480 seconds, and infill_end_s must not exceed the song length.
- If you do not send lyrics, the lyrics sung inside the window are filled in automatically from the song's word timings. Send them yourself when you want different words.
- A result whose length differs from the original by more than 15 seconds is discarded. If no result is left, the task ends as FAILED and your credits are refunded; moving the window start or end by a few seconds usually helps.
- 5 credits per request, charged when the request is accepted. Requests rejected during validation and tasks that fail are refunded automatically.
- Only songs created with /v2/generate or /v2/extend under the same API key can be edited. Uploaded audio and earlier replace results are not supported as a source.
Quick Start
{
"origin_task_id": "gen2cd84c4e3ecb94ed6a9137a8f12138ca1bksv",
"audio_id": "24015dc4-1b81-4033-9f41-cf47a3fae958",
"infill_start_s": 70,
"infill_end_s": 85,
"prompt": "Same melody and arrangement, cleaner vocal in this part"
}style, title and full_lyrics are optional. When omitted, the values of the original song are used.
Response
{
"code": 200,
"message": "success",
"workId": "rep2a15b5bbc14304ca89fcc7b7eae29c8a7bksv",
"data": {
"task_id": "rep2a15b5bbc14304ca89fcc7b7eae29c8a7bksv"
}
}Poll the returned workId every 5–10 seconds until the status is SUCCESS or FAILED, using the Fetch Task Status API
Parameters
Required parameters
origin_task_idrequiredstringtask_id of the completed song you want to edit, as returned by /v2/generate or /v2/extend.
audio_idrequiredstringid of the song inside that task (response_data[].id). A task usually returns two songs; pick the one to edit.
infill_start_srequirednumberStart of the section in seconds: 0 or greater, up to two decimals.
infill_end_srequirednumberEnd of the section in seconds. Must be at least 10 seconds after infill_start_s and not past the end of the song.
promptrequiredstringHow the section should change, up to 1000 characters, for example "Same melody and arrangement, cleaner vocal in this part".
Optional parameters
lyricsoptionalstringLyrics to sing inside the section, up to 5000 characters. Defaults to the lyrics currently sung in the window.
styleoptionalstringMusic style for the result, up to 1000 characters. Defaults to the style of the original song.
titleoptionalstringTitle for the result, up to 80 characters. Defaults to the original title.
full_lyricsoptionalstringComplete lyrics of the edited song, up to 5000 characters. Defaults to the original lyrics.
callback_urloptionalstringPublic URL that receives the final result, with the same items as response_data in the task status. Polling works with or without it.
Results
When the task succeeds, response_data contains the new full-length songs. Each item has its own id, audio_url and duration. If only one variation kept the original length, only that one is returned.
{
"code": 200,
"message": "success",
"data": {
"type": "SUCCESS",
"request_body": {
"origin_task_id": "gen2cd84c4e3ecb94ed6a9137a8f12138ca1bksv",
"audio_id": "24015dc4-1b81-4033-9f41-cf47a3fae958",
"infill_start_s": 70,
"infill_end_s": 85,
"prompt": "Same melody and arrangement, cleaner vocal in this part"
},
"response_data": [
{
"id": "3a8248e4-07b0-4ceb-92b7-34b7615d2552",
"audio_url": "https://…/3a8248e4-07b0-4ceb-92b7-34b7615d2552.mp3",
"image_url": "https://…/3a8248e4-07b0-4ceb-92b7-34b7615d2552.jpeg",
"status": "complete",
"title": "Harbor Lights",
"duration": 119.6,
"model_name": "chirp-v6-mini"
},
{
"id": "eac654a1-5c07-4b6c-896a-59061d323e11",
"audio_url": "https://…/eac654a1-5c07-4b6c-896a-59061d323e11.mp3",
"image_url": "https://…/eac654a1-5c07-4b6c-896a-59061d323e11.jpeg",
"status": "complete",
"title": "Harbor Lights",
"duration": 120.84,
"model_name": "chirp-v6-mini"
}
]
}
}When every result changed the song length, or the section could not be rendered, the task is FAILED and the credits are refunded:
{
"code": 200,
"message": "success",
"data": {
"type": "FAILED",
"response_data": [
{
"status": "FAILED",
"fail_message": "Generation failed. Your credits have been refunded. The result changed the song length (119.6s -> 225.36s / 224.6s), so it was discarded. Try moving the section start or end by a few seconds.",
"error_message": "Generation failed. Your credits have been refunded. The result changed the song length (119.6s -> 225.36s / 224.6s), so it was discarded. Try moving the section start or end by a few seconds."
},
{
"status": "FAILED",
"fail_message": "Generation failed. Your credits have been refunded. The result changed the song length (119.6s -> 225.36s / 224.6s), so it was discarded. Try moving the section start or end by a few seconds.",
"error_message": "Generation failed. Your credits have been refunded. The result changed the song length (119.6s -> 225.36s / 224.6s), so it was discarded. Try moving the section start or end by a few seconds."
}
]
}
}Code Examples
cURL
curl -X POST "https://udioapi.pro/api/v2/replace-section" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"origin_task_id": "gen2cd84c4e3ecb94ed6a9137a8f12138ca1bksv",
"audio_id": "24015dc4-1b81-4033-9f41-cf47a3fae958",
"infill_start_s": 70,
"infill_end_s": 85,
"prompt": "Same melody and arrangement, cleaner vocal in this part"
}'JavaScript
const response = await fetch('https://udioapi.pro/api/v2/replace-section', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"origin_task_id": "gen2cd84c4e3ecb94ed6a9137a8f12138ca1bksv",
"audio_id": "24015dc4-1b81-4033-9f41-cf47a3fae958",
"infill_start_s": 70,
"infill_end_s": 85,
"prompt": "Same melody and arrangement, cleaner vocal in this part"
})
});
const { workId } = await response.json();
// Poll https://udioapi.pro/api/v2/feed?workId=... every 5-10 seconds until SUCCESS or FAILED.Python
import requests
response = requests.post(
"https://udioapi.pro/api/v2/replace-section",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={
"origin_task_id": "gen2cd84c4e3ecb94ed6a9137a8f12138ca1bksv",
"audio_id": "24015dc4-1b81-4033-9f41-cf47a3fae958",
"infill_start_s": 70,
"infill_end_s": 85,
"prompt": "Same melody and arrangement, cleaner vocal in this part"
},
)
work_id = response.json()["workId"]
# Poll https://udioapi.pro/api/v2/feed?workId=... every 5-10 seconds until SUCCESS or FAILED.Error Responses
{
"code": 400,
"message": "The section must be at least 10 seconds long (requested 9.99s)."
}{
"code": 400,
"message": "The section can cover at most 50% of the song and 480s (max 59.8s for this song, requested 65s)."
}{
"code": 400,
"message": "\"infill_end_s\" must not exceed the song length (119.6s)."
}{
"code": 400,
"message": "The provided \"origin_task_id\" is invalid or could not be found. Use the task_id of a completed song generated with your API key."
}{
"code": 400,
"message": "\"audio_id\" 1234 does not belong to this task. Use one of the song ids returned for \"origin_task_id\"."
}{
"code": 400,
"message": "Only songs generated with this API can be edited: send \"origin_task_id\" and \"audio_id\", without \"upload_url\" or \"model\"."
}{
"code": 402,
"message": "No available credits"
}{
"code": 401,
"message": "Invalid API key"
}