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

# Generate music

> Starts a background job that generates a music track from a prompt. The response contains a
`job_id` to poll with `GET /music/{job_id}`, and the credits the job is expected to cost: the
model's per-minute price times the requested length (180 seconds
when `duration_seconds` is omitted). The job is charged for the length actually generated.
The finished track's `music_id` works as background music in the podcast endpoints.
Requires a valid `X-API-KEY` header.

Throws:
- 400 if the model is unknown, or `duration_seconds` is sent for a fixed-length model
- 402 if the workspace does not have enough credits, or the model is not available on its plan
- 422 if the request body is invalid



## OpenAPI

````yaml POST /music
openapi: 3.1.0
info:
  title: Wondercraft Public API
  version: 0.0.1
servers:
  - url: https://api.wondercraft.ai/v1
    description: Base Wondercraft API
security: []
paths:
  /music:
    post:
      tags:
        - Music
      summary: Generate music
      description: >-
        Starts a background job that generates a music track from a prompt. The
        response contains a

        `job_id` to poll with `GET /music/{job_id}`, and the credits the job is
        expected to cost: the

        model's per-minute price times the requested length (180 seconds

        when `duration_seconds` is omitted). The job is charged for the length
        actually generated.

        The finished track's `music_id` works as background music in the podcast
        endpoints.

        Requires a valid `X-API-KEY` header.


        Throws:

        - 400 if the model is unknown, or `duration_seconds` is sent for a
        fixed-length model

        - 402 if the workspace does not have enough credits, or the model is not
        available on its plan

        - 422 if the request body is invalid
      operationId: generate_music_music_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GenerateMusicApiRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateMusicJobResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKeyHeader: []
components:
  schemas:
    GenerateMusicApiRequest:
      properties:
        prompt:
          type: string
          maxLength: 2000
          minLength: 1
          title: Prompt
          description: Genre, mood, instruments, tempo, and lyrics if any
        model_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Model Id
          description: >-
            A model `id` from `GET /music/models`. Omit it for the default
            model.
        duration_seconds:
          anyOf:
            - type: integer
              maximum: 300
              minimum: 10
            - type: 'null'
          title: Duration Seconds
          description: >-
            Length of the track (10-300 seconds). Omit it to let the model
            choose; the estimate then assumes 180 seconds.
      additionalProperties: false
      type: object
      required:
        - prompt
      title: GenerateMusicApiRequest
    CreateMusicJobResponse:
      properties:
        job_id:
          type: string
          format: uuid
          title: Job Id
          description: Poll `GET /music/{job_id}` with this ID
        estimated_credits:
          type: number
          title: Estimated Credits
          description: >-
            Expected credits; the job is charged for the length actually
            generated
      type: object
      required:
        - job_id
        - estimated_credits
      title: CreateMusicJobResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      in: header
      name: X-API-KEY

````

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