# Audio Ducking API

Canonical docs: https://platform.sonilo.com/docs/api/audio-ducking
Source path: /docs/api/audio-ducking
Runtime API host: https://api.sonilo.com/v1

Do not send API requests to platform.sonilo.com, docs.sonilo.com, or local docs URLs. Documentation pages are for reading only. Send runtime requests to https://api.sonilo.com/v1 with Authorization: Bearer sk_your_api_key.

## Endpoint

POST /v1/audio-ducking

## Summary

Mix foreground speech or narration with background music by lowering music under voice and returning a post-production output.

## Use This For

- Ducking music under narration for videos, ads, tutorials, podcasts, and social clips.
- Combining voice_file or voice_url with music_file or music_url.
- Agent-built audio post-production workflows that submit a job and poll for the output_url.

## Request

- voice_file or voice_url: foreground speech input.
- music_file or music_url: background music input.
- ducking_ratio, attack_ms, release_ms, output_format: optional mix controls.

## Response And Errors

- 202 returns task_id and status=processing.
- Poll GET /v1/tasks/{task_id} every 2-3 seconds until status is succeeded, failed, or canceled.
- On success, use output_url or audio.url from the task response.
- 401, 402, 403, 404, and 429 have the same auth, balance, permission, not-found, and Retry-After meanings as other endpoints.

## Example

```bash
curl -X POST "https://api.sonilo.com/v1/audio-ducking" \
  -H "Authorization: Bearer sk_your_api_key" \
  -F "voice_file=@voice.wav" \
  -F "music_file=@music.wav"
```

## Shared Error Handling

- 401 auth_invalid: set Authorization: Bearer sk_your_api_key on the request.
- 402 payment_required or insufficient_balance: add credits before rerunning; do not create fake audio.
- 403 forbidden: the key is valid but the account or service permission is missing.
- 404 not_found: check the endpoint path and host. Use https://api.sonilo.com/v1, not a docs URL.
- 429 rate_limit_exceeded: honor Retry-After and retry with backoff.

## Endpoint Vocabulary

- GET /v1/account/services
- GET /v1/account/usage
- POST /v1/text-to-music
- POST /v1/video-to-music
- POST /v1/audio-ducking
- POST /v1/text-to-sfx
- POST /v1/video-to-sfx
- GET /v1/tasks/{task_id}

