When you submit a task to the Upload and Extend 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 extension task completed successfully
  • Audio extension task failed
  • Errors occurred during task processing

Callback Method

  • HTTP Method: POST
  • Content Type: application/json
  • Timeout Setting: 15 seconds
  • Retry Mechanism: Retry 3 times after failure, with intervals of 1 minute, 5 minutes, and 15 minutes respectively

Callback Request Format

When the task is completed, the system will send a POST request to your callBackUrl in the following format:
{
  "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": 198.44
      }
    ]
  }
}

Status Code Description

code
integer
required
Callback status code indicating task processing result:
Status CodeDescription
200Success - Audio extension completed
400Bad Request - Parameter error, unsupported audio file format, content violation, etc.
451Download Failed - Unable to download source audio file
500Server Error - Please try again later
msg
string
required
Status message providing detailed status description
data.callbackType
string
required
Callback type indicating the current callback stage:
  • text: Text generation completed
  • first: First music track completed
  • complete: All music tracks completed
  • error: Task failed
data.task_id
string
required
Task ID, consistent with the taskId returned when you submitted the task
data.data
array
Audio extension result information, returned on success
data.data[].id
string
Music unique identifier
data.data[].audio_url
string
Extended audio file URL
data.data[].source_audio_url
string
Original audio file URL
data.data[].stream_audio_url
string
Streaming audio URL
data.data[].source_stream_audio_url
string
Original streaming audio URL
data.data[].image_url
string
Cover image URL
data.data[].source_image_url
string
Original cover image URL
data.data[].prompt
string
Generation prompt/lyrics
data.data[].model_name
string
Model name used
data.data[].title
string
Music title
data.data[].tags
string
Music tags
data.data[].createTime
string
Creation time
data.data[].duration
number
Audio duration (seconds)

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-extend-callback', (req, res) => {
  const { code, msg, data } = req.body;
  
  console.log('Received audio extension callback:', {
    taskId: data.task_id,
    callbackType: data.callbackType,
    status: code,
    message: msg
  });
  
  if (code === 200) {
    // Task completed successfully
    console.log('Audio extension completed');
    const musicData = data.data || [];
    
    console.log(`Extended ${musicData.length} music tracks:`);
    musicData.forEach((music, index) => {
      console.log(`Extended music ${index + 1}:`);
      console.log(`  Title: ${music.title}`);
      console.log(`  Duration: ${music.duration} seconds`);
      console.log(`  Style tags: ${music.tags}`);
      console.log(`  Extended audio URL: ${music.audio_url}`);
      console.log(`  Cover URL: ${music.image_url}`);
    });
    
    // Process extended music
    // Can download audio files, save locally, etc.
    
  } else {
    // Task failed
    console.log('Audio extension 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');
});

Best Practices

Callback URL Configuration Recommendations

  1. Use HTTPS: Ensure your callback URL uses HTTPS protocol for secure data transmission
  2. Verify Source: Verify the legitimacy of the request source in callback processing
  3. Idempotent Processing: The same taskId may receive multiple callbacks, ensure processing logic is idempotent
  4. Quick Response: Callback processing should return a 200 status code as quickly as possible to avoid timeout
  5. Asynchronous Processing: Complex business logic should be processed asynchronously to avoid blocking callback response
  6. 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:

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.