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

# Generate music

> <Info>This API is in beta. Endpoints, fields, and behavior may still change, so avoid depending on it in production.</Info>

Generates a track from a prompt, stores it in the app's files and returns its URL. Answers once the track is ready, which can take a minute. Pick a model and length from List models (`type=music`). Billed to the app's credits at the same price as an AI gateway call.

For an estimate that generates and charges nothing, send the body you plan to generate with and add `dry_run: true`. The price depends on the model and the length, so an estimate for a different body can be off. Send an `Idempotency-Key` with each generation, and the same key when you retry it, so a retry isn't charged twice.

When the model provider fails, the same request usually fails the same way again, so try another model rather than resending it unchanged.



## OpenAPI

````yaml /developers/references/app-management/app-management-openapi.json post /api/apps/{app_id}/media/music
openapi: 3.1.0
info:
  title: Base44 App Management API
  version: 1.0.0
servers:
  - url: https://app.base44.com
security:
  - PersonalAccessTokenAuth: []
paths:
  /api/apps/{app_id}/media/music:
    post:
      summary: Generate music
      description: >-
        <Info>This API is in beta. Endpoints, fields, and behavior may still
        change, so avoid depending on it in production.</Info>


        Generates a track from a prompt, stores it in the app's files and
        returns its URL. Answers once the track is ready, which can take a
        minute. Pick a model and length from List models (`type=music`). Billed
        to the app's credits at the same price as an AI gateway call.


        For an estimate that generates and charges nothing, send the body you
        plan to generate with and add `dry_run: true`. The price depends on the
        model and the length, so an estimate for a different body can be off.
        Send an `Idempotency-Key` with each generation, and the same key when
        you retry it, so a retry isn't charged twice.


        When the model provider fails, the same request usually fails the same
        way again, so try another model rather than resending it unchanged.
      operationId: create_music_api_apps__app_id__media_music_post
      parameters:
        - name: app_id
          in: path
          required: true
          schema:
            type: string
            description: ID of the app to generate media for.
            title: App Id
          description: ID of the app to generate media for.
          example: 6820f3a4e7b91d003c45a1f2
        - name: Idempotency-Key
          in: header
          required: false
          schema:
            type: string
            description: >-
              One key per operation, 1 to 128 characters. A retry with the same
              key and request within 24 hours returns the first response.
            examples:
              - 7f3c9a2e-retry-1
            title: Idempotency-Key
          description: >-
            One key per operation, 1 to 128 characters. A retry with the same
            key and request within 24 hours returns the first response.
        - name: X-Active-Branch-Id
          in: header
          required: false
          schema:
            type: string
            description: >-
              ID of the branch the editor shows. Used when `branch_id` is
              omitted, for users who work on protected-main branches.
            title: X-Active-Branch-Id
          description: >-
            ID of the branch the editor shows. Used when `branch_id` is omitted,
            for users who work on protected-main branches.
          example: 68f1a2b3c4d5e6f708192a3b
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateMusicRequest'
      responses:
        '200':
          description: The stored track, or an estimate for a dry run.
          content:
            application/json:
              schema:
                anyOf:
                  - $ref: '#/components/schemas/MusicResponse'
                  - $ref: '#/components/schemas/Estimate'
                title: Response Create Music Api Apps  App Id  Media Music Post
              example:
                url: >-
                  https://media.base44.com/files/public/6820f3a4/music_1a2b3c4d.mp3
                model: lyria_3_5
                duration_seconds: 30
                usage:
                  credits: 6
        '400':
          description: >-
            The request can't be served (`invalid_request_error`,
            `model_not_found`), for example an option the model doesn't support.
            `details.param` names the field.
          content:
            application/json:
              examples:
                invalid_request_error:
                  summary: invalid_request_error
                  value:
                    error:
                      code: invalid_request_error
                      message: '`n` must be between 1 and 4.'
                      details:
                        param: 'n'
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '402':
          description: >-
            The app's workspace doesn't have enough credits
            (`insufficient_quota`).
          content:
            application/json:
              examples:
                insufficient_quota:
                  summary: insufficient_quota
                  value:
                    error:
                      code: insufficient_quota
                      message: Not enough credits.
                      details: {}
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '403':
          description: >-
            The workspace's AI policy turns off media generation for this app
            (`forbidden`).
          content:
            application/json:
              examples:
                forbidden:
                  summary: forbidden
                  value:
                    error:
                      code: forbidden
                      message: AI media generation is turned off for this app.
                      details: {}
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '404':
          description: >-
            The API or music isn't enabled for you or this app, or the app
            doesn't exist or you can't edit it (`not_found`).
          content:
            application/json:
              examples:
                not_found:
                  summary: not_found
                  value:
                    error:
                      code: not_found
                      message: Not found.
                      details: {}
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '409':
          description: >-
            `idempotency_in_progress`: A request with this `Idempotency-Key` is
            still running, or its outcome isn't known yet.
          content:
            application/json:
              examples:
                idempotency_in_progress:
                  summary: idempotency_in_progress
                  value:
                    error:
                      code: idempotency_in_progress
                      message: >-
                        A request with this Idempotency-Key is still running.
                        Retry shortly.
                      details: {}
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '422':
          description: >-
            The request body is invalid (`detail`). `idempotency_key_reused`:
            The `Idempotency-Key` was already used with a different request.
            `invalid_request`: The `Idempotency-Key` header is empty or longer
            than 128 characters.
          content:
            application/json:
              examples:
                idempotency_key_reused:
                  summary: idempotency_key_reused
                  value:
                    error:
                      code: idempotency_key_reused
                      message: >-
                        This Idempotency-Key was already used with a different
                        request.
                      details: {}
                invalid_request:
                  summary: invalid_request
                  value:
                    error:
                      code: invalid_request
                      message: Idempotency-Key must be 1 to 128 characters.
                      details: {}
              schema:
                anyOf:
                  - $ref: '#/components/schemas/HTTPValidationError'
                  - $ref: '#/components/schemas/StandardErrorEnvelope'
        '429':
          description: >-
            Too many requests (`rate_limited`). The base limit is 10 requests
            per 60 seconds for each caller, raised by your plan's multiplier.
            Retry after the `Retry-After` seconds.
          content:
            application/json:
              examples:
                rate_limited:
                  summary: rate_limited
                  value:
                    error:
                      code: rate_limited
                      message: Rate limit exceeded.
                      details: {}
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '502':
          description: >-
            The model provider or file storage couldn't complete the request
            (`internal_error`).
          content:
            application/json:
              examples:
                internal_error:
                  summary: internal_error
                  value:
                    error:
                      code: internal_error
                      message: Internal server error
                      details: {}
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '503':
          description: >-
            Database temporarily unavailable (`database_unavailable`): the data
            cluster did not answer in time. Retry after the `Retry-After`
            seconds.
          headers:
            Retry-After:
              description: Seconds to wait before retrying.
              schema:
                type: integer
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
              examples:
                database_unavailable:
                  summary: database_unavailable
                  value:
                    error:
                      code: database_unavailable
                      message: Database temporarily unavailable, please retry
                      details: {}
      security:
        - PersonalAccessTokenAuth:
            - full_access
        - WorkspaceApiKeyAuth:
            - full_access
        - WorkspaceApiKeyBearerAuth:
            - full_access
components:
  schemas:
    CreateMusicRequest:
      properties:
        dry_run:
          type: boolean
          title: Dry Run
          description: >-
            `true` returns a credit estimate without generating or charging;
            omit or `false` to generate
          default: false
        model:
          anyOf:
            - type: string
              maxLength: 100
            - type: 'null'
          title: Model
          description: >-
            model alias or vendor ID; prefer `"automatic"` (or omit it), which
            selects a fixed default
          examples:
            - automatic
        prompt:
          type: string
          maxLength: 10000
          minLength: 1
          title: Prompt
          description: >-
            required; style, mood and optional lyrics, with sections marked by
            tags such as `[Verse]` and `[Chorus]`. Never name a real artist or
            use copyrighted lyrics, which the provider refuses
          examples:
            - Upbeat acoustic jingle for a bakery
        duration_seconds:
          anyOf:
            - type: integer
            - type: 'null'
          title: Duration Seconds
          description: >-
            whole seconds within the model's range; omitted uses the default. An
            `approximate` model treats it as a target and may run longer
        instrumental:
          type: boolean
          title: Instrumental
          description: >-
            true asks for a track without vocals (a `best effort` model may
            still sing, so keep lyrics out of an instrumental prompt)
          default: false
        response_format:
          anyOf:
            - type: string
              maxLength: 20
            - type: 'null'
          title: Response Format
          description: only `"mp3"`
      additionalProperties: false
      type: object
      required:
        - prompt
      title: CreateMusicRequest
    MusicResponse:
      properties:
        url:
          type: string
          title: Url
          description: >-
            Public URL of the stored track. Anyone with the link can open it,
            and the link doesn't expire.
        model:
          type: string
          title: Model
          description: The model that made it.
          examples:
            - lyria_3_5
        duration_seconds:
          type: integer
          title: Duration Seconds
          description: The requested length in seconds.
          examples:
            - 30
        usage:
          $ref: '#/components/schemas/MediaUsage'
      type: object
      required:
        - url
        - model
        - duration_seconds
        - usage
      title: MusicResponse
    Estimate:
      properties:
        dry_run:
          type: boolean
          const: true
          title: Dry Run
          description: 'Always `true`: nothing was generated or charged.'
        model:
          type: string
          title: Model
          description: The model that would serve the request.
          examples:
            - gpt_image_2
        usage:
          $ref: '#/components/schemas/MediaUsage'
      type: object
      required:
        - dry_run
        - model
        - usage
      title: Estimate
    StandardErrorEnvelope:
      properties:
        error:
          $ref: '#/components/schemas/StandardError'
          description: What went wrong.
      type: object
      required:
        - error
      title: StandardErrorEnvelope
      description: The error body returned in the standard envelope.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    MediaUsage:
      properties:
        credits:
          type: number
          title: Credits
          description: Credits charged to the app, or the estimate for a dry run.
          examples:
            - 4
      type: object
      required:
        - credits
      title: MediaUsage
    StandardError:
      properties:
        code:
          type: string
          title: Code
          description: >-
            Stable machine-readable cause of the failure. Match on this, not on
            `message`.
          example: not_found
        message:
          type: string
          title: Message
          description: Human-readable explanation. It isn't a stable contract.
          example: App not found
        details:
          additionalProperties: true
          type: object
          title: Details
          description: >-
            Structured context for the failure, or an empty object when there's
            none.
          example: {}
      type: object
      required:
        - code
        - message
      title: StandardError
    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:
    PersonalAccessTokenAuth:
      type: http
      scheme: bearer
      description: >-
        Personal access token, sent as `Authorization: Bearer <token>`. Each
        operation lists the permission it needs: `read_only` or `full_access`. A
        full-access token can call every operation. A read-only token can call
        only the operations that list `read_only`; anything else returns 403
        `read_only_credential_route_not_allowed`.
    WorkspaceApiKeyAuth:
      type: apiKey
      in: header
      name: api_key
      description: >-
        Workspace API key, sent as `api_key: <key>`. Each operation that accepts
        one lists what the key needs: a permission, `read_only` or
        `full_access`, like a personal access token, or a scope. A key without
        the scope gets 403 `workspace_api_key_scope_required`.
    WorkspaceApiKeyBearerAuth:
      type: http
      scheme: bearer
      description: >-
        Workspace API key, sent as `Authorization: Bearer <key>`. Accepted
        wherever `api_key` is, with the same permission.

````

## Related topics

- [Generate music with the AI Gateway](https://docs.base44.com/developers/references/sdk/getting-started/ai-gateway-music.md)
- [Using Base44 built-in integrations](https://docs.base44.com/Integrations/built-in-integrations.md)
- [Using integrations](https://docs.base44.com/Integrations/Using-integrations.md)
- [Generate images with the AI Gateway](https://docs.base44.com/developers/references/sdk/getting-started/ai-gateway-images.md)
- [Generate video with the AI Gateway](https://docs.base44.com/developers/references/sdk/getting-started/ai-gateway-video.md)


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