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

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

<ResponseExample>
  ```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"
    }
  }
  ```
</ResponseExample>

## 鉴权

<ParamField header="Authorization" type="string" required>
  所有 Flow Music 接口都需要 Bearer Token 鉴权

  获取 API Key：

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

  添加到请求头：

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

## 路径参数

<ParamField path="task_id" type="string" required>
  提交 Flow Music 任务后返回的任务 ID

  <Note>
    任务 ID 来自提交接口响应中的 `data[0].task_id`。
  </Note>
</ParamField>

## 查询参数

<ParamField query="language" type="string" default="zh">
  错误信息和部分提示文案的语言

  可选值：`zh`、`en`、`ja`、`ko`
</ParamField>

## 响应字段

<ResponseField name="code" type="integer">
  响应状态码，成功时为 200
</ResponseField>

<ResponseField name="data" type="object">
  任务详情

  <Expandable title="任务字段">
    <ResponseField name="id" type="string">
      任务 ID
    </ResponseField>

    <ResponseField name="status" type="string">
      任务状态：`pending`、`processing`、`completed`、`failed`
    </ResponseField>

    <ResponseField name="progress" type="integer">
      任务进度，范围 0-100
    </ResponseField>

    <ResponseField name="cost" type="number">
      实际扣费金额；任务失败时通常为 0
    </ResponseField>

    <ResponseField name="credits_cost" type="number">
      实际消耗的 credits
    </ResponseField>

    <ResponseField name="result" type="object">
      任务完成后的生成结果；不同 Flow Music 能力返回的字段不同
    </ResponseField>
  </Expandable>
</ResponseField>

## 结果结构

### 音乐类任务

生成音乐、音乐延伸、片段替换、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` 中读取生成结果。
</Note>
