> For the documentation index, fetch https://sync.so/docs/llms.txt. Append .md to a page URL for Markdown. Documentation-search MCP: https://sync.so/docs/_mcp/server.

# Trim Audio

POST https://api.sync.so/v2/audio-trims
Content-Type: application/json

Prepare a new audio asset from the first durationSeconds of an audio file. Provide exactly one source: assetId or a sourceUrl for audio hosted in Sync storage that you can access. Returns 202 with the trim. Poll GET /v2/audio-trims/\{id} until status is completed or failed. Use the completed assetId as an audio input to a generation.
A source you cannot access returns 404. Unsupported sources can return 422 audio\_trim\_source\_not\_hosted or audio\_trim\_source\_not\_allowed. Each organization can have 4 trims in progress and start 60 per hour; requests beyond these limits return 429 audio\_trim\_rate\_limited.

Reference: https://sync.so/docs/api-reference/api/audio-trims-api/create

## Authentication

- `x-api-key` header (required) — API Key authentication via header

## Servers

- `https://api.sync.so` (Default, default)
- `https://dev-api.sync.so` (dev)
- `http://localhost:3001` (local)

## Request

### Headers

- `Idempotency-Key` (string, required) — Required. 1–128 characters matching [A-Za-z0-9._~-]+, scoped to your organization and the calling user or API key. Retrying with the same key and body returns the original trim; reusing the key with a different body returns 409.

### Body (application/json)

This endpoint expects a CreateAudioTrimDto.

- `durationSeconds` (double, required) — Length of the audio to keep from the start, in seconds (0.01–3600).
- `assetId` (string, optional) — ID of a saved audio asset you can access.
- `sourceUrl` (string, optional) — URL of audio stored in sync. storage for your organization.
- `projectId` (string, optional) — Project to add the trimmed audio asset to.

## Response

### 202

Trim accepted.

- `id` (string, required) — Unique identifier for the trim.
- `status` (enum, required) — Status of an audio trim. Terminal states are completed and failed.
  - Allowed values: `queued`, `processing`, `completed`, `failed`
- `retryAfterMs` (integer, required) — Milliseconds to wait before polling again. 0 once the trim is completed or failed.
- `assetId` (string, optional) — ID of the trimmed audio asset. Null until status is completed.
- `durationSeconds` (double, optional) — Measured duration of the trimmed audio in seconds. Null until status is completed.
- `errorCode` (string, optional) — audio_trim_failed when status is failed; otherwise null.

## Errors

### 401 Unauthorized Error

Unauthorized - Invalid or missing authentication

- `message` (GenerationErrorMessage, required) — A message describing the error.
- `statusCode` (double, required) — The type of error that occurred.
- `errorCode` (string, optional) — Stable, machine-readable error code (e.g. project_not_found, voice_not_found, concurrency_limit_reached). Branch your error handling on this, not on the message text. The full catalog of codes with messages and suggested fixes is served unauthenticated at GET /v2/errors.
- `suggestion` (string, optional) — A suggested fix an agent can act on.
- `field` (string, optional) — The request field the error refers to, when the failure is tied to a specific field (e.g. projectId, voiceId, input[].assetId).
- `docsUrl` (string, optional) — Link to the documentation page for the failing operation.
- `billingUrl` (string, optional) — Billing page for resolving a payment, plan, or allowance issue, when applicable.
- `requestId` (string, optional) — Present on unexpected 500 responses. Include it when contacting support so the failing request can be located directly.
- `generationId` (string, optional) — Original generation ID when available for an uncertain keyed submission or a DUPLICATE_SUBMISSION. Poll this ID; do not create another action to bypass IDEMPOTENCY_OUTCOME_UNKNOWN.
- `dialogueEditSection` (DialogueEditRetimeFailureSection, optional) — For dialogue_edit_removal_too_large: the section to change, when it can be identified. Create a new dialogue edit preview before submitting again.
- `lineNumber` (integer, optional) — For batch creation, on dialogue edit refusals only: the 1-based line of the refused record, counting non-empty JSONL lines. With a `rows` body, line N is `rows[N-1]`. Other record errors name the line only in `message`.

### 400 Bad Request Error

Bad Request - Invalid input or unsupported model

- `message` (GenerationErrorMessage, required) — A message describing the error.
- `statusCode` (double, required) — The type of error that occurred.
- `errorCode` (string, optional) — Stable, machine-readable error code (e.g. project_not_found, voice_not_found, concurrency_limit_reached). Branch your error handling on this, not on the message text. The full catalog of codes with messages and suggested fixes is served unauthenticated at GET /v2/errors.
- `suggestion` (string, optional) — A suggested fix an agent can act on.
- `field` (string, optional) — The request field the error refers to, when the failure is tied to a specific field (e.g. projectId, voiceId, input[].assetId).
- `docsUrl` (string, optional) — Link to the documentation page for the failing operation.
- `billingUrl` (string, optional) — Billing page for resolving a payment, plan, or allowance issue, when applicable.
- `requestId` (string, optional) — Present on unexpected 500 responses. Include it when contacting support so the failing request can be located directly.
- `generationId` (string, optional) — Original generation ID when available for an uncertain keyed submission or a DUPLICATE_SUBMISSION. Poll this ID; do not create another action to bypass IDEMPOTENCY_OUTCOME_UNKNOWN.
- `dialogueEditSection` (DialogueEditRetimeFailureSection, optional) — For dialogue_edit_removal_too_large: the section to change, when it can be identified. Create a new dialogue edit preview before submitting again.
- `lineNumber` (integer, optional) — For batch creation, on dialogue edit refusals only: the 1-based line of the refused record, counting non-empty JSONL lines. With a `rows` body, line N is `rows[N-1]`. Other record errors name the line only in `message`.

### 404 Not Found Error

Job not found

- `message` (GenerationErrorMessage, required) — A message describing the error.
- `statusCode` (double, required) — The type of error that occurred.
- `errorCode` (string, optional) — Stable, machine-readable error code (e.g. project_not_found, voice_not_found, concurrency_limit_reached). Branch your error handling on this, not on the message text. The full catalog of codes with messages and suggested fixes is served unauthenticated at GET /v2/errors.
- `suggestion` (string, optional) — A suggested fix an agent can act on.
- `field` (string, optional) — The request field the error refers to, when the failure is tied to a specific field (e.g. projectId, voiceId, input[].assetId).
- `docsUrl` (string, optional) — Link to the documentation page for the failing operation.
- `billingUrl` (string, optional) — Billing page for resolving a payment, plan, or allowance issue, when applicable.
- `requestId` (string, optional) — Present on unexpected 500 responses. Include it when contacting support so the failing request can be located directly.
- `generationId` (string, optional) — Original generation ID when available for an uncertain keyed submission or a DUPLICATE_SUBMISSION. Poll this ID; do not create another action to bypass IDEMPOTENCY_OUTCOME_UNKNOWN.
- `dialogueEditSection` (DialogueEditRetimeFailureSection, optional) — For dialogue_edit_removal_too_large: the section to change, when it can be identified. Create a new dialogue edit preview before submitting again.
- `lineNumber` (integer, optional) — For batch creation, on dialogue edit refusals only: the 1-based line of the refused record, counting non-empty JSONL lines. With a `rows` body, line N is `rows[N-1]`. Other record errors name the line only in `message`.

### 409 Conflict Error

Conflict - The resource is in a state that does not allow the requested action (e.g. deleting a generation that is still processing). For creation, generation_conflict indicates a duplicate internal backend submission. Keyed creates return IDEMPOTENCY_KEY_CONFLICT for a changed payload or IDEMPOTENCY_IN_PROGRESS while the original request prepares or the previous attempt is still being finalized (Retry-After: 2). Retry only with the same key and original inputs after an ambiguous network failure. An API-key create without Idempotency-Key that is identical to one your organization sent in the last 60 seconds returns DUPLICATE_SUBMISSION with the original generationId once it was accepted; poll that generation, or send a unique Idempotency-Key with each intended generation. See [Idempotent Requests](/docs/api-reference/guides/idempotency).

- `message` (GenerationErrorMessage, required) — A message describing the error.
- `statusCode` (double, required) — The type of error that occurred.
- `errorCode` (string, optional) — Stable, machine-readable error code (e.g. project_not_found, voice_not_found, concurrency_limit_reached). Branch your error handling on this, not on the message text. The full catalog of codes with messages and suggested fixes is served unauthenticated at GET /v2/errors.
- `suggestion` (string, optional) — A suggested fix an agent can act on.
- `field` (string, optional) — The request field the error refers to, when the failure is tied to a specific field (e.g. projectId, voiceId, input[].assetId).
- `docsUrl` (string, optional) — Link to the documentation page for the failing operation.
- `billingUrl` (string, optional) — Billing page for resolving a payment, plan, or allowance issue, when applicable.
- `requestId` (string, optional) — Present on unexpected 500 responses. Include it when contacting support so the failing request can be located directly.
- `generationId` (string, optional) — Original generation ID when available for an uncertain keyed submission or a DUPLICATE_SUBMISSION. Poll this ID; do not create another action to bypass IDEMPOTENCY_OUTCOME_UNKNOWN.
- `dialogueEditSection` (DialogueEditRetimeFailureSection, optional) — For dialogue_edit_removal_too_large: the section to change, when it can be identified. Create a new dialogue edit preview before submitting again.
- `lineNumber` (integer, optional) — For batch creation, on dialogue edit refusals only: the 1-based line of the refused record, counting non-empty JSONL lines. With a `rows` body, line N is `rows[N-1]`. Other record errors name the line only in `message`.

### 422 Unprocessable Entity Error

Unprocessable Entity - The requested generation is not downloadable (generation_not_downloadable), or submit-time validation failed (e.g. inaccessible media, invalid segments, a projectId/voiceId/assetId that does not resolve in your organization, or a file exceeding the plan size limit). The body carries a stable errorCode and, where applicable, the failing field.

- `message` (GenerationErrorMessage, required) — A message describing the error.
- `statusCode` (double, required) — The type of error that occurred.
- `errorCode` (string, optional) — Stable, machine-readable error code (e.g. project_not_found, voice_not_found, concurrency_limit_reached). Branch your error handling on this, not on the message text. The full catalog of codes with messages and suggested fixes is served unauthenticated at GET /v2/errors.
- `suggestion` (string, optional) — A suggested fix an agent can act on.
- `field` (string, optional) — The request field the error refers to, when the failure is tied to a specific field (e.g. projectId, voiceId, input[].assetId).
- `docsUrl` (string, optional) — Link to the documentation page for the failing operation.
- `billingUrl` (string, optional) — Billing page for resolving a payment, plan, or allowance issue, when applicable.
- `requestId` (string, optional) — Present on unexpected 500 responses. Include it when contacting support so the failing request can be located directly.
- `generationId` (string, optional) — Original generation ID when available for an uncertain keyed submission or a DUPLICATE_SUBMISSION. Poll this ID; do not create another action to bypass IDEMPOTENCY_OUTCOME_UNKNOWN.
- `dialogueEditSection` (DialogueEditRetimeFailureSection, optional) — For dialogue_edit_removal_too_large: the section to change, when it can be identified. Create a new dialogue edit preview before submitting again.
- `lineNumber` (integer, optional) — For batch creation, on dialogue edit refusals only: the 1-based line of the refused record, counting non-empty JSONL lines. With a `rows` body, line N is `rows[N-1]`. Other record errors name the line only in `message`.

### 429 Audio Trim Too Many Requests Error

Too Many Requests - Audio trim concurrency or request-rate limit reached (audio_trim_rate_limited). Follow the response retry guidance.

- `message` (GenerationErrorMessage, required) — A message describing the error.
- `statusCode` (double, required) — The type of error that occurred.
- `errorCode` (string, optional) — Stable, machine-readable error code (e.g. project_not_found, voice_not_found, concurrency_limit_reached). Branch your error handling on this, not on the message text. The full catalog of codes with messages and suggested fixes is served unauthenticated at GET /v2/errors.
- `suggestion` (string, optional) — A suggested fix an agent can act on.
- `field` (string, optional) — The request field the error refers to, when the failure is tied to a specific field (e.g. projectId, voiceId, input[].assetId).
- `docsUrl` (string, optional) — Link to the documentation page for the failing operation.
- `billingUrl` (string, optional) — Billing page for resolving a payment, plan, or allowance issue, when applicable.
- `requestId` (string, optional) — Present on unexpected 500 responses. Include it when contacting support so the failing request can be located directly.
- `generationId` (string, optional) — Original generation ID when available for an uncertain keyed submission or a DUPLICATE_SUBMISSION. Poll this ID; do not create another action to bypass IDEMPOTENCY_OUTCOME_UNKNOWN.
- `dialogueEditSection` (DialogueEditRetimeFailureSection, optional) — For dialogue_edit_removal_too_large: the section to change, when it can be identified. Create a new dialogue edit preview before submitting again.
- `lineNumber` (integer, optional) — For batch creation, on dialogue edit refusals only: the 1-based line of the refused record, counting non-empty JSONL lines. With a `rows` body, line N is `rows[N-1]`. Other record errors name the line only in `message`.

## Types

### GenerationErrorMessage

A message describing the error.

- string
- list of string

### DialogueEditRetimeFailureSection

The dialogue-edit section that removes too much speech to stay in sync.

- `slotIndex` (integer, required) — Zero-based index of the section in the preview's `resultSlots`.
- `sourceStartMs` (integer, optional) — Start of the section in the source video, in absolute milliseconds.
- `sourceDurationMs` (integer, optional) — Length of the section in the source video, in milliseconds.

## Examples

**Request**

```json
{
  "durationSeconds": 20,
  "assetId": "3f2b8c1e-5d4a-4e9b-8c7d-1a2b3c4d5e6f"
}
```

**Response**

```json
{
  "id": "6533643b-aceb-4c40-967e-d9ba9baac39e",
  "status": "queued",
  "retryAfterMs": 2000,
  "assetId": null,
  "durationSeconds": null,
  "errorCode": null
}
```

**SDK Code**

```python
import requests

url = "https://api.sync.so/v2/audio-trims"

payload = {
    "durationSeconds": 20,
    "assetId": "3f2b8c1e-5d4a-4e9b-8c7d-1a2b3c4d5e6f"
}
headers = {
    "Idempotency-Key": "trim-intro-20s",
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.sync.so/v2/audio-trims';
const options = {
  method: 'POST',
  headers: {
    'Idempotency-Key': 'trim-intro-20s',
    'x-api-key': '<apiKey>',
    'Content-Type': 'application/json'
  },
  body: '{"durationSeconds":20,"assetId":"3f2b8c1e-5d4a-4e9b-8c7d-1a2b3c4d5e6f"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.sync.so/v2/audio-trims"

	payload := strings.NewReader("{\n  \"durationSeconds\": 20,\n  \"assetId\": \"3f2b8c1e-5d4a-4e9b-8c7d-1a2b3c4d5e6f\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Idempotency-Key", "trim-intro-20s")
	req.Header.Add("x-api-key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.sync.so/v2/audio-trims")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = 'trim-intro-20s'
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"durationSeconds\": 20,\n  \"assetId\": \"3f2b8c1e-5d4a-4e9b-8c7d-1a2b3c4d5e6f\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.sync.so/v2/audio-trims")
  .header("Idempotency-Key", "trim-intro-20s")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"durationSeconds\": 20,\n  \"assetId\": \"3f2b8c1e-5d4a-4e9b-8c7d-1a2b3c4d5e6f\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.sync.so/v2/audio-trims', [
  'body' => '{
  "durationSeconds": 20,
  "assetId": "3f2b8c1e-5d4a-4e9b-8c7d-1a2b3c4d5e6f"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'Idempotency-Key' => 'trim-intro-20s',
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.sync.so/v2/audio-trims");
var request = new RestRequest(Method.POST);
request.AddHeader("Idempotency-Key", "trim-intro-20s");
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"durationSeconds\": 20,\n  \"assetId\": \"3f2b8c1e-5d4a-4e9b-8c7d-1a2b3c4d5e6f\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Idempotency-Key": "trim-intro-20s",
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "durationSeconds": 20,
  "assetId": "3f2b8c1e-5d4a-4e9b-8c7d-1a2b3c4d5e6f"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.sync.so/v2/audio-trims")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```