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

# Extend

> This endpoint allows users to extend an existing audio file or stream by appending new audio content after a specific timestamp. The new audio is generated using a prompt (e.g., describing the desired sound) and optional lyrics.



## OpenAPI

````yaml POST /v1/extend
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/extend:
    post:
      summary: Extend Audio Using Prompt and Optional Lyrics
      description: >-
        This endpoint allows users to extend an existing audio file or stream by
        appending new audio content after a specific timestamp. The new audio is
        generated using a prompt (e.g., describing the desired sound) and
        optional lyrics.
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                audio_file:
                  type: string
                  format: binary
                  description: Uploaded audio file to be extended.
                audio_url:
                  type: string
                  description: URL or S3 path to the input audio.
                  example: https://mybucket.s3.amazonaws.com/song.mp3
                extend_after:
                  type: number
                  format: float
                  description: Time in seconds after which to start the extension.
                  example: 35
                prompt:
                  type: string
                  description: Describes how the extended section should sound.
                  example: Add a calming piano outro
                lyrics:
                  type: string
                  description: Original lyrics of song
                  example: Let the journey fade away
                  maxLength: 2000
                lyrics_section_to_extend:
                  type: string
                  description: >-
                    Lyrics to be used for the extended portion(optional, max
                    3000 characters).
                  maxLength: 3000
                gender:
                  type: string
                  description: Voice style if vocal content is generated.
                  enum:
                    - male
                    - female
                    - neutral
                  example: neutral
                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:
                - extend_after
              anyOf:
                - required:
                    - audio_url
                - required:
                    - audio_file
      responses:
        '200':
          description: Successfully initiated extend 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: Extend request submitted successfully
                  task_id: task-extend-789
                  conversion_id_1: extend-a1b2
                  conversion_id_2: extend-c3d4
                  eta: 38
                  credit_estimate: 42
        '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 extend_after 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/extend"

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

            data = {
              "extend_after": 35.0,
              "prompt": "Add a calming piano outro",
              "lyrics": "Let the journey fade away",
              "gender": "neutral", 
              "lyrics_section_to_extend": "New lyrics",
              "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

````