POST
/
inpaint
Python
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: 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())
{
  "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
}
Replace a specific segment of an audio file using a prompt and optional lyrics.

Endpoint

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

ParameterTypeRequiredDescription
audio_fileUploadFileOptionalUpload the input audio file. Required if audio_url is not provided.
audio_urlStringOptionalPublic/S3/YouTube URL of the input audio. Required if audio_file is not provided.
promptStringRequiredPrompt describing how the replacement should sound. Example: β€œReplace this part with an opera-style vocal.”
replace_start_atFloatRequiredStart time (in seconds) of the segment to replace.
replace_end_atFloatRequiredEnd time (in seconds) of the segment to replace.
lyricsStringOptionalOptional lyrics to use for inpainting.
genderStringOptionalVoice style for vocal generation. One of: male, female, neutral.
webhook_urlStringOptionalCallback URL for async response.
πŸ’‘ Note: You must provide either audio_file or audio_url β€” at least one is required.

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. Download Audio

Try it Yourself

Visit the Inpaint Endpoint Explorer to test the endpoint β€” set your payload, hit send, and view the generated results.

Sample Request

cURL

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

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)

{
  "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 Remix conversion details (one per version)
  • 2 (webhooks) x Lyrics with timestamp data
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

Authorizations

Authorization
string
header
required

Body

multipart/form-data

Response

200
application/json

Successfully initiated inpaint task

The response is of type object.