# Elevenlabs Music API

> Trình tạo văn bản thành âm nhạc được điều khiển bằng lời nhắc hoặc kế hoạch sáng tác có cấu trúc, với tùy chọn nhạc không lời

Sáng tác nhạc từ `prompt` văn bản dài tối đa 4100 ký tự hoặc từ `composition_plan` chi tiết. Với lời nhắc, `music_length_ms` có thể nằm trong khoảng từ 3000 đến 600000 mili giây, còn `force_instrumental` đảm bảo không có giọng hát. `respect_sections_durations` kiểm soát mức độ tuân thủ thời lượng của các phần trong kế hoạch. `output_format` cung cấp nhiều lựa chọn về codec và tốc độ lấy mẫu.

- Model id: `elevenlabs/music`
- Made by: ElevenLabs
- Category: Text to Music
- Output: audio
- Price per minute of your output audio: $0.60 / minute of output audio (cheapest run $0.60 (600 API credits))
- Run: `POST https://api.doitong.com/v1/run/elevenlabs/music`
- Quote: `POST https://api.doitong.com/v1/quote/elevenlabs/music`
- Docs page: https://doitong.com/vi/developers/models/elevenlabs/music

## Pricing

Price: **$0.60 / minute of output audio**. Price per minute of your output audio: the input files are measured before the run (length, resolution, frame rate). The quote measures the same files and is exactly what the run charges.

The full example input below costs $1.80 = 1800 API credits (3 min output audio × $0.60).

Prices are the upstream price in USD, paid from the API balance in API credits (1000 API credits = 1 USD). `POST https://api.doitong.com/v1/quote/elevenlabs/music` with the same JSON body returns the exact price for that input; the quote is exactly what a run charges. Invalid input is never charged and failed or canceled requests are refunded automatically.

## Input parameters

| Parameter | Canonical name | Type | Required | Default | Allowed values / range | Description |
|---|---|---|---|---|---|---|
| `prompt` |  | string \| null | no |  | ≤ 4100 characters | Mô tả bằng văn bản về nhạc mong muốn. |
| `composition_plan` |  | object {positive_global_styles, negative_global_styles, sections} \| null | no |  |  | Kế hoạch xác định cấu trúc của nhạc. |
| `composition_plan.positive_global_styles` |  | array of string | yes |  |  | Các phong cách cần đưa vào trong toàn bài hát. |
| `composition_plan.negative_global_styles` |  | array of string | yes |  |  | Các phong cách cần loại trừ trong toàn bài hát. |
| `composition_plan.sections` |  | array of object {section_name, positive_local_styles, negative_local_styles, duration_ms, lines} | yes |  |  | Các phần cấu thành bài hát. |
| `composition_plan.sections[].section_name` |  | string | yes |  | 1 – 100 characters | Tên phần, có độ dài từ 1 đến 100 ký tự. |
| `composition_plan.sections[].positive_local_styles` |  | array of string | yes |  |  | Các phong cách cần đưa vào trong phần này. |
| `composition_plan.sections[].negative_local_styles` |  | array of string | yes |  |  | Các phong cách cần loại trừ trong phần này. |
| `composition_plan.sections[].duration_ms` |  | integer | yes |  | 3,000 – 120,000 | Độ dài phần tính bằng mili giây, trong phạm vi từ 3000 ms đến 120000 ms. |
| `composition_plan.sections[].lines` |  | array of string | yes |  |  | Lời bài hát cho phần này, giới hạn 200 ký tự mỗi dòng. |
| `music_length_ms` |  | integer \| null | no |  | 3,000 – 600,000 | Thời lượng bài hát tùy chọn tính bằng mili giây, trong phạm vi từ 3000 ms đến 600000 ms, chỉ áp dụng khi dùng lời nhắc. Khi bỏ qua, mô hình xác định thời lượng từ lời nhắc. |
| `force_instrumental` |  | boolean | no | `false` |  | Điều khiển chỉ nhạc cụ, chỉ khả dụng khi dùng lời nhắc. Đặt thành true đảm bảo đầu ra chỉ có nhạc cụ; false cho phép nhạc có hoặc không có giọng hát theo lời nhắc. |
| `respect_sections_durations` |  | boolean | no | `true` |  | Thực thi thời gian phần cho `composition_plan`, không có tác dụng ngoài kế hoạch đó. False cho phép mô hình thay đổi độ dài từng phần, thường cải thiện chất lượng và độ trễ mà không thay đổi tổng thời lượng bài hát của kế hoạch; true buộc chính xác `duration_ms` của mọi phần. |
| `output_format` |  | enum (string) | no | `mp3_44100_128` | `mp3_22050_32`, `mp3_44100_32`, `mp3_44100_64`, `mp3_44100_96`, `mp3_44100_128`, `mp3_44100_192`, `pcm_8000`, `pcm_16000`, `pcm_22050`, `pcm_24000`, `pcm_44100`, `pcm_48000`, `ulaw_8000`, `alaw_8000`, `opus_48000_32`, `opus_48000_64`, `opus_48000_96`, `opus_48000_128`, `opus_48000_192` | Định dạng đầu ra âm thanh, tuân theo yêu cầu của gói: MP3 192 kbps cần gói Creator trở lên, còn PCM 44.1 kHz cần gói Pro trở lên. Các giá trị theo `codec_sample_rate_bitrate`; ví dụ `mp3_22050_32` chỉ định MP3 22.05 kHz ở 32 kbs. Với đầu vào âm thanh Twilio, μ-law thường được dùng; định dạng này cũng được viết là mu-law hoặc xấp xỉ là u-law. |

## Example input

Required parameters only:

```json
{}
```

A fuller example:

```json
{
  "prompt": "A red fox trots through fresh snow at sunrise, soft golden light, shallow depth of field"
}
```

## Run it

Set `DOITONG_API_KEY` to a key from https://doitong.com/developers/dashboard#keys. `?wait=20` returns the finished request in the same call when it is ready within 20 seconds; otherwise poll `GET /requests/{id}` (it also accepts `?wait=`), or pass `webhook_url`.

### curl

```bash
# Run the model; wait up to 20 s for the finished result in the same call
curl -X POST "https://api.doitong.com/v1/run/elevenlabs/music?wait=20" \
  -H "Authorization: Bearer $DOITONG_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A red fox trots through fresh snow at sunrise, soft golden light, shallow depth of field"
  }'

# Still "queued" or "running"? Poll with the id from the response:
curl "https://api.doitong.com/v1/requests/REQUEST_ID?wait=20" \
  -H "Authorization: Bearer $DOITONG_API_KEY"
```

### JavaScript

```javascript
const API = "https://api.doitong.com/v1";
const headers = {
  "Authorization": "Bearer " + process.env.DOITONG_API_KEY,
  "Content-Type": "application/json",
};

// Run the model; wait up to 20 s for the finished result in the same call
let res = await fetch(API + "/run/elevenlabs/music?wait=20", {
  method: "POST",
  headers,
  body: JSON.stringify({
    "prompt": "A red fox trots through fresh snow at sunrise, soft golden light, shallow depth of field"
  }),
});
let request = await res.json();
if (!res.ok) throw new Error(request.error.code + ": " + request.error.message);

// Not finished yet: long-poll until it is
while (request.status === "queued" || request.status === "running") {
  res = await fetch(API + "/requests/" + request.id + "?wait=20", { headers });
  request = await res.json();
}
if (request.status !== "succeeded") throw new Error(JSON.stringify(request.error));
console.log(request.outputs.map((o) => o.url), request.cost.credits + " API credits ($" + request.cost.usd + ")");
```

### Python

```python
import os
import requests

API = "https://api.doitong.com/v1"
headers = {"Authorization": "Bearer " + os.environ["DOITONG_API_KEY"]}

payload = {
    "prompt": "A red fox trots through fresh snow at sunrise, soft golden light, shallow depth of field",
}

# Run the model; wait up to 20 s for the finished result in the same call
r = requests.post(API + "/run/elevenlabs/music", params={"wait": 20}, json=payload, headers=headers)
request = r.json()
if not r.ok:
    raise RuntimeError(request["error"]["code"] + ": " + request["error"]["message"])

# Not finished yet: long-poll until it is
while request["status"] in ("queued", "running"):
    request = requests.get(API + "/requests/" + request["id"], params={"wait": 20}, headers=headers).json()
if request["status"] != "succeeded":
    raise RuntimeError(request["error"])
print([o["url"] for o in request["outputs"]], request["cost"]["credits"], "API credits", "$" + request["cost"]["usd"])
```

### MCP

The MCP server at `https://api.doitong.com/v1/mcp` exposes the tools `search_models`, `get_model`, `quote`, `run`, `get_request`, `cancel_request`, `list_requests`, `create_upload` and `get_account`. A `run` call for this model:

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "run",
    "arguments": {
      "model_id": "elevenlabs/music",
      "input": {
        "prompt": "A red fox trots through fresh snow at sunrise, soft golden light, shallow depth of field"
      },
      "wait_seconds": 20
    }
  }
}
```

## Response

Every call returns a request object. `status` is one of `queued`, `running`, `succeeded`, `failed`, `canceled`. `outputs` lists the generated files with URLs on our storage (kept forever, or 7 days with `?storage=temporary`; `storage` says which); `output` is the model's own result object with the same URLs.

```json
{
  "id": "req_8k2m4q7x1z9c3v5b6n0p2r4t",
  "object": "request",
  "model": "elevenlabs/music",
  "status": "succeeded",
  "created_at": "2026-10-20T12:00:00Z",
  "started_at": "2026-10-20T12:00:02Z",
  "completed_at": "2026-10-20T12:00:09Z",
  "queue_position": null,
  "cost": {
    "credits": 1800,
    "usd": "1.80",
    "charged": 1800,
    "refunded": 0
  },
  "input": {
    "prompt": "A red fox trots through fresh snow at sunrise, soft golden light, shallow depth of field"
  },
  "output": {
    "audio": {
      "url": "https://content.doitong.com/dev-api/2026/10/20/req_8k2m4q7x1z9c3v5b6n0p2r4t/0-output.mp3",
      "content_type": "audio/mpeg",
      "file_name": "0-output.mp3",
      "file_size": 1843200
    }
  },
  "outputs": [
    {
      "type": "audio",
      "url": "https://content.doitong.com/dev-api/2026/10/20/req_8k2m4q7x1z9c3v5b6n0p2r4t/0-output.mp3",
      "content_type": "audio/mpeg",
      "file_size": 1843200,
      "duration": 12,
      "stored": true
    }
  ],
  "error": null,
  "metrics": {
    "inference_seconds": 6.8
  },
  "urls": {
    "self": "https://api.doitong.com/v1/requests/req_8k2m4q7x1z9c3v5b6n0p2r4t",
    "cancel": "https://api.doitong.com/v1/requests/req_8k2m4q7x1z9c3v5b6n0p2r4t/cancel"
  }
}
```

### Output fields (`output`)

| Field | Type | Description |
|---|---|---|
| `audio` | object {url, content_type, file_name, file_size} | Tệp nhạc được tạo, mã hóa dưới dạng âm thanh MP3. |

## Related models

- [ElevenLabs Dubbing](https://doitong.com/developers/models/elevenlabs/dubbing.md) (`elevenlabs/dubbing`): $0.60 / minute of input file
- [Elevenlabs - Forced Alignment](https://doitong.com/developers/models/elevenlabs/forced-alignment.md) (`elevenlabs/forced-alignment`): $0.22 / hour of input audio
- [ElevenLabs Voice Changer](https://doitong.com/developers/models/elevenlabs/voice-changer.md) (`elevenlabs/voice-changer`): $0.30 / minute of input audio
- [MiniMax Music 3](https://doitong.com/developers/models/minimax/music-3.md) (`minimax/music-3`): $0.002 / second
- [Elevenlabs Music v2](https://doitong.com/developers/models/elevenlabs/music/v2.md) (`elevenlabs/music/v2`): $0.60 / minute of output audio
- [Elevenlabs Music v2.5](https://doitong.com/developers/models/elevenlabs/music/v2.5.md) (`elevenlabs/music/v2.5`): $0.60 / minute of output audio
- [ACE Step](https://doitong.com/developers/models/ace-step.md) (`ace-step`): $0.0002 / second
- [ACE Step Audio Inpaint](https://doitong.com/developers/models/ace-step/audio-inpaint.md) (`ace-step/audio-inpaint`): $0.0002 / second of input audio

## Links

- HTML page: https://doitong.com/developers/models/elevenlabs/music
- All models and guides for AI agents: https://doitong.com/developers/llms.txt
- OpenAPI 3.1 with this model's typed request body: https://doitong.com/developers/openapi.json?model=elevenlabs/music
- Errors: https://doitong.com/developers/docs/errors
- Model details as JSON: https://api.doitong.com/v1/models/elevenlabs/music
