# Video to Video (Music) API

Canonical docs: https://platform.sonilo.com/docs/api/video-to-video-music
Source path: /docs/api/video-to-video-music
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/video-to-video-music

## Summary

Generate a music-scored version of a video, muxed with the original picture and delivered as a new video file. By default the returned video's audio is the generated music alone; set keep_original_sound=true to keep the source track, mixed in or ducked under the music with ducking=true. Generated audio carries an inaudible provenance watermark.

## Use This For

- Delivering a finished clip with the generated soundtrack already muxed in.
- The same video-native music generation as /v1/video-to-music, returned as an mp4 instead of a bare audio file.
- Skipping a separate mux step in editors, AI video apps, and automated pipelines.

## Related Guide

- [Generate music from a video file or URL with the REST API](https://sonilo.com/blog/guides/generate-music-from-video-file-url-rest-api): a walkthrough that sends a video file or a public video URL.

## Request

Content type: multipart/form-data

- `video` (file; optional): Accepted formats: mp4, mov, m4v, or webm carrying H.264, H.265/HEVC, VP9, or AV1 video. The source picture is copied into the result without re-encoding, so animated gif and VP8 webm are not supported. Max 300MB by default; max duration 360 seconds.
- `video_url` (string; optional): Downloaded before generation starts, so the same accepted formats, 300MB size limit, and 360-second duration limit apply as for video. An over-size download is rejected with 413.
- `prompt` (string; optional): Optional text prompt describing the music to generate, up to 2000 characters. For best results, omit this and let the model infer a soundtrack from the on-screen action and visuals.
- `segments` (string; optional): Optional JSON array of timed segment prompts; the music changes style at each boundary. Each item has `start` (seconds; the first must be 0, starts strictly increasing and at least 5 seconds apart, the last at least 5 seconds before the end of the video), `prompt` (1-200 characters), and an optional `label` that must be exactly one of these values — any other value is rejected with a 422 error, and it defaults to `none` when omitted: `intro`, `verse`, `pre-chorus`, `chorus`, `bridge`, `break`, `silence`, `outro`, `none`. 1-30 items.
- `preserve_speech` (boolean; optional): Isolates the source video's speech and keeps only that as the voice source. Superseded by keep_original_sound: when that is also set, the whole original track is kept as the voice source instead of just the isolated speech.
- `isolate_vocals` (boolean; optional): Legacy alias for preserve_speech; the two are ORed together, not separate behaviors.
- `ducking` (boolean; optional; default `false`): Selects how the voice source combines with the generated music in the returned video's audio: off (default) mixes it in statically, on ducks it dynamically under the music. The voice source is the whole original track when keep_original_sound is set, the isolated vocals when only preserve_speech is set, or nothing at all when neither is set — with no voice source, ducking has no effect and the returned audio is the generated music alone. Best-effort: falls back to music-only audio if voice isolation or the duck/mix pass fails.
- `keep_original_sound` (boolean; optional; default `false`): Keeps the whole source video's audio track as the voice source, instead of the isolated vocals (preserve_speech) or no voice source at all. Defaults to false: by default the returned video's audio is the generated music alone, with the source's own audio removed. Supersedes preserve_speech when both are set.
- `prompt_influence` (number; optional; default `0.5`; 0 to 1): How strongly the generated music follows the prompt: lower values let the video lead, higher values follow the prompt more literally. Omit to keep the default behavior. Free of charge.
- `variants_num` (integer; optional; default `1`; 1 to 10): How many distinct music variants to generate in one request. Each variant is a separate creative direction, returned as its own entry in the async result's `videos` array. Cost scales linearly — `variants_num=3` costs three times a single-variant request. Values above 1 are never covered by the free trial and are always billed.

Machine-readable schema: https://platform.sonilo.com/openapi.json

### Usage notes

- Provide exactly one of video or video_url. Max file size: default 300MB. Max duration: 360 sec.
- keep_original_sound, preserve_speech, and ducking decide what happens to the source audio; keep_original_sound supersedes preserve_speech.

## Response And Errors

- 202 returns task_id and status=processing.
- Poll GET /v1/tasks/{task_id} every 2-3 seconds.
- On success, download video.url: the source video with the generated music muxed in (mp4). videos lists one entry per variant.
- 401 auth_invalid, 402 payment_required or insufficient_balance, 403 forbidden, 404 not_found, and 429 Retry-After should be handled explicitly.

## Example

```bash
curl -X POST "https://api.sonilo.com/v1/video-to-video-music" \
  -H "Authorization: Bearer sk_your_api_key" \
  -F "video_url=https://example.com/clip.mp4" \
  -F "prompt=warm acoustic soundtrack for a travel vlog"
```

## 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/video-to-video-music
- POST /v1/audio-ducking
- POST /v1/text-to-sfx
- POST /v1/video-to-sfx
- POST /v1/video-to-video-sfx
- POST /v1/video-to-sound
- POST /v1/video-to-video-sound
- GET /v1/tasks/{task_id}

