Skip to main content
meta avatar

musicgen API

meta/musicgen

A fast, controllable auto-regressive Transformer for high-fidelity music generation.

Model Input

Input

Model to use for generation

A description of the music you want to generate.

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.

Duration of the generated audio in seconds.

If `True`, generated music will continue from `input_audio`. Otherwise, generated music will mimic `input_audio`'s melody.

Min: 0

Start time of the audio file to use for continuation.

Min: 0

End time of the audio file to use for continuation. If -1 or None, will default to the end of the audio clip.

If `True`, the EnCodec tokens will be decoded with MultiBand Diffusion. Only works with non-stereo models.

Strategy for normalizing audio.

Reduces sampling to the k most likely tokens.

Reduces sampling to tokens with cumulative probability of p. When set to `0` (default), top_k sampling is used.

Controls the 'conservativeness' of the sampling process. Higher temperature means more diversity.

Increases the influence of inputs on the output. Higher values produce lower-varience outputs that adhere more closely to inputs.

Output format for generated audio.

Seed for random number generator. If None or -1, a random seed will be used.

You need to be logged in to run this model and view results.
Log in

Model Output

Output

Fill in the input form and click submit to see the output
Logs (1 lines)

musicgen API

musicgen is a sound AI model by meta. On ModelRunner it runs through a REST API or via MCP from any AI assistant, at about $0.07 per audio clip.

POST https://queue.modelrunner.run/meta/musicgen

cURL

# Submit a request to the queue. Input fields go at the top level of the
# body. The optional reserved "metadata" object holds your own flat string
# tags — stored on the request, never sent to the model; filter later with
# GET https://queue.modelrunner.run/requests?metadata=<url-encoded JSON>.
curl -X POST https://queue.modelrunner.run/meta/musicgen \
  -H "Authorization: Key $MRUN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model_version": "stereo-melody-large",
    "metadata": {
      "project": "my-project"
    }
  }'
# → { "request_id": "...", "status_url": "...", "response_url": "..." }

# Poll status_url until "COMPLETED", then fetch the result
curl "https://queue.modelrunner.run/meta/musicgen/requests/$REQUEST_ID/status" \
  -H "Authorization: Key $MRUN_API_KEY"
curl "https://queue.modelrunner.run/meta/musicgen/requests/$REQUEST_ID" \
  -H "Authorization: Key $MRUN_API_KEY"

JavaScript

import { modelrunner } from "@modelrunner/client";

const result = await modelrunner.subscribe("meta/musicgen", {
  input: {
    "model_version": "stereo-melody-large"
  },
});
console.log(result);

Python

import os
import requests

headers = {"Authorization": f"Key {os.environ['MRUN_API_KEY']}"}

submitted = requests.post(
    "https://queue.modelrunner.run/meta/musicgen",
    headers=headers,
    json={
      "model_version": "stereo-melody-large"
    },
).json()

# Poll submitted["status_url"] until "COMPLETED", then:
result = requests.get(submitted["response_url"], headers=headers).json()

Input parameters

NameTypeRequiredDescription
model_versionenumnoModel to use for generation Default: "stereo-melody-large".
promptstringnoA description of the music you want to generate.
input_audiostring (uri)noAn 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.
durationintegernoDuration of the generated audio in seconds. Default: 8.
continuationbooleannoIf `True`, generated music will continue from `input_audio`. Otherwise, generated music will mimic `input_audio`'s melody. Default: false.
continuation_startintegernoStart time of the audio file to use for continuation. Default: 0.
continuation_endintegernoEnd time of the audio file to use for continuation. If -1 or None, will default to the end of the audio clip.
multi_band_diffusionbooleannoIf `True`, the EnCodec tokens will be decoded with MultiBand Diffusion. Only works with non-stereo models. Default: false.
normalization_strategyenumnoStrategy for normalizing audio. Default: "loudness".
top_kintegernoReduces sampling to the k most likely tokens. Default: 250.
top_pnumbernoReduces sampling to tokens with cumulative probability of p. When set to `0` (default), top_k sampling is used. Default: 0.
temperaturenumbernoControls the 'conservativeness' of the sampling process. Higher temperature means more diversity. Default: 1.
classifier_free_guidanceintegernoIncreases the influence of inputs on the output. Higher values produce lower-varience outputs that adhere more closely to inputs. Default: 3.
output_formatenumnoOutput format for generated audio. Default: "wav".
seedintegernoSeed for random number generator. If None or -1, a random seed will be used.

Machine-readable: OpenAPI schema · llms.txt

Use musicgen from Claude & Cursor (MCP)

Point Claude Code, Claude Desktop, Cursor, or any MCP client at the ModelRunner MCP server and musicgen becomes a tool your assistant can call directly — it authorizes via OAuth (no API key in config) and runs this model with the run_model tool using the endpoint meta/musicgen.

MCP client config (Claude Desktop, Cursor)

{
  "mcpServers": {
    "modelrunner": {
      "command": "npx",
      "args": ["-y", "mcp-remote", "https://mcp.modelrunner.run/mcp"]
    }
  }
}

Claude Code

claude mcp add --transport http modelrunner https://mcp.modelrunner.run/mcp

Then ask your assistant, for example: “Run meta/musicgen on ModelRunner to generate sound”. MCP setup guide.

Model Details

Model Details

### Musicgen Model Description MusicGen by AudioCraft is a single-stage, auto-regressive Transformer that generates high-quality music at 32 kHz using a 4-codebook EnCodec tokenizer. Trained on 20 000 hours of licensed tracks, it predicts all codebooks in parallel with only 50 autoregressive steps per second—no separate semantic embeddings required.

### Models & Demos - **Scales:** small, medium, large, melody, stereo - **Demos:** Hugging Face Space, Colab notebook, local Gradio app, Jupyter examples

### Key Benefits - **Efficiency:** Parallel codebook prediction for faster inference - **Flexibility:** Text-only or text+melody conditioning across multiple model sizes - **Accessibility:** Available via 🤗 Transformers (v4.31.0+) with minimal dependencies