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

# AI Music Generator

> Generate music from a description, with optional custom lyrics or instrumental-only output. Costs 1 credits per requested second. Returns a project ID; poll GET /v1/audio-projects/{id} for status and downloads.



## OpenAPI

````yaml /api-reference/openapi.json post /v1/ai-music-generator
openapi: 3.0.2
info:
  title: Magic Hour API
  version: beta
  description: >

    Magic Hour provides a REST API (beta) for generating and editing video,
    images, and audio using AI.


    Webhook documentation can be found
    [here](https://docs.magichour.ai/webhook-reference).


    If you have any questions, please reach out to us via
    [discord](https://discord.gg/JX5rgsZaJp).


    # Authentication


    Every request requires an API key.


    To get started, first generate your API key
    [here](https://magichour.ai/developer?tab=api-keys&utm_source=docs&utm_medium=referral&utm_campaign=api-reference).


    Then, add the `Authorization` header to the request.


    | Key | Value |

    |-|-|

    | Authorization | Bearer mhk_live_apikey |


    > **Warning**: API generation and editing requests consume account credits.
    Cost varies by tool, model, and settings; see [API
    pricing](https://magichour.ai/api#api-cost-calculator).
  termsOfService: https://magichour.ai/terms-of-service
servers:
  - url: https://api.magichour.ai
security: []
tags:
  - name: Video Projects
    description: API related to video projects
  - name: Image Projects
    description: API related to image projects
  - name: Audio Projects
    description: API related to audio projects
  - name: Files
    description: API related to uploading and reusing assets
  - name: Account
    description: API related to the account that owns the API key
paths:
  /v1/ai-music-generator:
    post:
      tags:
        - Audio Projects
      summary: AI Music Generator
      description: >-
        Generate music from a description, with optional custom lyrics or
        instrumental-only output. Costs 1 credits per requested second. Returns
        a project ID; poll GET /v1/audio-projects/{id} for status and downloads.
      operationId: aiMusicGenerator.createAudio
      parameters: []
      requestBody:
        required: true
        description: Body
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  description: Give your audio a custom name for easy identification.
                  example: My Music Generator audio
                  default: AI Music Generator
                duration:
                  type: integer
                  minimum: 15
                  maximum: 300
                  description: >-
                    Requested track duration in seconds, from 15 to 300.
                    Determines credits charged.
                  example: 120
                style:
                  type: object
                  properties:
                    prompt:
                      type: string
                      minLength: 1
                      description: >-
                        Describe the song, including genre, mood, and
                        instruments.
                      example: Dreamy synthwave with warm bass and soft vocals
                    instrumental:
                      default: false
                      type: boolean
                      description: >-
                        Generate music without vocals. When true, lyrics is
                        ignored.
                      example: false
                    lyrics:
                      type: string
                      description: >-
                        Custom lyrics. Omit or leave blank for AI-generated
                        lyrics when instrumental is false.
                      example: City lights are fading...
                  required:
                    - prompt
                  additionalProperties: false
              required:
                - duration
                - style
              additionalProperties: false
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    example: cuid-example
                    description: >-
                      Unique ID of the audio. Use it with the [Get audio Project
                      API](https://docs.magichour.ai/api-reference/audio-projects/get-audio-details)
                      to fetch status and downloads.
                  credits_charged:
                    type: integer
                    description: >-
                      The amount of credits deducted from your account to
                      generate the audio. We charge credits right when the
                      request is made. 


                      If an error occurred while generating the audio, credits
                      will be refunded and this field will be updated to include
                      the refund.
                    example: 120
                required:
                  - id
                  - credits_charged
                description: Success
        '400':
          description: Invalid Request
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                  - message
                properties:
                  code:
                    type: string
                    enum:
                      - invalid_request
                    description: >-
                      Machine-readable error code.


                      - `invalid_request`: Fix request syntax or validation
                      errors before retrying.
                  message:
                    type: string
                    description: Human-readable error message.
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                  - message
                properties:
                  code:
                    type: string
                    enum:
                      - unauthorized
                    description: |-
                      Machine-readable error code.

                      - `unauthorized`: Provide a valid API key before retrying.
                  message:
                    type: string
                    description: Human-readable error message.
        '402':
          description: Payment Required
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                  - message
                properties:
                  code:
                    type: string
                    enum:
                      - insufficient_credits
                      - subscription_required
                      - plan_upgrade_required
                    description: >-
                      Machine-readable error code.


                      - `insufficient_credits`: Purchase credits before
                      retrying.


                      - `subscription_required`: Start a subscription before
                      retrying.


                      - `plan_upgrade_required`: Upgrade the subscription plan
                      before retrying.
                  message:
                    type: string
                    description: Human-readable error message.
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                  - message
                properties:
                  code:
                    type: string
                    enum:
                      - not_found
                    description: |-
                      Machine-readable error code.

                      - `not_found`: Check the route or resource identifier.
                  message:
                    type: string
                    description: Human-readable error message.
        '422':
          description: '422'
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                  - message
                properties:
                  code:
                    type: string
                    enum:
                      - unprocessable_entity
                    description: >-
                      Machine-readable error code.


                      - `unprocessable_entity`: Change the request values before
                      retrying.
                  message:
                    type: string
                    description: Human-readable error message.
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                  - message
                properties:
                  code:
                    type: string
                    enum:
                      - internal_server_error
                    description: >-
                      Machine-readable error code.


                      - `internal_server_error`: Retry later or contact support
                      if the error continues.
                  message:
                    type: string
                    description: Human-readable error message.
      security:
        - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Bearer authentication header of the form `Bearer <api_key>`, where
        `<api_key>` is your API key. To get your API key, go to [Developer
        Hub](https://magichour.ai/developer?tab=api-keys&utm_source=docs&utm_medium=referral&utm_campaign=api-reference)
        and click "Create new API Key".

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.