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:
Text generation completed (text stage)
First vocal track generated (first stage)
All vocal tracks generated (complete stage)
Vocal generation task failed
Error occurred during task processing
Callback Method
HTTP Method : POST
Content Type : application/json
Timeout : 15 seconds
When the task is completed, the system will send a POST request to your callBackUrl in the following format:
Text Generation Complete Callback
First Track Complete Callback
All Tracks Complete Callback
Failed Callback
{
"code" : 200 ,
"msg" : "Text generation completed successfully." ,
"data" : {
"callbackType" : "text" ,
"task_id" : "2fac****9f72" ,
"data" : []
}
}
Status Code Description
Callback status code indicating task processing result: Status Code Description 200 Success - Vocal generation completed 400 Bad Request - Parameter error or content violation 401 Unauthorized - Invalid API key 413 Content Too Long - Prompt or style description exceeds limit 429 Insufficient Credits - Account credit balance insufficient 500 Server Error - Please retry later
Status message providing detailed status description
Callback type indicating the current callback stage:
text: Text generation completed
first: First vocal track generated
complete: All vocal tracks generated
failed: Task failed
Task ID, consistent with the taskId returned when you submitted the task
Vocal generation result information, returned on success
Audio unique identifier (audioId)
Audio file download link with vocals
data.data[].source_audio_url
Original source audio file download link
data.data[].stream_audio_url
Streaming audio playback link with vocals
Prompt/lyrics used for vocal generation
AI model name used for vocal generation
Music style tags including vocal characteristics
Callback Reception Examples
Here are example codes for receiving callbacks in various popular programming languages:
const express = require ( 'express' );
const app = express ();
app . use ( express . json ());
app . post ( '/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 successful
const { callbackType , data : vocalsData } = data ;
switch ( callbackType ) {
case 'text' :
console . log ( 'Text generation completed' );
break ;
case 'first' :
console . log ( 'First vocal track generated' );
if ( vocalsData . length > 0 ) {
console . log ( `Track title: ${ vocalsData [ 0 ]. title } ` );
console . log ( `Vocal audio link: ${ vocalsData [ 0 ]. audio_url } ` );
console . log ( `Duration: ${ vocalsData [ 0 ]. duration } seconds` );
console . log ( `Vocals prompt: ${ vocalsData [ 0 ]. prompt } ` );
}
break ;
case 'complete' :
console . log ( 'All vocal tracks generated' );
console . log ( `Total ${ vocalsData . length } vocal tracks generated:` );
vocalsData . forEach (( track , index ) => {
console . log ( `Track ${ index + 1 } : ${ track . title } - ${ track . audio_url } ` );
console . log ( `Vocals: ${ track . prompt } ` );
});
// Process generated vocal tracks
// Can download audio, save locally, etc.
break ;
}
} else {
// Task failed
console . log ( 'Vocal generation failed:' , msg );
// Handle failure cases...
if ( code === 400 ) {
console . log ( 'Parameter error or vocal content violation' );
} else if ( code === 429 ) {
console . log ( 'Insufficient credits' );
} 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 ( 'Vocal callback server running on port 3000' );
});
from flask import Flask, request, jsonify
import requests
app = Flask( __name__ )
@app.route ( '/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' )
vocals_data = callback_data.get( 'data' , [])
print ( f "Received vocal generation callback: { task_id } , Type: { callback_type } , Status: { code } " )
if code == 200 :
# Task successful
if callback_type == 'text' :
print ( "Text generation completed" )
elif callback_type == 'first' :
print ( "First vocal track generated" )
if vocals_data:
track = vocals_data[ 0 ]
print ( f "Track title: { track.get( 'title' ) } " )
print ( f "Vocal audio link: { track.get( 'audio_url' ) } " )
print ( f "Duration: { track.get( 'duration' ) } seconds" )
print ( f "Vocals prompt: { track.get( 'prompt' ) } " )
elif callback_type == 'complete' :
print ( "All vocal tracks generated" )
print ( f "Total { len (vocals_data) } vocal tracks generated:" )
for i, track in enumerate (vocals_data):
print ( f "Track { i + 1 } : { track.get( 'title' ) } - { track.get( 'audio_url' ) } " )
print ( f "Vocals: { track.get( 'prompt' ) } " )
# Download vocal audio example
try :
audio_url = track.get( 'audio_url' )
if audio_url:
response = requests.get(audio_url)
if response.status_code == 200 :
filename = f "vocals_ { task_id } _ { i + 1 } .mp3"
with open (filename, "wb" ) as f:
f.write(response.content)
print ( f "Vocal audio saved as { filename } " )
except Exception as e:
print ( f "Vocal audio download failed: { e } " )
else :
# Task failed
print ( f "Vocal generation failed: { msg } " )
# Handle failure cases...
if code == 400 :
print ( "Parameter error or vocal content violation" )
elif code == 429 :
print ( "Insufficient credits" )
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' ] ?? '' ;
$vocalsData = $callbackData [ 'data' ] ?? [];
error_log ( "Received vocal generation callback: $taskId , Type: $callbackType , Status: $code " );
if ( $code === 200 ) {
// Task successful
switch ( $callbackType ) {
case 'text' :
error_log ( "Text generation completed" );
break ;
case 'first' :
error_log ( "First vocal track generated" );
if ( ! empty ( $vocalsData )) {
$track = $vocalsData [ 0 ];
error_log ( "Track title: " . ( $track [ 'title' ] ?? '' ));
error_log ( "Vocal audio link: " . ( $track [ 'audio_url' ] ?? '' ));
error_log ( "Duration: " . ( $track [ 'duration' ] ?? 0 ) . " seconds" );
error_log ( "Vocals prompt: " . ( $track [ 'prompt' ] ?? '' ));
}
break ;
case 'complete' :
error_log ( "All vocal tracks generated" );
error_log ( "Total " . count ( $vocalsData ) . " vocal tracks generated:" );
foreach ( $vocalsData as $index => $track ) {
$title = $track [ 'title' ] ?? '' ;
$audioUrl = $track [ 'audio_url' ] ?? '' ;
$prompt = $track [ 'prompt' ] ?? '' ;
error_log ( "Track " . ( $index + 1 ) . ": $title - $audioUrl " );
error_log ( "Vocals: $prompt " );
// Download vocal audio example
try {
if ( $audioUrl ) {
$audioContent = file_get_contents ( $audioUrl );
if ( $audioContent !== false ) {
$filename = "vocals_{ $taskId }_" . ( $index + 1 ) . ".mp3" ;
file_put_contents ( $filename , $audioContent );
error_log ( "Vocal audio saved as $filename " );
}
}
} catch ( Exception $e ) {
error_log ( "Vocal audio download failed: " . $e -> getMessage ());
}
}
break ;
}
} else {
// Task failed
error_log ( "Vocal generation failed: $msg " );
// Handle failure cases...
if ( $code === 400 ) {
error_log ( "Parameter error or vocal content violation" );
} elseif ( $code === 429 ) {
error_log ( "Insufficient credits" );
} 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
Vocal Generation Callback 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 : Ensure processing logic is idempotent as the same taskId may receive multiple callbacks
Quick Response : Callback processing should return 200 status code quickly to avoid timeout
Asynchronous Processing : Complex business logic should be processed asynchronously to avoid blocking callback response
Stage-based Processing : Handle different callback stages (text, first, complete) with appropriate business logic
Vocal Content Analysis : Implement vocal content analysis and quality assessment for generated tracks
Lyrics Extraction : Extract and process lyrics from vocal prompts for better content management
Important Reminders
Callback URL must be publicly accessible
Server must respond within 15 seconds, otherwise considered timeout
After 3 consecutive retry failures, the system will stop sending callbacks
Ensure stability of callback processing logic to avoid callback failures due to exceptions
Generated vocal audio URLs may have time limits, recommend downloading and saving promptly
Pay attention to vocal content compliance to avoid generation failures due to violations
Vocal generation has three stages, each stage will trigger callback notifications
Consider implementing content filtering for vocal lyrics and audio content
Troubleshooting
If you don’t receive callback notifications, please check the following:
Network Connection Issues
Confirm that the callback URL is accessible from the public internet
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 if Content-Type is application/json
Verify that JSON parsing is correct
Confirm that vocal audio URLs are accessible
Check vocal audio download permissions and network connectivity
Verify audio save path and permissions
Note that vocal content must comply with content policies
Verify vocal quality meets your application requirements
Callback Stage Processing
Understand the differences and handling methods of the three callback stages
text stage: Only indicates text generation completed, no audio data
first stage: First vocal track completed, contains data for one track
complete stage: All vocal tracks completed, contains complete vocal track list
Implement lyrics extraction from vocal prompts
Check vocal content for compliance with platform policies
Assess vocal quality and appropriateness for your use case
Handle different vocal styles and languages appropriately
Alternative Solutions
If you cannot use the callback mechanism, you can also use polling:
Poll Query Results Use the Get Music Generation Details interface to regularly query task status. Recommend querying every 30 seconds.