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

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 - Vocal generation completed
400Bad Request - Parameter error or content violation
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 vocal track generated
  • complete: All vocal 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
Vocal generation result information, returned on success
data.data[].id
string
Audio unique identifier (audioId)
data.data[].audio_url
string
Audio file download link with vocals
data.data[].source_audio_url
string
Original source audio file download link
data.data[].stream_audio_url
string
Streaming audio playback link with vocals
data.data[].image_url
string
Music cover image link
data.data[].prompt
string
Prompt/lyrics used for vocal generation
data.data[].model_name
string
AI model name used for vocal generation
data.data[].title
string
Music title with vocals
data.data[].tags
string
Music style tags including vocal characteristics
data.data[].createTime
string
Creation time
data.data[].duration
number
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('/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');
});

Best Practices

Vocal Generation Callback 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: Ensure processing logic is idempotent as the same taskId may receive multiple callbacks
  4. Quick Response: Callback processing should return 200 status code quickly to avoid timeout
  5. Asynchronous Processing: Complex business logic should be processed asynchronously to avoid blocking callback response
  6. Stage-based Processing: Handle different callback stages (text, first, complete) with appropriate business logic
  7. Vocal Content Analysis: Implement vocal content analysis and quality assessment for generated tracks
  8. 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:

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.