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

# Generate Lyrics

> Flow Music generates lyrics from a prompt. The result can be filled into the lyrics field of the Generate Music endpoint

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://gccai.heqingsong.uk/v1/music/generations/lyricsFlowMusic \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
      "model": "flowmusic",
      "prompt": "A rock song about perseverance"
    }'
  ```

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

  url = "https://gccai.heqingsong.uk/v1/music/generations/lyricsFlowMusic"

  payload = {
      "model": "flowmusic",
      "prompt": "A rock song about perseverance"
  }

  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://gccai.heqingsong.uk/v1/music/generations/lyricsFlowMusic";

  const payload = {
    model: "flowmusic",
    prompt: "A rock song about perseverance"
  };

  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": "Insufficient balance",
      "type": "invalid_request",
      "param": "",
      "code": "quota_not_enough"
    }
  }
  ```

  ```json 429 theme={null}
  {
    "error": {
      "message": "Current group capacity is saturated, please retry later",
      "type": "rate_limit_error",
      "param": "",
      "code": "rate_limit_error"
    }
  }
  ```
</ResponseExample>

## Authentication

<ParamField header="Authorization" type="string" required>
  All endpoints require Bearer Token authentication

  Get your API Key:

  Visit the [API Key management page](https://gccai.heqingsong.uk/keys) to get your API Key

  Add it to the request header:

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

## Request Parameters

<ParamField body="model" type="string" required>
  Model name, **must be `"flowmusic"`** (case-insensitive)
</ParamField>

<ParamField body="prompt" type="string" required>
  Prompt for generating lyrics, **≤ 3000 characters**

  It is recommended to describe the song's theme, style, and mood to get better-fitting lyrics

  Example: `"A rock song about perseverance"`
</ParamField>

## Response

<ResponseField name="code" type="integer">
  Response status code, 200 on success
</ResponseField>

<ResponseField name="data" type="array">
  Array of returned data

  <Expandable title="Array elements">
    <ResponseField name="status" type="string">
      Task status, `submitted` upon initial submission
    </ResponseField>

    <ResponseField name="task_id" type="string">
      Unique task identifier, used to query task status and results
    </ResponseField>
  </Expandable>
</ResponseField>

## Use Cases

### Scenario 1: Generate lyrics by theme

```json theme={null}
{
  "model": "flowmusic",
  "prompt": "A rock song about perseverance"
}
```

### Scenario 2: Fill generated lyrics into a song

First generate lyrics; once done, take the `title` and `lyrics` from `result.lyrics[0]` and fill them into the [Generate Music](./music) endpoint:

```json theme={null}
{
  "model": "flowmusic",
  "title": "Perseverance",
  "lyrics": "[Verse 1]\nEven the longest night turns to dawn\n...",
  "sound_prompt": "energetic rock with electric guitar"
}
```

<Note>
  **Query Task Results**

  Lyrics generation is an asynchronous task; a `task_id` is returned after submission. Use the [Get Task Status](./query) endpoint to query generation progress and results.
</Note>

## Completed Task Result Example

**Query response example** (`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..."
        }
      ]
    }
  }
}
```
