> ## 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 プロンプトに基づいて歌詞を生成します。結果は音楽生成 API の lyrics フィールドに設定できます

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://api.apimart.ai/v1/music/generations/lyricsFlowMusic \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
      "model": "flowmusic",
      "prompt": "継続をテーマにしたロックソング"
    }'
  ```

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

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

  payload = {
      "model": "flowmusic",
      "prompt": "継続をテーマにしたロックソング"
  }

  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/lyricsFlowMusic";

  const payload = {
    model: "flowmusic",
    prompt: "継続をテーマにしたロックソング"
  };

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

  ```json 400 theme={null}
  {
    "error": {
      "message": "model is required",
      "type": "invalid_request",
      "param": "",
      "code": "model_required"
    }
  }
  ```

  ```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="prompt" type="string" required>
  歌詞生成のプロンプト。**3000 文字以内**

  よりマッチした歌詞を得るために、曲のテーマ、スタイル、雰囲気などを記述することをおすすめします

  例：`"継続をテーマにしたロックソング"`
</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：テーマから歌詞を生成

```json theme={null}
{
  "model": "flowmusic",
  "prompt": "継続をテーマにしたロックソング"
}
```

### シーン 2：歌詞を設定して作曲

先に歌詞を生成し、完了後に `result.lyrics[0]` の `title` と `lyrics` を取得して、[音楽生成](./music)API に設定します：

```json theme={null}
{
  "model": "flowmusic",
  "title": "継続",
  "lyrics": "[Verse 1]\nどんなに長い夜も必ず明ける\n...",
  "sound_prompt": "energetic rock with electric guitar"
}
```

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

  歌詞生成は非同期タスクです。送信後に `task_id` が返されます。[タスクステータスの取得](./query) API を使用して、生成の進捗と結果を照会してください。
</Note>

## タスク完了結果の例

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

```json theme={null}
{
  "code": 200,
  "data": {
    "id": "task_01KWXVCX91HYHSTHZ0NC1SRFW1",
    "status": "completed",
    "progress": 100,
    "created": 1783413241,
    "completed": 1783413284,
    "actual_time": 43,
    "cost": 0.016,
    "credits_cost": 0.16,
    "result": {
      "lyrics": [
        {
          "title": "Bleached",
          "lyrics": "[Intro]\n(Check)\n(One two)\n\n[Verse 1]\nThe birds are..."
        }
      ]
    }
  }
}
```
