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