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

# Audio Cutter

> Trims an audio file using the specified start and end times.

Trim your audio files with precision using AI.

**Audio Cutter** allows you to select specific sections of audio recordings, making it perfect for creating highlights, clips, ringtones, and more.

* Easily extract the best parts of any audio
* Supports multiple formats like MP3, WAV, FLAC, and more
* Fast processing with high-quality output

Audio Cutter ensures your trimmed audio sounds clean and professional.

***

## Endpoint

```http theme={null}
POST /audio_cutter
```

Use this endpoint to trim a section from an existing audio file.

***

## Sample Output

Listen to the trimmed audio:
<audio controls="1" controlslist="nodownload nofullscreen noremoteplayback" src="https://lalals.s3.amazonaws.com/FileConversions/8993b364-9141-4de7-ab38-5a4178618f0e.mp3">Your browser does not support audio playback.</audio>

<a href="https://lalals.s3.amazonaws.com/FileConversions/8993b364-9141-4de7-ab38-5a4178618f0e.wav" target="_blank">Download Audio</a>

***

## Try it Yourself

Visit the [Audio Cutter Endpoint Explorer](/api-documentation/endpoint/audio_cutter) to cut and download trimmed audio segments instantly.

> ✂️ Try trimming different parts to see how accurate the cut is!

***

## Request Parameters

| Parameter          | Type   | Required | Description                                           |
| ------------------ | ------ | -------- | ----------------------------------------------------- |
| `audio_path`       | String | Yes      | The S3 path of the input audio file to trim           |
| `conversion_id`    | String | Yes      | A unique identifier for the conversion request        |
| `start_time`       | Float  | Yes      | The start time (in milliseconds) of the audio to trim |
| `end_time`         | Float  | Yes      | The end time (in milliseconds) of the audio to trim   |
| `output_extension` | String | Yes      | Output format: mp3, wav, flac, ogg, aac, or webm      |

> **content-type:** multipart/form-data

***

## Sample Request

### Python

```python theme={null}
import requests

url = "https://api.musicgpt.com/api/public/v1/audio_cutter"
headers = {"Authorization": "<API_KEY>"}

# Option 1: Using audio URL
payload = {
    "audio_url": "https://example.com/input_audio.mp3",
    "start_time": 10500,
    "end_time": 45000,
    "output_extension": "mp3"
}
response = requests.post(url, headers=headers, data=payload)
print(response.json())

# Option 2: Upload local audio file
payload = {
    "start_time": 5000,
    "end_time": 20000,
    "output_extension": "wav"
}
with open("input_audio.mp3", "rb") as f:
    files = {"audio_file": f}
    response = requests.post(url, headers=headers, data=payload, files=files)
print(response.json())
```

***

## Sample Response

### Success (200 OK)

```json theme={null}
{
  "success":true,
  "task_id":"b0ac9d46-64d7-4843-af48-a0b6effe3666",
  "conversion_id":"fe19945b-d466-4183-b559-5d264bddd492",
  "eta":66,
  "credit_estimate":25.0,
  "message":"Message published to queue",
  "status":"IN_QUEUE"
}
```

***

## Webhook Response

When audio cutter conversion completes, your webhook will receive:

```json theme={null}
{
  "success": true, 
  "conversion_type": "Audio Cutter", 
  "task_id": "8993b364-9141-4de7-ab38-5a4178618f0e", 
  "conversion_id": "3f07f1ba-9eb5-4581-95ed-427eac1dda0c", 
  "output_file": "https://lalals.s3.amazonaws.com/FileConversions/8993b364-9141-4de7-ab38-5a4178618f0e.mp3", 
  "message": "Audio cutter completed"
} 
```

> 📂 The `conversion_path` field contains the direct link to download the trimmed audio.

***

## Payload and Request Formation


## OpenAPI

````yaml POST /v1/audio_cutter
openapi: 3.1.0
info:
  title: Musicgpt API
  version: 1.0.0
  description: API for retrieving conversion details by ID.
servers:
  - url: https://api.musicgpt.com/api/public
    description: Production server
security: []
paths:
  /v1/audio_cutter:
    post:
      summary: Cut an audio file between specified timestamps
      description: Trims an audio file using the specified start and end times.
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                audio_url:
                  type: string
                  description: URL of the input audio to be trimmed.
                  example: https://example.com/input_audio.mp3
                audio_file:
                  type: string
                  format: binary
                  description: Audio file to upload and process directly.
                start_time:
                  type: number
                  format: float
                  description: Start time in milliseconds.
                  example: 10500
                end_time:
                  type: number
                  format: float
                  description: End time in milliseconds.
                  example: 45000
                output_extension:
                  type: string
                  enum:
                    - mp3
                    - wav
                    - flac
                    - ogg
                    - aac
                    - webm
                  description: Desired output format.
                  example: mp3
                webhook_url:
                  type: string
                  description: Callback URL for async processing results.
                  example: http://your-webhook-url.com/callback
              required:
                - start_time
                - end_time
              anyOf:
                - required:
                    - audio_url
                - required:
                    - audio_file
      responses:
        '200':
          description: Successfully initiated audio cut
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  conversion_id:
                    type: string
                  credit_estimate:
                    type: number
                    format: float
                  conversion_path:
                    type: string
                  message:
                    type: string
                example:
                  success: true
                  conversion_id: conv789
                  credit_estimate: 25
                  conversion_path: https://example.com/trimmed_audio.mp3
                  message: Audio trim task queued successfully
        '400':
          description: Invalid parameters
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: false
                  error:
                    type: string
                    example: Invalid time range specified
        '401':
          description: Invalid authentication
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: false
                  error:
                    type: string
                    example: Authentication failed
        '402':
          description: Insufficient credits
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: false
                  error:
                    type: string
                    example: Insufficient credits for this operation
                  required_credits:
                    type: number
                    example: 25
                  available_credits:
                    type: number
                    example: 10
        '404':
          description: User or plan not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: false
                  error:
                    type: string
                    example: User subscription plan not found
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: false
                  error:
                    type: string
                    example: Internal server error during audio trimming
      security:
        - ApiKeyAuth: []
      x-codeSamples:
        - lang: Python
          source: |-
            import requests

            url = "https://api.musicgpt.com/api/public/v1/audio_cutter"
            headers = {"Authorization": "<API_KEY>"}

            # Option 1: Using audio URL
            payload = {
                "audio_url": "https://example.com/input_audio.mp3",
                "start_time": 10500,
                "end_time": 45000,
                "output_extension": "mp3"
            }
            response = requests.post(url, headers=headers, data=payload)
            print(response.json())

            # Option 2: Upload local audio file
            payload = {
                "start_time": 5000,
                "end_time": 20000,
                "output_extension": "wav"
            }
            with open("input_audio.mp3", "rb") as f:
                files = {"audio_file": f}
                response = requests.post(url, headers=headers, data=payload, files=files)
            print(response.json())
        - lang: PHP
          source: |-
            <?php
            $url = 'https://api.musicgpt.com/api/public/v1/audio_cutter';
            $headers = ['Authorization: <API_KEY>'];

            $data = [
                'audio_url' => 'https://example.com/input_audio.mp3',
                'start_time' => 10500,
                'end_time' => 45000,
                'output_extension' => 'mp3'
            ];

            $ch = curl_init($url);
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $response = curl_exec($ch);
            curl_close($ch);
            echo $response;
        - lang: Go
          source: "package main\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"net/http\"\n\t\"strings\"\n)\n\nfunc main() {\n\turl := \"https://api.musicgpt.com/api/public/v1/audio_cutter\"\n\ttoken := \"<API_KEY>\"\n\tdata := \"audio_url=https://example.com/input_audio.mp3&start_time=10500&end_time=45000&output_extension=mp3\"\n\n\treq, _ := http.NewRequest(\"POST\", url, strings.NewReader(data))\n\treq.Header.Add(\"Authorization\", token)\n\tres, _ := http.DefaultClient.Do(req)\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\tfmt.Println(string(body))\n}"
        - lang: Java
          source: // Java version omitted for brevity; request if needed.
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization

````