When you submit a task to the music extension 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 extended music track generated (first stage)
  • All extended music tracks generated (complete stage)
  • Music extension task failed
  • Error occurred during task processing

Callback Method

  • HTTP Method: POST
  • Content Type: application/json
  • Timeout: 15 seconds

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": "Text generation completed successfully.",
  "data": {
    "callbackType": "text",
    "task_id": "2fac****9f72",
    "data": []
  }
}

Status Code Description

code
integer
required
Callback status code indicating task processing result:
Status CodeDescription
200Success - Music extension completed
400Bad Request - Invalid source audio or parameter error
401Unauthorized - Invalid API key
413Content Too Long - Prompt or style description exceeds limit
429Insufficient Credits - Account credit balance insufficient
500Server Error - Please retry 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 extended music track generated
  • complete: All extended music tracks generated
  • failed: Task failed
data.task_id
string
required
Task ID, consistent with the taskId returned when you submitted the task
data.data
array
Music extension result information, returned on success
data.data[].id
string
Audio unique identifier
data.data[].audio_url
string
Extended audio file download link
data.data[].source_audio_url
string
Original extended audio file download link
data.data[].stream_audio_url
string
Streaming audio playback link
data.data[].image_url
string
Music cover image link
data.data[].prompt
string
Extension prompt used
data.data[].model_name
string
AI model name used for extension
data.data[].title
string
Extended music title
data.data[].tags
string
Music style tags
data.data[].createTime
string
Creation time
data.data[].duration
number
Extended audio duration (seconds)

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('/extend-callback', (req, res) => {
  const { code, msg, data } = req.body;
  
  console.log('Received music extension callback:', {
    taskId: data.task_id,
    callbackType: data.callbackType,
    status: code,
    message: msg
  });
  
  if (code === 200) {
    // Task successful
    const { callbackType, data: musicData } = data;
    
    switch (callbackType) {
      case 'text':
        console.log('Text generation completed');
        break;
        
      case 'first':
        console.log('First extended music track generated');
        if (musicData.length > 0) {
          console.log(`Extended music title: ${musicData[0].title}`);
          console.log(`Audio link: ${musicData[0].audio_url}`);
          console.log(`Duration: ${musicData[0].duration} seconds`);
        }
        break;
        
      case 'complete':
        console.log('All extended music tracks generated');
        console.log(`Total ${musicData.length} extended tracks:`);
        musicData.forEach((track, index) => {
          console.log(`Track ${index + 1}: ${track.title} - ${track.audio_url}`);
        });
        
        // Process extended music
        // Can download music, save locally, etc.
        break;
    }
    
  } else {
    // Task failed
    console.log('Music extension failed:', msg);
    
    // Handle failure cases...
    if (code === 400) {
      console.log('Invalid source audio or parameter error');
    } 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('Extension callback server running on port 3000');
});

Best Practices

Music Extension Callback Configuration

  1. Source Validation: Verify that the original audio source is valid before processing extension callbacks
  2. Duration Tracking: Monitor the extended duration to ensure it meets your requirements
  3. Quality Check: Implement quality checks for the extended audio segments
  4. Version Control: Keep track of extension iterations and maintain version history
  5. Fallback Handling: Implement fallback mechanisms if extension fails
  6. Seamless Integration: Ensure the extended portion integrates smoothly with the original track

Extension-Specific Considerations

  • Extension tasks require a valid source audio file
  • The continueAt parameter determines where the extension begins
  • Extended tracks maintain the style and characteristics of the original
  • Extension quality depends on the source audio quality
  • Some complex musical structures may be challenging to extend seamlessly

Troubleshooting

Common issues specific to music extension callbacks:

Alternative Solutions

If you cannot use the callback mechanism, you can also use polling:

Poll Extension Results

Use the Get Music Generation Details interface to regularly query extension task status. Recommend querying every 30 seconds.