# musicgen > A fast, controllable auto-regressive Transformer for high-fidelity music generation. ## Overview - **Endpoint**: `https://queue.modelrunner.run/meta/musicgen` - **Model ID**: `meta/musicgen` - **Category**: sound - **Kind**: inference - **Tags**: music, song, sound ## Pricing - **Estimated Price**: $0.07 average per output ## Request Lifecycle This model runs on the ModelRunner **asynchronous queue API** — a single POST does not return the output. Every call requires an `Authorization: Key $MODEL_RUNNER_KEY` header. Run three steps: 1. **Submit** — `POST https://queue.modelrunner.run/meta/musicgen` with a JSON body holding the input fields at the top level. The body may also include a reserved top-level `metadata` object — a flat string map (max 16 keys, key ≤64 / value ≤512 chars) stored on the request for your own tagging. It is never sent to the model; filter your request history with `GET https://queue.modelrunner.run/requests?metadata=` (exact key=value matches, AND-ed). The response carries request handles only (no output yet): ```json { "status": "IN_QUEUE", "request_id": "<21-char id>", "status_url": "https://queue.modelrunner.run/meta/musicgen/requests//status", "response_url": "https://queue.modelrunner.run/meta/musicgen/requests/", "cancel_url": "https://queue.modelrunner.run/meta/musicgen/requests//cancel" } ``` 2. **Poll status** — `GET ` until `status` is `COMPLETED`. Possible values are `IN_QUEUE`, `IN_PROGRESS`, `COMPLETED`, `FAILED`, `CANCELLED`. A `FAILED` request responds with HTTP 400 and an `error` field. 3. **Read result** — `GET `. Returns the finished request, including the generated `output`: ```json { "id": "", "status": "COMPLETED", "output": ..., "input": ... } ``` The JavaScript and Python SDKs below perform steps 2–3 for you. In any language without an SDK (Swift, Go, Kotlin, etc.) you must implement the polling loop and the final result fetch yourself — see the cURL example for the full flow. ### Input Schema - **`seed`** (`integer`, _optional_): Seed for random number generator. If None or -1, a random seed will be used. - **`top_k`** (`integer`, _optional_): Reduces sampling to the k most likely tokens. - Default: `250` - **`top_p`** (`number`, _optional_): Reduces sampling to tokens with cumulative probability of p. When set to \`0\` (default), top_k sampling is used. - Default: `0` - **`prompt`** (`string`, _optional_): A description of the music you want to generate. - **`duration`** (`integer`, _optional_): Duration of the generated audio in seconds. - Default: `8` - **`input_audio`** (`string`, _optional_): An audio file that will influence the generated music. If \`continuation\` is \`True\`, the generated music will be a continuation of the audio file. Otherwise, the generated music will mimic the audio file's melody. - **`temperature`** (`number`, _optional_): Controls the 'conservativeness' of the sampling process. Higher temperature means more diversity. - Default: `1` - **`continuation`** (`boolean`, _optional_): If \`True\`, generated music will continue from \`input_audio\`. Otherwise, generated music will mimic \`input_audio\`'s melody. - Default: `false` - **`model_version`** (`model_version`, _optional_): Model to use for generation - Default: `"stereo-melody-large"` - Options: `"stereo-melody-large"`, `"stereo-large"`, `"melody-large"`, `"large"` - **`output_format`** (`output_format`, _optional_): Output format for generated audio. - Default: `"wav"` - Options: `"wav"`, `"mp3"` - **`continuation_end`** (`integer`, _optional_): End time of the audio file to use for continuation. If -1 or None, will default to the end of the audio clip. - Range: `0` to `"+inf"` - **`continuation_start`** (`integer`, _optional_): Start time of the audio file to use for continuation. - Default: `0` - Range: `0` to `"+inf"` - **`multi_band_diffusion`** (`boolean`, _optional_): If \`True\`, the EnCodec tokens will be decoded with MultiBand Diffusion. Only works with non-stereo models. - Default: `false` - **`normalization_strategy`** (`normalization_strategy`, _optional_): Strategy for normalizing audio. - Default: `"loudness"` - Options: `"loudness"`, `"clip"`, `"peak"`, `"rms"` - **`classifier_free_guidance`** (`integer`, _optional_): Increases the influence of inputs on the output. Higher values produce lower-varience outputs that adhere more closely to inputs. - Default: `3` ### Output Schema _No `Output` schema properties are available._ ## Usage Examples ### cURL The queue API is asynchronous: submit the request, poll `status_url` until it is `COMPLETED`, then read the result from `response_url`. Requires `jq`. ```bash # 1. Submit the request (returns request handles, not the output) SUBMIT=$(curl --silent --request POST \ --url https://queue.modelrunner.run/meta/musicgen \ --header "Authorization: Key $MODEL_RUNNER_KEY" \ --header "Content-Type: application/json" \ --data '{}') STATUS_URL=$(echo "$SUBMIT" | jq -r '.status_url') RESPONSE_URL=$(echo "$SUBMIT" | jq -r '.response_url') # 2. Poll until the request leaves the queue / in-progress state while true; do STATUS=$(curl --silent --url "$STATUS_URL" \ --header "Authorization: Key $MODEL_RUNNER_KEY" | jq -r '.status') echo "Status: $STATUS" case "$STATUS" in COMPLETED) break ;; FAILED|CANCELLED) echo "Request $STATUS"; exit 1 ;; esac sleep 1 done # 3. Read the finished request, including the generated output curl --silent --url "$RESPONSE_URL" \ --header "Authorization: Key $MODEL_RUNNER_KEY" ``` ### JavaScript ```javascript import { modelrunner } from "@modelrunner/client"; const result = await modelrunner.subscribe("meta/musicgen", { input: {} }); console.log(result.data); ``` ### Python ```python import asyncio import modelrunner_ai async def main(): response = await modelrunner_ai.submit_async( "meta/musicgen", arguments={} ) result = await response.get() print(result["output"]) asyncio.run(main()) ``` ## Additional Resources - [Playground](https://modelrunner.ai/models/meta/musicgen) - [OpenAPI Schema](https://modelrunner.ai/models/meta/musicgen/openapi.json) - [LLM Instructions](https://modelrunner.ai/models/meta/musicgen/llms.txt) - [GitHub](https://github.com/facebookresearch/audiocraft/blob/main/docs/MUSICGEN.md) - [License](https://github.com/facebookresearch/audiocraft/blob/main/model_cards/MUSICGEN_MODEL_CARD.md) - [Paper](https://arxiv.org/abs/2306.05284)