> ## 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 按模板把音乐渲染成 mp4 视频，支持 simple / modern / player 三种预设

```bash cURL theme={null}
curl --request POST \
  --url https://api.apimart.ai/v1/music/generations/videoClipFlowMusic \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "flowmusic",
    "clip_id": "abc123-def456",
    "preset": "modern"
  }'
```

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

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

payload = {
    "model": "flowmusic",
    "clip_id": "abc123-def456",
    "preset": "modern"
}

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

const payload = {
  model: "flowmusic",
  clip_id: "abc123-def456",
  preset: "modern"
};

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));
```

```json 200 theme={null}
{
  "code": 200,
  "data": [
    {
      "status": "submitted",
      "task_id": "task_01KWXVD4HQEEY7B5NJ31177Q1H"
    }
  ]
}
```

```json 400 theme={null}
{
  "error": {
    "message": "clip_id is required",
    "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"
  }
}
```

## 认证

**Authorization** `string` *required*

所有接口均需要使用 Bearer Token 进行认证

获取 API Key：

访问 [API Key 管理页面](https://apimart.ai/keys) 获取您的 API Key

使用时在请求头中添加：

```
Authorization: Bearer YOUR_API_KEY
```

## 请求参数

**model** `string` *required*

模型名称，**固定传 `"flowmusic"`**（大小写不敏感）

**clip\_id** `string` *required*

需要生成视频的音乐 clip\_id，来自已成功任务的 `result.music[].clip_id`

**preset** `string` (default: simple)

视频模板预设

可选值：

* `simple` - 简洁模板
* `modern` - 现代风格模板
* `player` - 播放器风格模板

## 响应

**code** `integer`

响应状态码，成功时为 200

**data** `array`

返回数据数组

**数组元素**

**status** `string`

任务状态，初始提交时为 `submitted`

**task\_id** `string`

任务唯一标识符，用于查询任务状态和结果

## 使用场景

### 场景 1：用 modern 模板渲染音乐视频

```json theme={null}
{
  "model": "flowmusic",
  "clip_id": "abc123-def456",
  "preset": "modern"
}
```

> [!NOTE]
>
> **查询任务结果**
>
> 音乐视频渲染为异步任务，提交后会返回 `task_id`。使用 [获取任务状态](/cn/api-reference/audios/flow-music/query.md) 接口查询生成进度和结果。结果在 `result.music[0].video_url`。

## 任务完成结果示例

**查询返回示例**（`GET /v1/music/tasks/{task_id}`）：

```json theme={null}
{
  "code": 200,
  "data": {
    "id": "task_01KWXVD4HQEEY7B5NJ31177Q1H",
    "status": "completed",
    "progress": 100,
    "created": 1783413248,
    "completed": 1783413327,
    "actual_time": 79,
    "cost": 0.016,
    "credits_cost": 0.16,
    "result": {
      "music": [
        {
          "clip_id": "a41aade4-993e-4d28-b56f-d97e7ef7167c",
          "video_url": "https://cdn.apimart.ai/video/flowmusic_a41aade4_video_clip.mp4",
          "url": "https://cdn.apimart.ai/video/flowmusic_a41aade4_video_clip.mp4"
        }
      ]
    }
  }
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.