When you submit a task to the Upload and Cover Audio 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:
Audio covering task completed successfully
Audio covering 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] Night city lights shining bright" ,
"model_name" : "chirp-v3-5" ,
"title" : "Iron Man" ,
"tags" : "electrifying, rock" ,
"createTime" : "2025-01-01 00:00:00" ,
"duration" : 228.28
}
]
}
}
Status Code Description
Callback status code indicating task processing result: Status Code Description 200 Success - Audio covering completed 400 Bad Request - Parameter error, unsupported audio file format, content violation, etc. 451 Download Failed - Unable to download source audio file 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 music track completed
complete: All music tracks completed
error: Task failed
Task ID, consistent with the taskId returned when you submitted the task
Audio covering result information, returned on success
data.data[].source_audio_url
Original audio file URL
data.data[].stream_audio_url
Streaming audio URL
data.data[].source_stream_audio_url
Original streaming audio URL
data.data[].source_image_url
Original cover image URL
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 ( '/upload-cover-callback' , ( req , res ) => {
const { code , msg , data } = req . body ;
console . log ( 'Received audio covering callback:' , {
taskId: data . task_id ,
callbackType: data . callbackType ,
status: code ,
message: msg
});
if ( code === 200 ) {
// Task completed successfully
console . log ( 'Audio covering completed' );
const musicData = data . data || [];
console . log ( `Covered ${ musicData . length } music tracks:` );
musicData . forEach (( music , index ) => {
console . log ( `Covered music ${ index + 1 } :` );
console . log ( ` Title: ${ music . title } ` );
console . log ( ` Duration: ${ music . duration } seconds` );
console . log ( ` Style tags: ${ music . tags } ` );
console . log ( ` Covered audio URL: ${ music . audio_url } ` );
console . log ( ` Cover URL: ${ music . image_url } ` );
});
// Process covered music
// Can download audio files, save locally, etc.
} else {
// Task failed
console . log ( 'Audio covering failed:' , msg );
// Handle failure cases...
if ( code === 400 ) {
console . log ( 'Parameter error or content violation' );
} else if ( code === 451 ) {
console . log ( 'Source audio 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 ( '/upload-cover-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' )
music_data = callback_data.get( 'data' , [])
print ( f "Received audio covering callback: { task_id } , type: { callback_type } , status: { code } , message: { msg } " )
if code == 200 :
# Task completed successfully
print ( "Audio covering completed" )
print ( f "Covered { len (music_data) } music tracks:" )
for i, music in enumerate (music_data):
print ( f "Covered music { i + 1 } :" )
print ( f " Title: { music.get( 'title' ) } " )
print ( f " Duration: { music.get( 'duration' ) } seconds" )
print ( f " Style tags: { music.get( 'tags' ) } " )
print ( f " Covered audio URL: { music.get( 'audio_url' ) } " )
print ( f " Cover URL: { music.get( 'image_url' ) } " )
# Download covered audio file example
try :
audio_url = music.get( 'audio_url' )
if audio_url:
response = requests.get(audio_url)
if response.status_code == 200 :
filename = f "covered_music_ { task_id } _ { i + 1 } .mp3"
with open (filename, "wb" ) as f:
f.write(response.content)
print ( f "Covered audio saved as { filename } " )
except Exception as e:
print ( f "Audio download failed: { e } " )
else :
# Task failed
print ( f "Audio covering failed: { msg } " )
# Handle failure cases...
if code == 400 :
print ( "Parameter error or content violation" )
elif code == 451 :
print ( "Source audio 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' ] ?? '' ;
$musicData = $callbackData [ 'data' ] ?? [];
error_log ( "Received audio covering callback: $taskId , type: $callbackType , status: $code , message: $msg " );
if ( $code === 200 ) {
// Task completed successfully
error_log ( "Audio covering completed" );
error_log ( "Covered " . count ( $musicData ) . " music tracks:" );
foreach ( $musicData as $index => $music ) {
error_log ( "Covered music " . ( $index + 1 ) . ":" );
error_log ( " Title: " . ( $music [ 'title' ] ?? '' ));
error_log ( " Duration: " . ( $music [ 'duration' ] ?? 0 ) . " seconds" );
error_log ( " Style tags: " . ( $music [ 'tags' ] ?? '' ));
error_log ( " Covered audio URL: " . ( $music [ 'audio_url' ] ?? '' ));
error_log ( " Cover URL: " . ( $music [ 'image_url' ] ?? '' ));
// Download covered audio file example
try {
$audioUrl = $music [ 'audio_url' ] ?? '' ;
if ( $audioUrl ) {
$audioContent = file_get_contents ( $audioUrl );
if ( $audioContent !== false ) {
$filename = "covered_music_{ $taskId }_" . ( $index + 1 ) . ".mp3" ;
file_put_contents ( $filename , $audioContent );
error_log ( "Covered audio saved as $filename " );
}
}
} catch ( Exception $e ) {
error_log ( "Audio download failed: " . $e -> getMessage ());
}
}
} else {
// Task failed
error_log ( "Audio covering failed: $msg " );
// Handle failure cases...
if ( $code === 400 ) {
error_log ( "Parameter error or content violation" );
} elseif ( $code === 451 ) {
error_log ( "Source audio 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
Ensure uploaded audio file format is supported
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
Confirm source audio file format is supported
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.