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

# CosyVoice 3 Plus API：语音合成与声音克隆

> CosyVoice 3 Plus 文本转语音 API 支持内置语音、自定义语音克隆和语音设计工作流

## 概览

CosyVoice 3 Plus 是阿里巴巴的音频模型，支持文字转语音，也能创建自定义音色。在 APIXO Playground 试用后，可以按本页示例调用 API。

| 功能 | 值 |
| - | - |
| 模型 ID | `cosyvoice-3-plus` |
| 模式 | `speech`, `clone`, `design` |
| 内置声音 | 是 |
| 自定义音色 | 是 |
| 语音提示长度 | 1 至 20000 个字符 |
| 设计提示长度 | 1 至 500 个字符 |
| 预览文本长度 | 1 至 200 个字符 |
| 克隆音频 URL | 正好 1 个 URL |

## 接口与身份验证

API 基础地址：

```text theme={null}
https://api.apixo.ai/api/v1
```

| 方法 | 端点 | 用途 |
| - | - | - |
| `POST` | `/generateTask/cosyvoice-3-plus` | 提交演讲、克隆或设计任务 |
| `GET` | `/statusTask/cosyvoice-3-plus?taskId={taskId}` | 查询任务状态并获取结果 |

每个请求都必须携带 APIXO API 密钥：

```http theme={null}
Authorization: Bearer YOUR_API_KEY
```

提交任务时，还需要设置以下请求头：

```http theme={null}
Content-Type: application/json
```

## 异步请求示例

此最小请求提交语音任务并返回 `taskId`。

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/cosyvoice-3-plus" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "async",
    "input": {
      "mode": "speech",
      "voice": "longanyang",
      "prompt": "Hello, welcome to APIXO.",
      "format": "mp3"
    }
  }'
```

成功响应：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678"
  }
}
```

保存 `taskId`，后续轮询结果时需要用到它。

## 轮询结果

```bash theme={null}
curl -X GET "https://api.apixo.ai/api/v1/statusTask/cosyvoice-3-plus?taskId=task_12345678" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

任务处理中的响应示例：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "processing",
    "createTime": 1767965610929
  }
}
```

成功响应：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "success",
    "resultJson": "{\"resultUrls\":[\"https://file.apixo.ai/xxx.mp3\"]}",
    "createTime": 1767965610929,
    "completeTime": 1767965622450,
    "costTime": 11521
  }
}
```

自定义语音成功响应：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "success",
    "voice_id": "cosyvoice-v3-plus-xxxx",
    "voice_status": "OK",
    "resultJson": "{\"resultUrls\":[\"https://file.apixo.ai/preview.wav\"]}",
    "createTime": 1767965610929,
    "completeTime": 1767965682450,
    "costTime": 71521
  }
}
```

任务失败时的响应示例：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "failed",
    "failCode": "UNDEPLOYED",
    "failMsg": "Voice review failed. This custom voice is unavailable (UNDEPLOYED).",
    "voice_id": "cosyvoice-v3-plus-xxxx",
    "voice_status": "UNDEPLOYED",
    "createTime": 1767965610929,
    "completeTime": 1767965682450
  }
}
```

等 `state` 变为 `success` 后，再解析 `resultJson`：

```javascript theme={null}
const payload = JSON.parse(data.resultJson);
const audioUrls = payload.resultUrls;
```

## 请求体

### 语音

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "speech",
    "voice": "longanyang",
    "prompt": "Welcome to APIXO.",
    "format": "mp3",
    "sample_rate": 24000,
    "rate": 1.0,
    "pitch": 1.0,
    "volume": 50
  }
}
```

### 克隆

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "clone",
    "prefix": "demo01",
    "audio_urls": [
      "https://example.com/reference.wav"
    ]
  }
}
```

### 设计

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "design",
    "prefix": "demo02",
    "prompt": "A calm and warm female narration voice for podcast reading.",
    "preview_text": "Hello, this is the preview sample."
  }
}
```

## 参数

**request\_type** `string` *required* (default: async)

结果获取方式。选择 `async` 时，通过 `statusTask` 轮询结果；选择 `callback` 时，通过 Webhook 接收结果。

**callback\_url** `string`

当 `request_type` 为 `callback` 时必填。请提供公网可访问的 HTTPS 地址，用于接收任务的最终结果。详见 [Webhook](https://apixo.ai/docs/zh/api-reference/webhooks.md)。

**input** `object` *required*

CosyVoice 3 Plus 的输入参数。

**属性**

**mode** `string` *required*

工作流程类型。支持的值：`speech`、`clone`、`design`。

**voice** `string`

`speech` 必填项，支持内置系统语音或先前创建的 `voice_id`。

**prompt** `string`

对于 `speech` 和 `design` 是必需的。在 `speech` 中，这是合成文本，支持 1-20000 个字符；在 `design` 中，这是语音描述，支持 1-500 个字符。

**audio\_urls** `string[]`

`clone` 所需。必须恰好包含 1 个非空音频 URL。

**preview\_text** `string`

`design` 所需。用于预览生成的自定义语音的文本，支持 1-200 个字符。

**prefix** `string`

对于 `clone` 和 `design` 是必需的。必须匹配正则表达式 `^[A-Za-z0-9]{1,10}$`。

**format** `string`

可选的输出格式。在 `speech` 中传递；在 `design` 中，APIXO 也将其作为预览的 `response_format` 使用。若 `design` 中未指定，则预览默认为 `wav`。

**sample\_rate** `integer`

可选采样率。在 `speech` 中传递，并支持克隆或设计预览输出时使用。

**rate** `number`

`speech` 的可选语速控制。

**pitch** `number`

`speech` 的可选音高控制。

**volume** `number`

`speech` 的可选音量控制。

**instruction** `string`

`speech` 的可选指令文本，最多 100 个字符。

**language\_hints** `string[]`

可选的语言提示。APIXO 接受字符串或字符串数组，并仅使用第一个非空项。

**enable\_ssml** `boolean`

可选，控制 `speech` 是否启用 SSML。

**word\_timestamp\_enabled** `boolean`

`speech` 的可选字时间戳开关。

**enable\_aigc\_tag** `boolean`

可选，控制 `speech` 是否添加 AIGC 标签。

**aigc\_propagator** `string`

可选，供 `speech` 使用的 AIGC 传播元数据。

**aigc\_propagate\_id** `string`

可选，供 `speech` 使用的 AIGC 传播 ID。

**hot\_fix** `boolean`

可选的语音兼容性选项。可用性可能因情况而异。

**enable\_markdown\_filter** `boolean`

可选，控制 `speech` 是否过滤 Markdown 标记。

**nsfw\_checker** `boolean` (default: false)

设为 `true` 可在支持的生成路由上启用上游内容审核。API 默认值为 `false`。

## 响应格式

### 提交任务时的响应

任务受理后，`POST /generateTask/cosyvoice-3-plus` 会返回任务 ID：

**code** `integer`

API 状态码。`200` 表示任务已受理。

**message** `string`

状态说明。

**data.taskId** `string`

任务的唯一 ID，用于查询任务状态。

### 状态响应字段

**taskId** `string`

任务的唯一标识符。

**state** `string`

当前任务状态，可能的值为 `pending`、`processing`、`success`、`failed`。

**resultJson** `string`

包含音频结果 URL 的 JSON 字符串。有音频输出时返回。

**voice\_id** `string`

克隆或设计工作流程返回的自定义语音 ID。

**voice\_status** `string`

自定义语音状态，例如 `DEPLOYING`、`OK` 或 `UNDEPLOYED`。

**failCode** `string`

供程序处理的错误码，仅在 `state` 为 `failed` 时返回。

**failMsg** `string`

失败原因说明，仅在 `state` 为 `failed` 时返回。

**createTime** `integer`

任务创建时的 Unix 时间戳，单位为毫秒。

**completeTime** `integer`

任务完成时的 Unix 时间戳，单位为毫秒。任务完成后返回。

**costTime** `integer`

处理耗时，单位为毫秒。任务成功后返回。

## Webhook 回调模式

如果希望服务端自动收到最终结果，可以使用回调模式，无需轮询。

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/cosyvoice-3-plus" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "callback",
    "callback_url": "https://your-server.com/webhooks/apixo",
    "input": {
      "mode": "design",
      "prefix": "warm01",
      "prompt": "A calm and clean male narration voice for explainers.",
      "preview_text": "This is a preview sample."
    }
  }'
```

Webhook 接收要求和重试规则见 [Webhook 文档](https://apixo.ai/docs/zh/api-reference/webhooks.md)。

## 计费

新提交的非 LLM 请求按 **1 积分 = `$0.001`** 计费。先按用量和附加项目计算总额，再应用账号折扣，最后将请求总额向上取整到整数积分。如果约定了固定单价，则按该单价的原始精度计算，不再使用标准价或另行打折；最终积分仍向上取整。详见[积分换算与取整](https://apixo.ai/docs/zh/pricing.md#credit-conversion-and-rounding)。

CosyVoice 3 Plus 根据工作流使用不同的计费单位。

| 工作流程 | APIXO 价格 |
| - | - |
| `speech` | `$0.30 / 10K characters` |
| `clone` | `$0.002 / request` |
| `design` | `$0.03 / request` |

最新的美元费率见 [API 价目表](https://apixo.ai/pricing/api)。

## 延迟与轮询

实际延迟可能因文本长度、语音路由、队列负载以及是否使用自定义语音而异。

| 工作流程 | 通常生成耗时 | 建议首次查询时间 | 轮询间隔 |
| - | - | - | - |
| `speech` | 5s-30s | 任务创建 5 秒后 | 3s-5s |
| `clone` | 30s-180s | 任务创建 20 秒后 | 5s-10s |
| `design` | 30s-180s | 任务创建 20 秒后 | 5s-10s |

> [!TIP]
>
> 在生产语音创建工作流中使用回调模式，以避免后端在较长的 `DEPLOYING` 阶段进行轮询。

如果自定义音色长时间停留在 `DEPLOYING` 状态，任务最终可能因超时而失败。

自定义 `voice_id` 连续 7 天未使用便会被清理。若要保留该音色，请确保每 7 天至少使用这个 `voice_id` 调用一次 `speech`。

## 错误与排查

### HTTP 错误

| 代码 | 含义 | 处理方式 |
| - | - | - |
| `400` | 请求体或参数结构不正确 | 在重试前修复请求 |
| `401` | 缺少 API 密钥，或密钥无效 | 检查 `Authorization` 请求头 |
| `402` | 余额或配额不足 | 充值或更换账号或API密钥 |
| `403` | 密钥或路由无权访问该模型 | 检查权限和路由策略 |
| `429` | 已达到速率或并发限制 | 按指数退避策略重试 |
| `500` | 服务器错误 | 逐步延长间隔后重试 |
| `502` | 服务错误 | 逐步延长间隔后重试 |
| `504` | 服务超时 | 重试或使用回调模式 |

### 任务失败案例

| 错误码 | 含义 | 处理方式 |
| - | - | - |
| `UNDEPLOYED` | 语音审核失败，自定义语音不可用 | 使用更好的输入音频或不同的设计提示创建新的语音 |
| `TASK_TIMEOUT` | 自定义语音部署在 `DEPLOYING` 状态中停留时间过长 | 稍后重试 |
| `VALIDATION_ERROR` | 输入未通过 APIXO 验证，或 `voice_id` 对当前用户、活动语音服务或目标模型无效 | 重试前需修复输入 |
| `UpstreamError` | 任务因未知原因失败 | 逐步延长间隔后重试 |

常见的验证规则：

* `voice` 必须用于 `speech`。APIXO 也接受请求中的遗留 `voice_id`，并将其标准化为 `voice`。
* 自定义 `voice_id` 值必须属于当前用户，并与活动语音服务及目标模型兼容
* 自定义 `voice_id` 连续 7 天未使用便会被删除。
* 仅 `cosyvoice-3-plus` 支持 `longanhuan` 和 `longanyang` 等内置系统语音。
* `audio_urls` 必须是一个包含且仅包含一个非空 URL 的数组
* `prefix`必须是1-10个字母或数字。
* `instruction` 最多只能是 100 个字符。

## MCP 集成

[完整模型 Schema](https://apixo.ai/docs/models/schemas/audio/cosyvoice-3-plus.json) 中的 `mcp.result` 指定了结果的解析方式，`mcp.attachments` 列出支持绑定文件的字段。这些元数据供客户端集成使用，无需作为生成参数提交。附件字段为 `audio_urls`。请保留用户指定的文件顺序。API 负责校验模型参数。轮询时请带上返回的 `media_type`：语音合成使用 `speech`，声音克隆或设计使用 `voice`。任务成功且声音就绪后，才能复用该声音。

## 相关链接

* [生成 API 概览](https://apixo.ai/docs/zh/models.md)
* [音频模型](https://apixo.ai/docs/zh/models/audio)
* [提交生成任务](https://apixo.ai/docs/zh/api-reference/generate-task.md)
* [查询任务状态](https://apixo.ai/docs/zh/api-reference/status-task.md)
* [Webhook](https://apixo.ai/docs/zh/api-reference/webhooks.md)
* [错误码](https://apixo.ai/docs/zh/api-reference/errors.md)
* [API定价](https://apixo.ai/pricing/api)


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