> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sunoapi.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Audio Separation Callbacks

> When vocal separation tasks are completed, the system will send results to your provided callback URL via POST request

When you submit a task to the Vocal Separation 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

<Info>
  The callback mechanism eliminates the need to poll the API for task status. The system will proactively push task completion results to your server.
</Info>

### Callback Timing

The system will send callback notifications in the following situations:

* Vocal separation task completed successfully
* Vocal separation task failed
* Errors occurred during task processing

### Callback Method

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

## Callback Request Format

When the task is completed, the system will send different format callback data based on the separation type you selected:

<CodeGroup>
  ```json separate_vocal Type Success Callback theme={null}
  {
    "code": 200,
    "data": {
      "task_id": "3e63b4cc88d52611159371f6af5571e7",
      "vocal_removal_info": {
        "instrumental_url": "https://file.aiquickdraw.com/s/d92a13bf-c6f4-4ade-bb47-f69738435528_Instrumental.mp3",
        "origin_url": "",
        "vocal_url": "https://file.aiquickdraw.com/s/3d7021c9-fa8b-4eda-91d1-3b9297ddb172_Vocals.mp3"
      }
    },
    "msg": "vocal Removal generated successfully."
  }
  ```

  ```json split_stem Type Success Callback theme={null}
  {
    "code": 200,
    "data": {
      "task_id": "e649edb7abfd759285bd41a47a634b10",
      "vocal_removal_info": {
        "origin_url": "",
        "backing_vocals_url": "https://file.aiquickdraw.com/s/aadc51a3-4c88-4c8e-a4c8-e867c539673d_Backing_Vocals.mp3",
        "bass_url": "https://file.aiquickdraw.com/s/a3c2da5a-b364-4422-adb5-2692b9c26d33_Bass.mp3",
        "brass_url": "https://file.aiquickdraw.com/s/334b2d23-0c65-4a04-92c7-22f828afdd44_Brass.mp3",
        "drums_url": "https://file.aiquickdraw.com/s/ac75c5ea-ac77-4ad2-b7d9-66e140b78e44_Drums.mp3",
        "fx_url": "https://file.aiquickdraw.com/s/a8822c73-6629-4089-8f2a-d19f41f0007d_FX.mp3",
        "guitar_url": "https://file.aiquickdraw.com/s/064dd08e-d5d2-4201-9058-c5c40fb695b4_Guitar.mp3",
        "keyboard_url": "https://file.aiquickdraw.com/s/adc934e0-df7d-45da-8220-1dba160d74e0_Keyboard.mp3",
        "percussion_url": "https://file.aiquickdraw.com/s/0f70884d-047c-41f1-a6d0-7044618b7dc6_Percussion.mp3",
        "strings_url": "https://file.aiquickdraw.com/s/49829425-a5b0-424e-857a-75d4c63a426b_Strings.mp3",
        "synth_url": "https://file.aiquickdraw.com/s/56b2d94a-eb92-4d21-bc43-3460de0c8348_Synth.mp3",
        "vocal_url": "https://file.aiquickdraw.com/s/07420749-29a2-4054-9b62-e6a6f8b90ccb_Vocals.mp3",
        "woodwinds_url": "https://file.aiquickdraw.com/s/d81545b1-6f94-4388-9785-1aaa6ecabb02_Woodwinds.mp3"
      }
    },
    "msg": "vocal Removal generated successfully."
  }
  ```

  ````json split_stem_advanced Type  Success Callback theme={null}
  {
    "code": 200,
    "msg": "vocal Removal generated successfully.",
    "data": {
      "task_id": "7220be2955295dda60de46ec6e4ead4c",
      "vocal_removal_info": {
        "origin_data": [
          {
            "extract": {
              "duration": 194.92,
              "audio_url": "https://tempfile.aiquickdraw.com/r/eb7d0f18-8349-4735-a65e-1812705d5ddf_Lead Vocal.mp3",
              "stem_type_group_name": "Lead Vocal",
              "id": "eb7d0f18-8349-4735-a65e-1812705d5ddf"
            },
            "remove": {
              "duration": 194.92,
              "audio_url": "https://tempfile.aiquickdraw.com/r/706d32df-e988-412e-bce4-42c9302e5478_Lead Vocal.mp3",
              "stem_type_group_name": "Lead Vocal",
              "id": "706d32df-e988-412e-bce4-42c9302e5478"
            }
          },
          {
            "extract": {
              "duration": 194.92,
              "audio_url": "https://tempfile.aiquickdraw.com/r/a7c503f6-1265-4f7e-bf5d-c50fb3b07238_Lead Vocal.mp3",
              "stem_type_group_name": "Lead Vocal",
              "id": "a7c503f6-1265-4f7e-bf5d-c50fb3b07238"
            },
            "remove": {
              "duration": 194.92,
              "audio_url": "https://tempfile.aiquickdraw.com/r/a3a0c954-1980-410f-9b34-8539b8eb23f8_Lead Vocal.mp3",
              "stem_type_group_name": "Lead Vocal",
              "id": "a3a0c954-1980-410f-9b34-8539b8eb23f8"
            }
          }
        ]
      }
    }
  }

  ```json Failure Callback
  {
    "code": 400,
    "msg": "Vocal separation failed",
    "data": {
      "task_id": "5e72d367bdfbe44785e28d72cb1697c7",
      "vocal_removal_info": null
    }
  }
  ````
</CodeGroup>

## Status Code Description

<ParamField path="code" type="integer" required>
  Callback status code indicating task processing result:

  | Status Code | Description                                                        |
  | ----------- | ------------------------------------------------------------------ |
  | 200         | Success - Vocal separation completed                               |
  | 400         | Bad Request - Parameter error, unsupported audio file format, etc. |
  | 451         | Download Failed - Unable to download source audio file             |
  | 500         | Server Error - Please try again later                              |
</ParamField>

<ParamField path="msg" type="string" required>
  Status message providing detailed status description
</ParamField>

<ParamField path="data.task_id" type="string" required>
  Task ID, consistent with the taskId returned when you submitted the task
</ParamField>

<ParamField path="data.vocal_removal_info" type="object">
  Vocal separation result information, returned on success
</ParamField>

## separate\_vocal Type Field Description

<ParamField path="data.vocal_removal_info.origin_url" type="string">
  Original mixed audio file URL
</ParamField>

<ParamField path="data.vocal_removal_info.instrumental_url" type="string">
  Instrumental-only audio file URL (vocals removed)
</ParamField>

<ParamField path="data.vocal_removal_info.vocal_url" type="string">
  Vocals-only audio file URL (instrumental removed)
</ParamField>

## split\_stem Type Field Description

<ParamField path="data.vocal_removal_info.origin_url" type="string">
  Original mixed audio file URL
</ParamField>

<ParamField path="data.vocal_removal_info.vocal_url" type="string">
  Vocals-only audio file URL
</ParamField>

<ParamField path="data.vocal_removal_info.backing_vocals_url" type="string">
  Backing vocals audio file URL
</ParamField>

<ParamField path="data.vocal_removal_info.drums_url" type="string">
  Drums audio file URL
</ParamField>

<ParamField path="data.vocal_removal_info.bass_url" type="string">
  Bass audio file URL
</ParamField>

<ParamField path="data.vocal_removal_info.guitar_url" type="string">
  Guitar audio file URL
</ParamField>

<ParamField path="data.vocal_removal_info.keyboard_url" type="string">
  Keyboard audio file URL
</ParamField>

<ParamField path="data.vocal_removal_info.percussion_url" type="string">
  Percussion audio file URL
</ParamField>

<ParamField path="data.vocal_removal_info.strings_url" type="string">
  Strings audio file URL
</ParamField>

<ParamField path="data.vocal_removal_info.synth_url" type="string">
  Synthesizer audio file URL
</ParamField>

<ParamField path="data.vocal_removal_info.fx_url" type="string">
  Effects audio file URL
</ParamField>

<ParamField path="data.vocal_removal_info.brass_url" type="string">
  Brass audio file URL
</ParamField>

<ParamField path="data.vocal_removal_info.woodwinds_url" type="string">
  Woodwinds audio file URL
</ParamField>

### split\_stem\_advanced Type Field Description

<ParamField path="data.vocal_removal_info.origin_data" type="array">
  An array of separation results for the original audio, containing extraction and removal information for multiple stem groups. Each element represents an independent stem group (e.g., Lead Vocal).
</ParamField>

<ParamField path="data.vocal_removal_info.origin_data[].extract" type="object">
  Information about the extracted target stem (isolates this stem while removing others).
</ParamField>

<ParamField path="data.vocal_removal_info.origin_data[].extract.duration" type="number">
  The duration of the extracted audio, in seconds.
</ParamField>

<ParamField path="data.vocal_removal_info.origin_data[].extract.audio_url" type="string">
  The download URL of the extracted target stem audio file.
</ParamField>

<ParamField path="data.vocal_removal_info.origin_data[].extract.stem_type_group_name" type="string">
  The stem type group name (e.g., Lead Vocal), indicating which type of stem this group extracts.
</ParamField>

<ParamField path="data.vocal_removal_info.origin_data[].extract.id" type="string">
  The unique identifier for the extracted audio.
</ParamField>

<ParamField path="data.vocal_removal_info.origin_data[].remove" type="object">
  Information about the remaining audio after removing the target stem (removes this stem while keeping others).
</ParamField>

<ParamField path="data.vocal_removal_info.origin_data[].remove.duration" type="number">
  The duration of the audio after removal, in seconds.
</ParamField>

<ParamField path="data.vocal_removal_info.origin_data[].remove.audio_url" type="string">
  The download URL of the remaining audio file after the target stem has been removed.
</ParamField>

<ParamField path="data.vocal_removal_info.origin_data[].remove.stem_type_group_name" type="string">
  The stem type group name (e.g., Lead Vocal), consistent with the corresponding extract entry.
</ParamField>

<ParamField path="data.vocal_removal_info.origin_data[].remove.id" type="string">
  The unique identifier for the remaining audio.
</ParamField>

## Callback Reception Examples

Here are example codes for receiving callbacks in popular programming languages:

<Tabs>
  <Tab title="Node.js">
    ```javascript theme={null}
    const express = require('express');
    const app = express();

    app.use(express.json());

    app.post('/vocal-separation-callback', (req, res) => {
      const { code, msg, data } = req.body;
      
      console.log('Received vocal separation callback:', {
        taskId: data.task_id,
        status: code,
        message: msg
      });
      
      if (code === 200) {
        // Task completed successfully
        console.log('Vocal separation completed');
        const vocalInfo = data.vocal_removal_info;
        
        if (vocalInfo) {
          console.log('Separation results:');
          console.log(`  Original audio: ${vocalInfo.origin_url}`);
          
          // Handle different separation types
          if (vocalInfo.instrumental_url) {
            // separate_vocal type
            console.log(`  Instrumental only: ${vocalInfo.instrumental_url}`);
            console.log(`  Vocals only: ${vocalInfo.vocal_url}`);
          } else {
            // split_stem type
            console.log(`  Vocals: ${vocalInfo.vocal_url}`);
            console.log(`  Backing vocals: ${vocalInfo.backing_vocals_url}`);
            console.log(`  Drums: ${vocalInfo.drums_url}`);
            console.log(`  Bass: ${vocalInfo.bass_url}`);
            console.log(`  Guitar: ${vocalInfo.guitar_url}`);
            console.log(`  Keyboard: ${vocalInfo.keyboard_url}`);
            console.log(`  Percussion: ${vocalInfo.percussion_url}`);
            console.log(`  Strings: ${vocalInfo.strings_url}`);
            console.log(`  Synthesizer: ${vocalInfo.synth_url}`);
            console.log(`  Effects: ${vocalInfo.fx_url}`);
            console.log(`  Brass: ${vocalInfo.brass_url}`);
            console.log(`  Woodwinds: ${vocalInfo.woodwinds_url}`);
          }
          
          // Download separated audio files
          const https = require('https');
          const fs = require('fs');
          
          const downloadFile = (url, filename) => {
            if (!url) return;
            
            const file = fs.createWriteStream(filename);
            https.get(url, (response) => {
              response.pipe(file);
              file.on('finish', () => {
                file.close();
                console.log(`Saved: ${filename}`);
              });
            }).on('error', (err) => {
              console.error(`Download failed ${filename}:`, err.message);
            });
          };
          
          // Download all available audio files
          Object.keys(vocalInfo).forEach(key => {
            if (vocalInfo[key] && key.endsWith('_url')) {
              const filename = `${data.task_id}_${key.replace('_url', '')}.mp3`;
              downloadFile(vocalInfo[key], filename);
            }
          });
        }
        
      } else {
        // Task failed
        console.log('Vocal separation failed:', msg);
        
        // Handle failure cases...
        if (code === 400) {
          console.log('Parameter error or unsupported audio format');
        } 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');
    });
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    from flask import Flask, request, jsonify
    import requests

    app = Flask(__name__)

    @app.route('/vocal-separation-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')
        vocal_info = callback_data.get('vocal_removal_info')
        
        print(f"Received vocal separation callback: {task_id}, status: {code}, message: {msg}")
        
        if code == 200:
            # Task completed successfully
            print("Vocal separation completed")
            
            if vocal_info:
                print("Separation results:")
                print(f"  Original audio: {vocal_info.get('origin_url')}")
                
                # Handle different separation types
                if vocal_info.get('instrumental_url'):
                    # separate_vocal type
                    print(f"  Instrumental only: {vocal_info.get('instrumental_url')}")
                    print(f"  Vocals only: {vocal_info.get('vocal_url')}")
                else:
                    # split_stem type
                    print(f"  Vocals: {vocal_info.get('vocal_url')}")
                    print(f"  Backing vocals: {vocal_info.get('backing_vocals_url')}")
                    print(f"  Drums: {vocal_info.get('drums_url')}")
                    print(f"  Bass: {vocal_info.get('bass_url')}")
                    print(f"  Guitar: {vocal_info.get('guitar_url')}")
                    print(f"  Keyboard: {vocal_info.get('keyboard_url')}")
                    print(f"  Percussion: {vocal_info.get('percussion_url')}")
                    print(f"  Strings: {vocal_info.get('strings_url')}")
                    print(f"  Synthesizer: {vocal_info.get('synth_url')}")
                    print(f"  Effects: {vocal_info.get('fx_url')}")
                    print(f"  Brass: {vocal_info.get('brass_url')}")
                    print(f"  Woodwinds: {vocal_info.get('woodwinds_url')}")
                
                # Download separated audio files
                def download_file(url, filename):
                    if not url:
                        return
                        
                    try:
                        response = requests.get(url)
                        if response.status_code == 200:
                            with open(filename, "wb") as f:
                                f.write(response.content)
                            print(f"Saved: {filename}")
                    except Exception as e:
                        print(f"Download failed {filename}: {e}")
                
                # Download all available audio files
                for key, url in vocal_info.items():
                    if url and key.endswith('_url'):
                        filename = f"{task_id}_{key.replace('_url', '')}.mp3"
                        download_file(url, filename)
                    
        else:
            # Task failed
            print(f"Vocal separation failed: {msg}")
            
            # Handle failure cases...
            if code == 400:
                print("Parameter error or unsupported audio format")
            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)
    ```
  </Tab>

  <Tab title="PHP">
    ```php theme={null}
    <?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'] ?? '';
    $vocalInfo = $callbackData['vocal_removal_info'] ?? null;

    error_log("Received vocal separation callback: $taskId, status: $code, message: $msg");

    if ($code === 200) {
        // Task completed successfully
        error_log("Vocal separation completed");
        
        if ($vocalInfo) {
            error_log("Separation results:");
            error_log("  Original audio: " . ($vocalInfo['origin_url'] ?? ''));
            
            // Handle different separation types
            if (isset($vocalInfo['instrumental_url'])) {
                // separate_vocal type
                error_log("  Instrumental only: " . ($vocalInfo['instrumental_url'] ?? ''));
                error_log("  Vocals only: " . ($vocalInfo['vocal_url'] ?? ''));
            } else {
                // split_stem type
                error_log("  Vocals: " . ($vocalInfo['vocal_url'] ?? ''));
                error_log("  Backing vocals: " . ($vocalInfo['backing_vocals_url'] ?? ''));
                error_log("  Drums: " . ($vocalInfo['drums_url'] ?? ''));
                error_log("  Bass: " . ($vocalInfo['bass_url'] ?? ''));
                error_log("  Guitar: " . ($vocalInfo['guitar_url'] ?? ''));
                error_log("  Keyboard: " . ($vocalInfo['keyboard_url'] ?? ''));
                error_log("  Percussion: " . ($vocalInfo['percussion_url'] ?? ''));
                error_log("  Strings: " . ($vocalInfo['strings_url'] ?? ''));
                error_log("  Synthesizer: " . ($vocalInfo['synth_url'] ?? ''));
                error_log("  Effects: " . ($vocalInfo['fx_url'] ?? ''));
                error_log("  Brass: " . ($vocalInfo['brass_url'] ?? ''));
                error_log("  Woodwinds: " . ($vocalInfo['woodwinds_url'] ?? ''));
            }
            
            // Download separated audio files
            function downloadFile($url, $filename) {
                if (!$url) return;
                
                try {
                    $content = file_get_contents($url);
                    if ($content !== false) {
                        file_put_contents($filename, $content);
                        error_log("Saved: $filename");
                    }
                } catch (Exception $e) {
                    error_log("Download failed $filename: " . $e->getMessage());
                }
            }
            
            // Download all available audio files
            foreach ($vocalInfo as $key => $url) {
                if ($url && strpos($key, '_url') !== false) {
                    $filename = $taskId . '_' . str_replace('_url', '', $key) . '.mp3';
                    downloadFile($url, $filename);
                }
            }
        }
        
    } else {
        // Task failed
        error_log("Vocal separation failed: $msg");
        
        // Handle failure cases...
        if ($code === 400) {
            error_log("Parameter error or unsupported audio format");
        } 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']);
    ?>
    ```
  </Tab>
</Tabs>

## Best Practices

<Tip>
  ### 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. **File Management**: Separated audio file download and processing should be done in asynchronous tasks
  7. **Type Detection**: Determine separation type based on returned fields and apply corresponding processing logic
</Tip>

<Warning>
  ### 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 file URLs may have time limits, recommend downloading and saving promptly
  * split\_stem mode produces more files, pay attention to storage space management
  * Ensure source audio file contains corresponding musical components for optimal separation results
  * Different separation types have different callback structures, requiring appropriate processing logic
</Warning>

## Troubleshooting

If you do not receive callback notifications, please check the following:

<AccordionGroup>
  <Accordion title="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
  </Accordion>

  <Accordion title="Server Response Issues">
    * 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
  </Accordion>

  <Accordion title="Content Format Issues">
    * Confirm that the received POST request body is in JSON format
    * Check that Content-Type is application/json
    * Verify that JSON parsing is correct
    * Ensure proper handling of different separation type data structures
  </Accordion>

  <Accordion title="Audio Processing Issues">
    * Confirm that separated audio file URLs are accessible
    * Check audio download permissions and network connections
    * Verify audio save paths and permissions
    * Note how source audio file quality affects separation results
    * Confirm source audio file format is supported
    * split\_stem mode requires checking more audio files
  </Accordion>
</AccordionGroup>

## Alternative Solution

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

<Card title="Poll Query Results" icon="radar" href="/suno-api/get-vocal-separation-details">
  Use the get vocal separation details endpoint to regularly query task status. We recommend querying every 30 seconds.
</Card>
