Add Vocals Callbacks
When vocal generation tasks are completed, the system will send results to your provided callback URL via POST request
When you submit a task to the Add Vocals API, you can use the callBackUrl parameter to set a callback URL. When the task is completed, the system will automatically push the results to your specified address.
Callback Mechanism Overview
The callback mechanism eliminates the need to poll the API for task status. The system will proactively push task completion results to your server.
Callback Timing
The system will send callback notifications in the following situations:
Vocal generation task completed successfully
Vocal generation task failed
Errors occurred during task processing
Callback Method
HTTP Method : POST
Content Type : application/json
Timeout Setting : 15 seconds
When the task is completed, the system will send a POST request to your callBackUrl in the following format:
Success Callback
Failure Callback
{
"code" : 200 ,
"msg" : "All generated successfully." ,
"data" : {
"callbackType" : "complete" ,
"task_id" : "2fac****9f72" ,
"data" : [
{
"id" : "8551****662c" ,
"audio_url" : "https://example.cn/****.mp3" ,
"source_audio_url" : "https://example.cn/****.mp3" ,
"stream_audio_url" : "https://example.cn/****" ,
"source_stream_audio_url" : "https://example.cn/****" ,
"image_url" : "https://example.cn/****.jpeg" ,
"source_image_url" : "https://example.cn/****.jpeg" ,
"prompt" : "[Verse] Calm and relaxing melodies with soothing vocals" ,
"model_name" : "chirp-v3-5" ,
"title" : "Relaxing Piano with Vocals" ,
"tags" : "relaxing, piano, vocals, jazz" ,
"createTime" : "2025-01-01 00:00:00" ,
"duration" : 198.44
}
]
}
}
Status Code Description
Callback status code indicating task processing result: Status Code Description 200 Success - Vocal generation completed 400 Bad Request - Parameter error, content violation, etc. 451 Download Failed - Unable to download related files 500 Server Error - Please try again later
Status message providing detailed status description
Callback type indicating the current callback stage:
text: Text generation completed
first: First track completed
complete: All tracks completed
error: Task failed
Task ID, consistent with the taskId returned when you submitted the task
Vocal generation result information, returned on success
Generated vocal audio file URL
data.data[].source_audio_url
Original vocal audio file URL
data.data[].stream_audio_url
Streaming vocal audio URL
data.data[].source_stream_audio_url
Original streaming vocal audio URL
data.data[].source_image_url
Original cover image URL
Generation prompt/lyrics describing the vocals
Model name used for generation
Callback Reception Examples
Here are example codes for receiving callbacks in popular programming languages:
const express = require ( 'express' );
const app = express ();
app . use ( express . json ());
app . post ( '/add-vocals-callback' , ( req , res ) => {
const { code , msg , data } = req . body ;
console . log ( 'Received vocal generation callback:' , {
taskId: data . task_id ,
callbackType: data . callbackType ,
status: code ,
message: msg
});
if ( code === 200 ) {
// Task completed successfully
console . log ( 'Vocal generation completed' );
const vocalData = data . data || [];
console . log ( `Generated ${ vocalData . length } vocal tracks:` );
vocalData . forEach (( vocal , index ) => {
console . log ( `Vocal ${ index + 1 } :` );
console . log ( ` Title: ${ vocal . title } ` );
console . log ( ` Duration: ${ vocal . duration } seconds` );
console . log ( ` Tags: ${ vocal . tags } ` );
console . log ( ` Audio URL: ${ vocal . audio_url } ` );
console . log ( ` Cover URL: ${ vocal . image_url } ` );
});
// Process generated vocals
// Can download audio files, save locally, etc.
} else {
// Task failed
console . log ( 'Vocal generation failed:' , msg );
// Handle failure cases...
if ( code === 400 ) {
console . log ( 'Parameter error or content violation' );
} else if ( code === 451 ) {
console . log ( 'File download failed' );
} else if ( code === 500 ) {
console . log ( 'Server internal error' );
}
}
// Return 200 status code to confirm callback received
res . status ( 200 ). json ({ status: 'received' });
});
app . listen ( 3000 , () => {
console . log ( 'Callback server running on port 3000' );
});
from flask import Flask, request, jsonify
import requests
app = Flask( __name__ )
@app.route ( '/add-vocals-callback' , methods = [ 'POST' ])
def handle_callback ():
data = request.json
code = data.get( 'code' )
msg = data.get( 'msg' )
callback_data = data.get( 'data' , {})
task_id = callback_data.get( 'task_id' )
callback_type = callback_data.get( 'callbackType' )
vocal_data = callback_data.get( 'data' , [])
print ( f "Received vocal generation callback: { task_id } , type: { callback_type } , status: { code } , message: { msg } " )
if code == 200 :
# Task completed successfully
print ( "Vocal generation completed" )
print ( f "Generated { len (vocal_data) } vocal tracks:" )
for i, vocal in enumerate (vocal_data):
print ( f "Vocal { i + 1 } :" )
print ( f " Title: { vocal.get( 'title' ) } " )
print ( f " Duration: { vocal.get( 'duration' ) } seconds" )
print ( f " Tags: { vocal.get( 'tags' ) } " )
print ( f " Audio URL: { vocal.get( 'audio_url' ) } " )
print ( f " Cover URL: { vocal.get( 'image_url' ) } " )
# Download audio file example
try :
audio_url = vocal.get( 'audio_url' )
if audio_url:
response = requests.get(audio_url)
if response.status_code == 200 :
filename = f "generated_vocal_ { task_id } _ { i + 1 } .mp3"
with open (filename, "wb" ) as f:
f.write(response.content)
print ( f "Vocal saved as { filename } " )
except Exception as e:
print ( f "Audio download failed: { e } " )
else :
# Task failed
print ( f "Vocal generation failed: { msg } " )
# Handle failure cases...
if code == 400 :
print ( "Parameter error or content violation" )
elif code == 451 :
print ( "File download failed" )
elif code == 500 :
print ( "Server internal error" )
# Return 200 status code to confirm callback received
return jsonify({ 'status' : 'received' }), 200
if __name__ == '__main__' :
app.run( host = '0.0.0.0' , port = 3000 )
<? php
header ( 'Content-Type: application/json' );
// Get POST data
$input = file_get_contents ( 'php://input' );
$data = json_decode ( $input , true );
$code = $data [ 'code' ] ?? null ;
$msg = $data [ 'msg' ] ?? '' ;
$callbackData = $data [ 'data' ] ?? [];
$taskId = $callbackData [ 'task_id' ] ?? '' ;
$callbackType = $callbackData [ 'callbackType' ] ?? '' ;
$vocalData = $callbackData [ 'data' ] ?? [];
error_log ( "Received vocal generation callback: $taskId , type: $callbackType , status: $code , message: $msg " );
if ( $code === 200 ) {
// Task completed successfully
error_log ( "Vocal generation completed" );
error_log ( "Generated " . count ( $vocalData ) . " vocal tracks:" );
foreach ( $vocalData as $index => $vocal ) {
error_log ( "Vocal " . ( $index + 1 ) . ":" );
error_log ( " Title: " . ( $vocal [ 'title' ] ?? '' ));
error_log ( " Duration: " . ( $vocal [ 'duration' ] ?? 0 ) . " seconds" );
error_log ( " Tags: " . ( $vocal [ 'tags' ] ?? '' ));
error_log ( " Audio URL: " . ( $vocal [ 'audio_url' ] ?? '' ));
error_log ( " Cover URL: " . ( $vocal [ 'image_url' ] ?? '' ));
// Download audio file example
try {
$audioUrl = $vocal [ 'audio_url' ] ?? '' ;
if ( $audioUrl ) {
$audioContent = file_get_contents ( $audioUrl );
if ( $audioContent !== false ) {
$filename = "generated_vocal_{ $taskId }_" . ( $index + 1 ) . ".mp3" ;
file_put_contents ( $filename , $audioContent );
error_log ( "Vocal saved as $filename " );
}
}
} catch ( Exception $e ) {
error_log ( "Audio download failed: " . $e -> getMessage ());
}
}
} else {
// Task failed
error_log ( "Vocal generation failed: $msg " );
// Handle failure cases...
if ( $code === 400 ) {
error_log ( "Parameter error or content violation" );
} elseif ( $code === 451 ) {
error_log ( "File download failed" );
} elseif ( $code === 500 ) {
error_log ( "Server internal error" );
}
}
// Return 200 status code to confirm callback received
http_response_code ( 200 );
echo json_encode ([ 'status' => 'received' ]);
?>
Best Practices
Callback URL Configuration Recommendations
Use HTTPS : Ensure your callback URL uses HTTPS protocol for secure data transmission
Verify Source : Verify the legitimacy of the request source in callback processing
Idempotent Processing : The same taskId may receive multiple callbacks, ensure processing logic is idempotent
Quick Response : Callback processing should return a 200 status code as quickly as possible to avoid timeout
Asynchronous Processing : Complex business logic should be processed asynchronously to avoid blocking callback response
Audio Processing : Audio download and processing should be done in asynchronous tasks to avoid blocking callback response
Important Reminders
Callback URL must be a publicly accessible address
Server must respond within 15 seconds, otherwise it will be considered a timeout
If 3 consecutive retries fail, the system will stop sending callbacks
Please ensure the stability of callback processing logic to avoid callback failures due to exceptions
Generated audio URLs may have time limits, recommend downloading and saving promptly
Pay attention to content policy compliance to avoid generation failures due to policy violations
Troubleshooting
If you do not receive callback notifications, please check the following:
Network Connection Issues
Confirm that the callback URL is accessible from the public network
Check firewall settings to ensure inbound requests are not blocked
Verify that domain name resolution is correct
Ensure the server returns HTTP 200 status code within 15 seconds
Check server logs for error messages
Verify that the interface path and HTTP method are correct
Confirm that the received POST request body is in JSON format
Check that Content-Type is application/json
Verify that JSON parsing is correct
Confirm that audio URLs are accessible
Check audio download permissions and network connections
Verify audio save paths and permissions
Note whether audio content complies with content policies
Alternative Solution
If you cannot use the callback mechanism, you can also use polling:
Poll Query Results Use the get music generation details endpoint to regularly query task status. We recommend querying every 30 seconds.