> ## 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 异步任务的执行状态、进度和生成结果

```bash cURL theme={null}
curl --request GET \
  --url https://api.apimart.ai/v1/music/tasks/task_01K8AYYM6R03TGZ3Q2P0TZVNPX?language=zh \
  --header 'Authorization: Bearer <token>'
```

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

task_id = "task_01K8AYYM6R03TGZ3Q2P0TZVNPX"
url = f"https://api.apimart.ai/v1/music/tasks/{task_id}"

headers = {
    "Authorization": "Bearer <token>"
}

params = {
    "language": "zh"
}

response = requests.get(url, headers=headers, params=params)

print(response.json())
```

```javascript JavaScript theme={null}
const taskId = "task_01K8AYYM6R03TGZ3Q2P0TZVNPX";
const url = `https://api.apimart.ai/v1/music/tasks/${taskId}?language=zh`;

const headers = {
  "Authorization": "Bearer <token>"
};

fetch(url, {
  method: "GET",
  headers: headers
})
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error("Error:", error));
```

```json 200 theme={null}
{
  "code": 200,
  "data": {
    "id": "task_01K8AYYM6R03TGZ3Q2P0TZVNPX",
    "status": "completed",
    "progress": 100,
    "created": 1783413241,
    "completed": 1783413352,
    "actual_time": 111,
    "cost": 0.06,
    "credits_cost": 0.6,
    "result": {
      "music": [
        {
          "clip_id": "a41aade4-993e-4d28-b56f-d97e7ef7167c",
          "title": "My Song",
          "duration_seconds": "181.70666667",
          "audio_url": "https://cdn.apimart.ai/audio/flowmusic_a41aade4.m4a",
          "wav_url": "https://cdn.apimart.ai/audio/flowmusic_a41aade4.wav"
        }
      ]
    }
  }
}
```

```json 404 theme={null}
{
  "error": {
    "message": "task not found",
    "type": "invalid_request",
    "param": "task_id",
    "code": "task_not_found"
  }
}
```

```json 429 theme={null}
{
  "error": {
    "message": "当前分组容量饱和，请稍后重试",
    "type": "rate_limit_error",
    "param": "",
    "code": "rate_limit_error"
  }
}
```

## 鉴权

**Authorization** `string` *required*

所有 Flow Music 接口都需要 Bearer Token 鉴权

获取 API Key：

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

添加到请求头：

```
Authorization: Bearer YOUR_API_KEY
```

## 路径参数

**task\_id** `string` *required*

提交 Flow Music 任务后返回的任务 ID

> [!NOTE]
>
> 任务 ID 来自提交接口响应中的 `data[0].task_id`。

## 查询参数

**language** `string` (default: zh)

错误信息和部分提示文案的语言

可选值：`zh`、`en`、`ja`、`ko`

## 响应字段

**code** `integer`

响应状态码，成功时为 200

**data** `object`

任务详情

**任务字段**

**id** `string`

任务 ID

**status** `string`

任务状态：`pending`、`processing`、`completed`、`failed`

**progress** `integer`

任务进度，范围 0-100

**cost** `number`

实际扣费金额；任务失败时通常为 0

**credits\_cost** `number`

实际消耗的 credits

**result** `object`

任务完成后的生成结果；不同 Flow Music 能力返回的字段不同

## 结果结构

### 音乐类任务

生成音乐、音乐延伸、片段替换、Cover 改编、词曲分离、上传音频、下载音频和视频渲染通常返回 `result.music` 数组。

```json theme={null}
{
  "result": {
    "music": [
      {
        "clip_id": "a41aade4-993e-4d28-b56f-d97e7ef7167c",
        "audio_url": "https://cdn.apimart.ai/audio/flowmusic_a41aade4.m4a",
        "wav_url": "https://cdn.apimart.ai/audio/flowmusic_a41aade4.wav",
        "video_url": "https://cdn.apimart.ai/video/flowmusic_a41aade4.mp4",
        "file_url": "https://cdn.apimart.ai/audio/flowmusic_a41aade4_stems.zip"
      }
    ]
  }
}
```

### 歌词任务

生成歌词返回 `result.lyrics` 数组。

```json theme={null}
{
  "result": {
    "lyrics": [
      {
        "title": "Bleached",
        "lyrics": "[Intro]\n(Check)\n(One two)\n..."
      }
    ]
  }
}
```

## 使用说明

> [!NOTE]
>
> Flow Music 提交接口都是异步任务。提交成功后先获取 `task_id`，再调用本接口轮询任务状态；当 `status` 为 `completed` 时，从 `result` 中读取生成结果。


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