> ## 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，换取 clip_id 供后续延伸 / 替换 / Cover / 分离使用

```bash cURL theme={null}
curl --request POST \
  --url https://api.apimart.ai/v1/music/generations/uploadAudioFlowMusic \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "flowmusic",
    "audio_url": "https://example.com/audio.mp3"
  }'
```

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

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

payload = {
    "model": "flowmusic",
    "audio_url": "https://example.com/audio.mp3"
}

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

const payload = {
  model: "flowmusic",
  audio_url: "https://example.com/audio.mp3"
};

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

```json 400 theme={null}
{
  "error": {
    "message": "audio_url 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"`**（大小写不敏感）

**audio\_url** `string` *required*

待上传音频文件地址，需公网可访问

> [!WARNING]
>
> 仅支持常见音频文件后缀（如 `.mp3` / `.wav`）。

## 响应

**code** `integer`

响应状态码，成功时为 200

**data** `array`

返回数据数组

**数组元素**

**status** `string`

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

**task\_id** `string`

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

## 使用场景

### 场景 1：导入外部音频换取 clip\_id

```json theme={null}
{
  "model": "flowmusic",
  "audio_url": "https://example.com/audio.mp3"
}
```

完成后从 `result.music[0].clip_id` 取导入产物的 clip\_id，即可用于[延伸](/cn/api-reference/audios/flow-music/extend.md) / [替换](/cn/api-reference/audios/flow-music/replace.md) / [Cover](/cn/api-reference/audios/flow-music/cover.md) / [分离](/cn/api-reference/audios/flow-music/stems.md)。

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

## 任务完成结果示例

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

```json theme={null}
{
  "code": 200,
  "data": {
    "id": "task_01KWXVD2FC61SYZ5103Z4XCCS5",
    "status": "completed",
    "progress": 100,
    "created": 1783413246,
    "completed": 1783413282,
    "actual_time": 36,
    "cost": 0.008,
    "credits_cost": 0.08,
    "result": {
      "music": [
        {
          "clip_id": "1db3a20f-4ddc-44e8-8c9c-6c9093c16ffe",
          "audio_url": "https://cdn.apimart.ai/audio/flowmusic_1db3a20f_upload_audio.wav",
          "url": "https://cdn.apimart.ai/audio/flowmusic_1db3a20f_upload_audio.wav"
        }
      ]
    }
  }
}
```


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