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

# MusicGen

> Generate music based on textual prompts and optional conditioning melodies.

## Request

Make a `POST` request to below endpoint and pass the required parameters as a request body.

```curl curl theme={null}
--request POST 'https://modelslab.com/api/v6/voice/music_gen' 
```

## Body

Without `init_audio`:

```json json theme={null}
{
    "key":"your_api_key",
    "prompt":"marimba, percussion, bass, tropical house, melodic riff, G# minor, 96 bpm",
    "duration": 30,
    "output_format": "wav",
    "bitrate": "320k",
    "base64":false,
    "temp": false,
    "webhook": null,
    "track_id": null
}
```

With `init_audio`:

```json json theme={null}
{
    "key":"your_api_key",
    "prompt":"marimba, percussion, bass, tropical house, melodic riff, G# minor, 96 bpm",
    "init_audio":"https://youtu.be/7Nm6uTHbB-Y?si=ORk1LOQ8J34Z0Lpm",
    "duration": 30,
    "output_format": "wav",
    "bitrate": "320k",
    "base64":false,
    "temp": false,
    "webhook": null,
    "track_id": null
}
```


## OpenAPI

````yaml POST /voice/music_gen
openapi: 3.1.0
info:
  title: ModelsLab Voice API
  description: >-
    A comprehensive API for AI-driven voice and audio generation including
    text-to-speech, voice cloning, music generation, and audio processing
    capabilities
  license:
    name: MIT
  version: 6.0.0
servers:
  - url: https://modelslab.com/api/v6
security: []
paths:
  /voice/music_gen:
    post:
      summary: Generate music from text prompt
      description: >-
        Creates music based on textual prompts with optional conditioning
        melodies
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MusicGenRequest'
      responses:
        '200':
          description: Music generation response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/VoiceResponse'
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    MusicGenRequest:
      type: object
      required:
        - key
        - prompt
      properties:
        key:
          type: string
          description: Your API Key for request authorization
        prompt:
          type: string
          description: Input text for music generation
        init_audio:
          type: string
          format: uri
          description: Conditioning melody URL for music generation (up to 30 seconds)
        duration:
          type: integer
          default: 30
          minimum: 30
          maximum: 480
          description: >-
            Duration of the generated music in seconds. Any arbitrary value
            between 30 and 480. Default: 30.
        output_format:
          type: string
          enum:
            - wav
            - mp3
            - flac
          default: wav
          description: >-
            Output format of the generated audio. Options: wav, mp3, flac.
            Default: wav.
        bitrate:
          type: string
          enum:
            - 128k
            - 192k
            - 320k
          default: 320k
          description: >-
            Bitrate of the generated audio file. Options: 128k, 192k, 320k.
            Default: 320k.
        base64:
          type: boolean
          default: false
          description: Whether input sound clip is in base64 format
        temp:
          type: boolean
          default: false
          description: Use temporary links for regions blocking storage access
        webhook:
          type: string
          format: uri
          description: URL to receive POST callback upon completion
        track_id:
          type: integer
          description: Unique ID for identifying webhook responses
    VoiceResponse:
      type: object
      properties:
        status:
          type: string
          enum:
            - success
            - processing
            - error
          description: Status of the voice generation
        generationTime:
          type: number
          description: Time taken to generate the audio in seconds
        id:
          type: integer
          description: Unique identifier for the voice generation
        output:
          type: array
          items:
            type: string
            format: uri
          description: Array of generated audio URLs
        proxy_links:
          type: array
          items:
            type: string
            format: uri
          description: Array of proxy audio URLs
        future_links:
          type: array
          items:
            type: string
            format: uri
          description: Array of future audio URLs for queued requests
        links:
          type: array
          items:
            type: string
            format: uri
          description: Array of audio URLs (voice cover response)
        meta:
          type: object
          description: Metadata about the audio generation including all parameters used
        eta:
          type: integer
          description: Estimated time for completion in seconds (processing status)
        message:
          type: string
          description: Status message or additional information
        tip:
          type: string
          description: Additional information or tips for the user
        fetch_result:
          type: string
          format: uri
          description: URL to fetch the result when processing
        audio_time:
          type: number
          description: Duration of the generated audio in seconds
    Error:
      type: object
      required:
        - status
        - message
      properties:
        status:
          type: string
          enum:
            - error
        message:
          type: string
          description: Error message description

````