> ## 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.

# Inpaint

> This endpoint allows users to replace a specific time segment of an audio clip using a textual prompt and optional lyrics. The inpainting operation blends new audio content into the selected range, guided by user-defined style and voice preferences.  

To use the inpaint feature, upload a song and specify the lyrics you want to replace in the field **'lyrics_section_to_replace'**. For best results, also provide the complete song lyrics in the **lyrics**.

Replace a specific segment of an audio file using a prompt and optional lyrics.

***

## Endpoint

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

This endpoint processes an input audio file along with a prompt, timestamp range, and optional lyrics to perform inpainting (replacement) in the specified segment.

***

## Request Parameters

| Parameter                   | Type         | Required | Description                                                                                                 |   |
| --------------------------- | ------------ | -------- | ----------------------------------------------------------------------------------------------------------- | - |
| `audio_file`                | `UploadFile` | Optional | Upload the input audio file. Required if `audio_url` is not provided.                                       |   |
| `audio_url`                 | `String`     | Optional | Public/S3/YouTube URL of the input audio. Required if `audio_file` is not provided.                         |   |
| `prompt`                    | `String`     | Required | Prompt describing how the replacement should sound. Example: "Replace this part with an opera-style vocal." |   |
| `replace_start_at`          | `Float`      | Required | Start time (in seconds) of the segment to replace.                                                          |   |
| `replace_end_at`            | `Float`      | Required | End time (in seconds) of the segment to replace.                                                            |   |
| `lyrics`                    | `String`     | Optional | Original lyrics of song.                                                                                    |   |
| `lyrics_section_to_replace` | `String`     | Optional | Lyrics to be used for the replaced portion(optional, max 3000 characters)                                   |   |
| `gender`                    | `String`     | Optional | Voice style for vocal generation. One of: `male`, `female`, `neutral`.                                      |   |
| `num_outputs`               | int          | Optional | The number of outputs to generate (1 or 2 only default : 1).                                                |   |
| `webhook_url`               | `String`     | Optional | Callback URL for async response.                                                                            |   |

> 💡 **Note:** You must provide either `audio_file` or `audio_url` — at least one is required.

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

***

## Sample Output

Listen to a real output:

Prompt: inpaint from 60 to 120 seconds in classical slow vibe - audio input : Moana How Far We will Go.
<audio controls="1" controlslist="nodownload nofullscreen noremoteplayback" src="https://lalals.s3.amazonaws.com/conversions/2104a105-2572-4412-b6fb-f67b0382582a.mp3">Your browser does not support the audio playback.</audio>

<a href="https://lalals.s3.amazonaws.com/conversions/2104a105-2572-4412-b6fb-f67b0382582a.wav" target="_blank">Download Audio</a>

***

## Try it Yourself

Visit the [Inpaint Endpoint Explorer](/api-documentation/endpoint/Inpaint) to test the endpoint — set your payload, hit send, and view the generated results.

***

## Sample Request

### cURL

```bash theme={null}
curl -X POST "https://api.musicgpt.com/api/public/v1/inpaint" \
-H "accept: application/json" \
-H "Authorization: <api_key>" \
-F "audio_file=@/path/to/audio.mp3" \
-F "prompt=Add a soft guitar solo here" \
-F "replace_start_at=12.5" \
-F "replace_end_at=20.0" \
-F "lyrics=This is where my story begins" \
-F "gender=male" \
-F "webhook_url=https://example.com/webhook"
```

### Python

```python theme={null}
import requests

url = "https://api.musicgpt.com/api/public/v1/inpaint"
headers = {"Authorization": "<API_KEY>"}
data = {
    "prompt": "Add a soft guitar solo here",
    "replace_start_at": 12.5,
    "replace_end_at": 20.0,
    "lyrics": "This is where my story begins",
    "gender": "male",
    "webhook_url": "https://example.com/webhook"
}

# Option 1: URL
files = {}
data["audio_url"] = "https://mybucket.s3.amazonaws.com/track.mp3"
response = requests.post(url, headers=headers, data=data, files=files)

# Option 2: File Upload
# with open("audio.mp3", "rb") as f:
#     files = {"audio_file": f}
#     response = requests.post(url, headers=headers, data=data, files=files)

print(response.json())
```

> 🔐 Replace `{path_to_your_audio_file}`, `api_key`, and `webhook_url` before executing.

***

## Sample Response

### Success (200 OK)

```json theme={null}
{
  "success": true,
  "message": "Inpaint request submitted successfully",
  "task_id": "task-xyz-123",
  "conversion_id_1": "inpaint-abc",
  "conversion_id_2": "inpaint-def",
  "eta": 40,
  "credit_estimate": 45
}
```

***

## Webhook Delivery

Once the generation is complete, **webhooks** will be triggered to deliver the following:

#### Standard Requests (non-instrumental):

* 2 (webhooks) x Inpaint conversion details (one per version)
* 2 (webhooks) x Lyrics with timestamp data
* 1 Album Cover Image

> Webhook responses include detailed metadata including task\_id, conversion\_id, audio files (conversion\_path), lyrics etc.

***

## Common Errors

* **422 Unprocessable Entity**: Missing required fields like `prompt`, `replace_start_at`, or `replace_end_at`, or neither `audio_file` nor `audio_url` provided.
* **500 Internal Server Error**: An unexpected error occurred during processing.

***

The response provides a downloadable or streamable inpainted audio file.

***

## Payload and Request Formation


## OpenAPI

````yaml POST /v1/inpaint
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/inpaint:
    post:
      summary: Inpaint an Audio Segment
      description: >-
        This endpoint allows users to replace a specific time segment of an
        audio clip using a textual prompt and optional lyrics. The inpainting
        operation blends new audio content into the selected range, guided by
        user-defined style and voice preferences.  


        To use the inpaint feature, upload a song and specify the lyrics you
        want to replace in the field **'lyrics_section_to_replace'**. For best
        results, also provide the complete song lyrics in the **lyrics**.
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                audio_file:
                  type: string
                  format: binary
                  description: Uploaded input audio file.
                audio_url:
                  type: string
                  description: URL or S3 path to the input audio.
                  example: https://mybucket.s3.amazonaws.com/song.mp3
                prompt:
                  type: string
                  description: A description of how the replacement should sound.
                  example: Replace this part with an opera-style vocal.
                replace_start_at:
                  type: number
                  format: float
                  description: Time in seconds to start replacing audio.
                  example: 12.5
                replace_end_at:
                  type: number
                  format: float
                  description: Time in seconds to stop replacing audio.
                  example: 20
                lyrics:
                  type: string
                  description: Lyrics to be used for inpainting.
                  example: This is where my story begins
                lyrics_section_to_replace:
                  type: string
                  description: >-
                    Lyrics to be used for the replaced portion(optional, max
                    3000 characters)
                  maxLength: 2000
                gender:
                  type: string
                  description: Voice style for the inpainted segment.
                  enum:
                    - male
                    - female
                    - neutral
                  example: male
                num_outputs:
                  type: number
                  format: integer
                  description: >-
                    The number of outputs to generate (1 or 2 only):default is
                    2.
                webhook_url:
                  type: string
                  description: Callback URL for async processing results.
                  example: https://example.com/webhook
              required:
                - prompt
                - replace_start_at
                - replace_end_at
              anyOf:
                - required:
                    - audio_url
                - required:
                    - audio_file
      responses:
        '200':
          description: Successfully initiated inpaint task
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  message:
                    type: string
                  task_id:
                    type: string
                  conversion_id_1:
                    type: string
                  conversion_id_2:
                    type: string
                  eta:
                    type: integer
                    description: Estimated processing time in seconds
                  credit_estimate:
                    type: number
                    format: float
                example:
                  success: true
                  message: Inpaint request submitted successfully
                  task_id: task-xyz-123
                  conversion_id_1: inpaint-abc
                  conversion_id_2: inpaint-def
                  eta: 40
                  credit_estimate: 45
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: false
                  error:
                    type: string
                    example: >-
                      audio_file or audio_url and valid replace range are
                      required.
        '500':
          description: Server Error
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: false
                  error:
                    type: string
                    example: Internal Server Error
      security:
        - ApiKeyAuth: []
      x-codeSamples:
        - lang: Python
          source: >-
            import requests


            url = "https://api.musicgpt.com/api/public/v1/inpaint"

            headers = {"Authorization": "<API_KEY>"}

            data = {
              "prompt": "Add a soft guitar solo here",
              "replace_start_at": 12.5,
              "replace_end_at": 20.0,
              "lyrics": "This is where my story begins",
              "lyrics_section_to_replace": "New lyrics",
              "gender": "male",
              "num_outputs": 1,
              "webhook_url": "https://example.com/webhook"
            }


            # Option 1: audio_url

            data["audio_url"] = "https://mybucket.s3.amazonaws.com/song.mp3"

            response = requests.post(url, headers=headers, data=data)


            # Option 2: File Upload

            # with open("song.mp3", "rb") as f:

            #     files = {"audio_file": f}

            #     response = requests.post(url, headers=headers, data=data,
            files=files)


            # print(response.json())
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization

````