> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apimart.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# セクション置換

> Flow Music 生成済みオーディオの一部のセクションを置き換えます。編集指示に従って start_s から end_s までのセクションを再生成します

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://api.apimart.ai/v1/music/generations/replaceFlowMusic \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
      "model": "flowmusic",
      "clip_id": "abc123-def456",
      "start_s": 10,
      "end_s": 20,
      "instruction": "ピアノバージョンに置き換える"
    }'
  ```

  ```python Python theme={null}
  import requests

  url = "https://api.apimart.ai/v1/music/generations/replaceFlowMusic"

  payload = {
      "model": "flowmusic",
      "clip_id": "abc123-def456",
      "start_s": 10,
      "end_s": 20,
      "instruction": "ピアノバージョンに置き換える"
  }

  headers = {
      "Authorization": "Bearer <token>",
      "Content-Type": "application/json"
  }

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

  print(response.json())
  ```

  ```javascript JavaScript theme={null}
  const url = "https://api.apimart.ai/v1/music/generations/replaceFlowMusic";

  const payload = {
    model: "flowmusic",
    clip_id: "abc123-def456",
    start_s: 10,
    end_s: 20,
    instruction: "ピアノバージョンに置き換える"
  };

  const headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
  };

  fetch(url, {
    method: "POST",
    headers: headers,
    body: JSON.stringify(payload)
  })
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "code": 200,
    "data": [
      {
        "status": "submitted",
        "task_id": "task_01KWXVHGTG5JM33S8FG1K90YQ6"
      }
    ]
  }
  ```

  ```json 400 theme={null}
  {
    "error": {
      "message": "end_s must be greater than start_s",
      "type": "invalid_request",
      "param": "",
      "code": "invalid_request"
    }
  }
  ```

  ```json 403 theme={null}
  {
    "error": {
      "message": "残高が不足しています",
      "type": "invalid_request",
      "param": "",
      "code": "quota_not_enough"
    }
  }
  ```

  ```json 429 theme={null}
  {
    "error": {
      "message": "現在のグループ容量が飽和しています。後でもう一度お試しください",
      "type": "rate_limit_error",
      "param": "",
      "code": "rate_limit_error"
    }
  }
  ```
</ResponseExample>

## 認証

<ParamField header="Authorization" type="string" required>
  すべての API は Bearer Token による認証が必要です

  API Key の取得：

  [API Key 管理ページ](https://apimart.ai/keys) にアクセスして API Key を取得してください

  使用時はリクエストヘッダーに以下を追加します：

  ```
  Authorization: Bearer YOUR_API_KEY
  ```
</ParamField>

## リクエストパラメータ

<ParamField body="model" type="string" required>
  モデル名。**必ず `"flowmusic"` を指定**（大文字小文字は区別されません）
</ParamField>

<ParamField body="clip_id" type="string" required>
  ソース音楽の clip\_id。成功済みタスクの `result.music[].clip_id` から取得します
</ParamField>

<ParamField body="start_s" type="number" required>
  置換の開始時間（秒）
</ParamField>

<ParamField body="end_s" type="number" required>
  置換の終了時間（秒）

  <Warning>
    `end_s` は `start_s` より大きい必要があり、ソース clip の長さを超えることはできません。
  </Warning>
</ParamField>

<ParamField body="instruction" type="string" required>
  セクション置換の編集指示

  例：`"ピアノバージョンに置き換える"`
</ParamField>

<ParamField body="title" type="string">
  置換後の音楽タイトル
</ParamField>

<ParamField body="seed" type="integer">
  ランダムシード。結果の再現や生成結果の制御に使用します
</ParamField>

## レスポンス

<ResponseField name="code" type="integer">
  レスポンスステータスコード。成功時は 200
</ResponseField>

<ResponseField name="data" type="array">
  返却データの配列

  <Expandable title="配列要素">
    <ResponseField name="status" type="string">
      タスクステータス。初回送信時は `submitted`
    </ResponseField>

    <ResponseField name="task_id" type="string">
      タスクの一意な識別子。タスクのステータスと結果の照会に使用します
    </ResponseField>
  </Expandable>
</ResponseField>

## 使用シーン

### シーン 1：10～20 秒をピアノバージョンに置き換える

```json theme={null}
{
  "model": "flowmusic",
  "clip_id": "abc123-def456",
  "start_s": 10,
  "end_s": 20,
  "instruction": "ピアノバージョンに置き換える"
}
```

<Note>
  **タスク結果の照会**

  セクション置換は非同期タスクです。送信後に `task_id` が返されます。[タスクステータスの取得](./query) API を使用して、生成の進捗と結果を照会してください。置換の成果物は**新しい** `clip_id` です（指定区間が置き換えられた状態で曲全体が再出力されます）。以降の操作には新しい clip\_id を使用してください。
</Note>

## タスク完了結果の例

**照会レスポンス例**（`GET /v1/music/tasks/{task_id}`）：

```json theme={null}
{
  "code": 200,
  "data": {
    "id": "task_01KWXVHGTG5JM33S8FG1K90YQ6",
    "status": "completed",
    "progress": 100,
    "created": 1783413392,
    "completed": 1783413454,
    "actual_time": 62,
    "cost": 0.048,
    "credits_cost": 0.48,
    "result": {
      "music": [
        {
          "clip_id": "9508d1fe-633e-464b-8a40-c6368e5464fa",
          "title": "Untitled (Replaced)",
          "duration_seconds": "181.58933333",
          "create_time": "2026-07-07T08:37:13.864452Z",
          "lyrics": "[Verse 1]\nWaking up to the morning light,\n...",
          "lyrics_id": "c302d603-81b6-552f-8122-e512928d6aa1",
          "lyrics_timing_markers": [[10, 12], [71, 15]],
          "audio_url": "https://cdn.apimart.ai/audio/flowmusic_9508d1fe.m4a",
          "wav_url": "https://cdn.apimart.ai/audio/flowmusic_9508d1fe.wav",
          "image_url": "https://cdn.apimart.ai/image/flowmusic_9508d1fe_cover.jpg"
        }
      ]
    }
  }
}
```
