> 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/plan
Content-Type: application/json

音楽生成用の構成プランを作成します。このエンドポイントの使用にクレジットはかかりませんが、プランに応じたレート制限が適用されます。

Reference: https://elevenlabs.io/docs/api-reference/music/create-composition-plan

## 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

- `enable_logging` (boolean, optional, default: true) — enable_loggingがfalseに設定されている場合、このリクエストにはゼロ保持モードが使用されます。ゼロ保持モードを利用できるのはエンタープライズのお客様のみです。

### Body (application/json)

This endpoint expects a Body_Generate_composition_plan_v1_music_plan_post.

- `prompt` (string, required) — プランを作成するためのシンプルなテキストプロンプト。
- `music_length_ms` (integer, optional, nullable) — 生成する構成プランの長さ（ミリ秒）。3000msから600000msの範囲で指定します。任意です。指定しない場合、モデルがプロンプトに基づいて長さを選択します。
- `source_composition_plan` (BodyGenerateCompositionPlanV1MusicPlanPostSourceCompositionPlan, optional, nullable) — 新しい構成プランの元として使用する任意の構成プラン。
- `model_id` (enum, optional, default: music_v1) — 生成に使用するモデル。
  - Allowed values: `music_v1`, `music_v2`, `music_v2_5`

## Response

### 200

成功レスポンス。

- `music_composition_plan_create_Response_200`

## Errors

### 422 Unprocessable Entity Error

検証エラー

- `detail` (list of ValidationError, optional)

## Types

### BodyGenerateCompositionPlanV1MusicPlanPostSourceCompositionPlan

新しい構成プランの元として使用する任意の構成プラン。

### 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) — 生成を構成するチャンク。

### ValidationError

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

### 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

### ValidationErrorLocItems

### 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": "string"
}
```

**Response**

```json
{
  "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"
    }
  ]
}
```

**SDK Code**

```python
import requests

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

payload = { "prompt": "string" }
headers = {"Content-Type": "application/json"}

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

print(response.json())
```

```javascript
const url = 'https://api.elevenlabs.io/v1/music/plan';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"prompt":"string"}'
};

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/plan"

	payload := strings.NewReader("{\n  \"prompt\": \"string\"\n}")

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

	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/plan")

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

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"prompt\": \"string\"\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/plan")
  .header("Content-Type", "application/json")
  .body("{\n  \"prompt\": \"string\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.elevenlabs.io/v1/music/plan', [
  'body' => '{
  "prompt": "string"
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

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

```swift
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = ["prompt": "string"] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.elevenlabs.io/v1/music/plan")! 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()
```