> This is a page from the ElevenLabs documentation. For a complete page index, fetch https://elevenlabs.io/docs/llms.txt. For the full documentation in a single file, fetch https://elevenlabs.io/docs/llms-full.txt.

# 詳細なレスポンスで音楽を作曲

POST https://api.elevenlabs.io/v1/music/detailed
Content-Type: application/json

プロンプトまたは構成プランから曲を作成します。

Reference: https://elevenlabs.io/docs/api-reference/music/compose-detailed

## Servers

- `https://api.elevenlabs.io` (Production, default)
- `https://api.us.elevenlabs.io` (Production US)
- `https://api.eu.residency.elevenlabs.io` (Production EU)
- `https://api.in.residency.elevenlabs.io` (Production India)
- `https://api.sg.residency.elevenlabs.io` (Production Singapore)

## Request

### Query parameters

- `output_format` (enum, optional, default: auto) — 生成されたオーディオの出力形式。codec_sample_rate_bitrate形式で指定します。選択したモデルに最適な形式をAPIに選択させるには、"auto"（デフォルト）を使用します。v1モデルではmp3_44100_128、v2モデルではmp3_48000_192が選択されます。
  - Allowed values: `auto`, `mp3_48000_128`, `mp3_48000_192`, `mp3_48000_240`, `mp3_48000_320`, `mp3_22050_32`, `mp3_24000_48`, `mp3_44100_32`, `mp3_44100_64`, `mp3_44100_96`, `mp3_44100_128`, `mp3_44100_192`, `pcm_8000`, `pcm_16000`, `pcm_22050`, `pcm_24000`, `pcm_32000`, `pcm_44100`, `pcm_48000`, `ulaw_8000`, `alaw_8000`, `opus_48000_32`, `opus_48000_64`, `opus_48000_96`, `opus_48000_128`, `opus_48000_192`
- `enable_logging` (boolean, optional, default: true) — enable_loggingがfalseに設定されている場合、このリクエストにはゼロ保持モードが使用されます。ゼロ保持モードを利用できるのはエンタープライズのお客様のみです。

### Body (application/json)

This endpoint expects a Body_Compose_Music_with_a_detailed_response_v1_music_detailed_post.

- `prompt` (string, optional, nullable) — 楽曲を生成するためのシンプルなテキストプロンプトです。`composition_plan`と併用できません。
- `composition_plan` (BodyComposeMusicWithADetailedResponseV1MusicDetailedPostCompositionPlan, optional, nullable) — 音楽生成をガイドする詳細な構成プランです。`prompt`と同時には使用できません。
- `music_length_ms` (integer, optional, nullable) — 生成する曲の長さ（ミリ秒）。`prompt`と併用する場合にのみ使用します。3000msから600000msの範囲で指定します。任意です。指定しない場合、モデルがプロンプトに基づいて長さを選択します。
- `model_id` (enum, optional, default: music_v1) — 生成に使用するモデル。
  - Allowed values: `music_v1`, `music_v2`, `music_v2_5`
- `seed` (integer, optional, nullable) — 音楽生成プロセスを初期化するランダムシード。同じパラメータで同じシードを指定すると、より一貫した結果を得やすくなりますが、完全な再現性は保証されず、システムの更新によって出力が変わる場合があります。promptと併用できません。
- `force_instrumental` (boolean, optional, default: false) — trueの場合、生成される楽曲がインストゥルメンタルであることを保証します。falseの場合、楽曲がインストゥルメンタルになるかどうかは`prompt`によって異なります。`prompt`と組み合わせてのみ使用できます。
- `finetune_id` (string, optional, nullable) — 生成に使用するFinetuneのID
- `respect_sections_durations` (boolean, optional, default: true) — `composition_plan`内のセクションの長さをどの程度厳密に適用するかを制御します。`composition_plan`でのみ使用され、`music_v1`にのみ適用されます。`music_v2`および`music_v2_5`ではセクションの長さが常に適用されるため、この設定は無視されます。`music_v1`でfalseの場合、プランの合計楽曲時間を維持しつつ、品質とレイテンシーを改善するためにモデルが各セクションの長さを調整することがあります。
- `store_for_inpainting` (boolean, optional, default: false) — インペインティング用に生成した楽曲を保存するかどうか。
- `with_timestamps` (boolean, optional, default: false) — 生成した楽曲内の単語のタイムスタンプを返すかどうか。
- `with_waveform_visual` (boolean, optional, default: false) — 生成した楽曲の視覚的な波形を返すかどうか。
- `sign_with_c2pa` (boolean, optional, default: false) — 生成した楽曲にC2PA署名を付与するかどうか。mp3ファイルにのみ適用されます。

## Response

### 200

JSONメタデータとバイナリ音声ファイルを含むmultipart/mixed応答

## Errors

### 422 Unprocessable Entity Error

検証エラー

- `detail` (list of ValidationError, optional)

## Types

### BodyComposeMusicWithADetailedResponseV1MusicDetailedPostCompositionPlan

音楽生成をガイドする詳細な構成プランです。`prompt`と同時には使用できません。

### ValidationError

- `loc` (list of ValidationErrorLocItems, required)
- `msg` (string, required)
- `type` (string, required)

### MusicPrompt

`music_v1`モデルの構成プランです。このフィールドを他のモデルで使用するとエラーになります。

- `positive_global_styles` (list of string, required) — 曲全体に含めるスタイルと音楽的な指示。最良の結果を得るには英語を使用してください。
- `negative_global_styles` (list of string, required) — 曲全体に含めないスタイルと音楽的な指示。最良の結果を得るには英語を使用してください。
- `sections` (list of SongSection, required) — 曲のセクション。

### CompositionPlan

`music_v2`および`music_v2_5`モデルの構成プランです。このフィールドを他のモデルで使用するとエラーになります。

- `chunks` (list of CompositionPlanChunksItems, required) — 生成を構成するチャンク。

### ValidationErrorLocItems

### SongSection

- `section_name` (string, required) — セクションの名前。1文字から100文字の範囲で指定します。
- `positive_local_styles` (list of string, required) — このセクションに含めるスタイルと音楽的な指示。最良の結果を得るには英語を使用してください。
- `negative_local_styles` (list of string, required) — このセクションに含めないスタイルと音楽的な指示。最良の結果を得るには英語を使用してください。
- `duration_ms` (integer, required) — セクションの長さ（ミリ秒）。3000ms～120000msである必要があります。
- `lines` (list of string, required) — セクションの歌詞。1セクションあたり最大30行、1行あたり最大200文字です。
- `source_from` (SectionSource, optional, nullable) — セクションの抽出元となる任意のソースです。インペインティングに使用します。

### CompositionPlanChunksItems

### SectionSource

- `song_id` (string, required) — セクションの元となる楽曲のID。楽曲を生成した際のレスポンスヘッダーで楽曲IDを確認できます。
- `range` (TimeRange, required) — 元の曲から抽出する範囲。
- `negative_ranges` (list of TimeRange, optional) — 「range」から除外する範囲。

### GenerationChunk-Input

- `text` (string, required) — このチャンクに生成するテキスト設定。先頭に任意のセクション名を角括弧で含めることができます（例：\[Verse 1]）。歌詞行や、中括弧で囲んだインライン指示（例：\{scratching}）も含められます。セクション名は1～100文字にする必要があります。最大30行まで指定でき、各行は最大200文字です。
- `duration_ms` (integer, required) — チャンクの長さ（ミリ秒）。3000ms～120000msである必要があります。
- `positive_styles` (list of string, required) — このチャンクに含めるスタイルと音楽的な指示。最良の結果を得るには英語を使用してください。最初のチャンクのスタイルは、全体のトーンとジャンルを決めるため最も重要です。後続のチャンクのスタイルは、ニュアンス、展開、強調を加えたり、曲の方向性を変えたりするために使用できます。方向性が確立するまで、初期のチャンクには少なくとも6～7個のスタイルを含めることを目指してください。「great production quality」のような汎用的なスタイルは、リストに追加するデフォルトスタイルとして適しています。
- `negative_styles` (list of string, optional) — このチャンクに含めないスタイルと音楽的な指示。最良の結果を得るには英語を使用してください。空のままにするのが適切なデフォルトです。特定のスタイルや方向性を明示的に避けたい場合にのみ、このフィールドを使用してください。
- `context_adherence` (enum, optional, default: high) — モデルが周囲のチャンクのコンテキストにどの程度従うかを指定します。忠実度が低い場合、モデルはコンテキストから逸脱してより創造的になります。忠実度が高い場合、モデルはコンテキストとの一貫性をより保ちます。
  - Allowed values: `low`, `medium`, `high`
- `conditioning_ref` (AudioRefChunk, optional, nullable) — 生成の条件付けに使用するオーディオ参照。最初のチャンクは以降のすべてのチャンクの生成に影響するため、最も重要です。曲全体に条件付けを適用する場合は、最初のチャンクから開始してください。
- `condition_strength` (enum, optional, nullable) — モデルが条件付け参照にどの程度忠実に従うかを指定します。強度が低い場合、モデルはより創造的になり、参照から逸脱します。強度が高い場合、モデルは参照との一貫性をより保ちます。
  - Allowed values: `low`, `medium`, `high`, `xhigh`

### AudioRefChunk

- `song_id` (string, required) — チャンクの元となる楽曲のID。楽曲を生成した際のレスポンスヘッダーで楽曲IDを確認できます。
- `range` (TimeRange, required) — 楽曲から抽出する時間範囲です。

### TimeRange

- `start_ms` (integer, required)
- `end_ms` (integer, required)

## Examples

**Request**

```json
{
  "prompt": "A prompt for music generation",
  "music_length_ms": 10000
}
```

**Response**

```json
{
  "audio": "[binary audio data]",
  "composition_plan": {
    "negative_global_styles": [
      "metal",
      "hip-hop",
      "country"
    ],
    "positive_global_styles": [
      "pop",
      "rock",
      "jazz"
    ],
    "sections": [
      {
        "duration_ms": 10000,
        "lines": [
          "Verse 1 lyrics"
        ],
        "negative_local_styles": [
          "metal",
          "hip-hop",
          "country"
        ],
        "positive_local_styles": [
          "pop",
          "rock",
          "jazz"
        ],
        "section_name": "Verse 1"
      }
    ]
  },
  "song_metadata": {
    "description": "曲の説明",
    "genres": [
      "pop",
      "rock",
      "jazz"
    ],
    "is_explicit": false,
    "languages": [
      "en",
      "fr"
    ],
    "title": "My Song"
  }
}
```

**SDK Code**

```python
import requests

url = "https://api.elevenlabs.io/v1/music/detailed"

payload = {
    "prompt": "A prompt for music generation",
    "music_length_ms": 10000
}
headers = {
    "xi-api-key": "xi-api-key",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.elevenlabs.io/v1/music/detailed';
const options = {
  method: 'POST',
  headers: {'xi-api-key': 'xi-api-key', 'Content-Type': 'application/json'},
  body: '{"prompt":"A prompt for music generation","music_length_ms":10000}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.elevenlabs.io/v1/music/detailed"

	payload := strings.NewReader("{\n  \"prompt\": \"A prompt for music generation\",\n  \"music_length_ms\": 10000\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("xi-api-key", "xi-api-key")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.elevenlabs.io/v1/music/detailed")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["xi-api-key"] = 'xi-api-key'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"prompt\": \"A prompt for music generation\",\n  \"music_length_ms\": 10000\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.elevenlabs.io/v1/music/detailed")
  .header("xi-api-key", "xi-api-key")
  .header("Content-Type", "application/json")
  .body("{\n  \"prompt\": \"A prompt for music generation\",\n  \"music_length_ms\": 10000\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.elevenlabs.io/v1/music/detailed', [
  'body' => '{
  "prompt": "A prompt for music generation",
  "music_length_ms": 10000
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'xi-api-key' => 'xi-api-key',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.elevenlabs.io/v1/music/detailed");
var request = new RestRequest(Method.POST);
request.AddHeader("xi-api-key", "xi-api-key");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"prompt\": \"A prompt for music generation\",\n  \"music_length_ms\": 10000\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "xi-api-key": "xi-api-key",
  "Content-Type": "application/json"
]
let parameters = [
  "prompt": "A prompt for music generation",
  "music_length_ms": 10000
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.elevenlabs.io/v1/music/detailed")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```