---
title: "Generate background music"
method: POST
path: "/api/ai/music"
tags: ["Audio"]
deprecated: true
---

# Generate background music

`POST /api/ai/music`

## Request

- Base URL: `https://your-deployment.example.com`
- URL: `https://your-deployment.example.com/api/ai/music`
- Auth: one of:
  - HTTP bearer
  - API key in header `x-api-key`

> **Deprecated.**

**Deprecated, sunset 2027-01-15.** Use `/api/v1/music-generations` instead. Generates an instrumental or vocal background-music track from a text prompt. `lengthMs` (3000-120000, default 10000) is forced on the provider, so the generated track always matches the billed length; credits are reserved before generation and refunded if it fails. The default `encoding: "binary"` returns the raw audio bytes; `encoding: "base64"` returns JSON. Audio over the ~4MB response ceiling is returned by signed URL (a `303` for binary, the `delivery: "url"` variant for base64). Generated audio is saved to the file browser unless the call sets `preview`; the outcome is reported in the JSON save fields and the `X-B4M-Audio-*` headers - fetch the saved copy from `fileUrl` / `X-B4M-Audio-File-Url`, since `GET /api/files/{id}` fails closed until moderation completes. Authenticate with an API key (`b4m_live_`) or a JWT.

## Request body

- GenerateMusicRequest
  - `provider` 'elevenlabs'
  - `prompt` string, required
  - `lengthMs` integer
  - `forceInstrumental` boolean
  - `modelId` 'music_v1'
  - `format` string
  - `encoding` 'binary' | 'base64'
  - `preview` boolean

## Response `200`

Music generated. Binary bodies carry a Content-Type that follows the requested `format` (mp3 by default). The default `encoding: "binary"` returns the raw audio bytes; `encoding: "base64"` returns the JSON body. Audio over the ~4MB response ceiling cannot ride in the body: the binary encoding answers `303` instead, and the base64 encoding returns the `delivery: "url"` variant, whose `url` is a time-limited signed GET for the audio (`bytes` is its size).

- union
  - object
    - `contentType` string, required
    - `saved` boolean
    - `fabFileId` string
    - `fileName` string
    - `fileUrl` string
    - `saveSkippedReason` 'storage_limit' | 'file_too_large' | 'error'
    - `delivery` 'url', required
    - `url` string, required
    - `bytes` integer, required
  - object
    - `contentType` string, required
    - `saved` boolean
    - `fabFileId` string
    - `fileName` string
    - `fileUrl` string
    - `saveSkippedReason` 'storage_limit' | 'file_too_large' | 'error'
    - `delivery` 'inline'
    - `audio` string, required

## Other responses

- `303`: Binary encoding only: the audio exceeds the ~4MB response ceiling, so it was offloaded to storage and `Location` is a time-limited signed GET for it. HTTP clients that follow redirects receive the audio transparently (they drop the `Authorization` header on the cross-origin hop, as the signed URL requires); browser callers should use `encoding: "base64"`, since the storage origin sends no CORS headers. Carries the same `X-B4M-*` headers as the 200.
- `400`: The billing user or organization could not be resolved.
- `401`: Missing or invalid credentials.
- `403`: The API key does not hold any of the required scopes.
- `405`: The path does not serve this HTTP method.
- `413`: The audio was generated (and billed) and exceeds the response ceiling, and offloading it to storage failed. Retry, or request shorter output.
- `422`: Request body failed validation (including a `format` whose codec the provider cannot produce), or the caller cannot afford the track - the latter is tagged `errorCode: "insufficient_credits"` (the balance is short, or the org member credit cap is exhausted).
- `502`: The provider failed to generate the track; reserved credits are refunded.
- `503`: No provider API key is configured for this deployment.

---

[API](https://skmtc.dev/bike4mind/apis/bike4mind-api.md) · [All operations](https://skmtc.dev/bike4mind/apis/bike4mind-api/llms.txt) · [OpenAPI document](https://skmtc.dev/bike4mind/apis/bike4mind-api/revisions/d437aaac22ac?raw)
