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



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

````