跳转到主要内容
POST
/
kling
/
v1
/
audio
/
text-to-audio
Create a Kling text-to-audio task
curl --request POST \
  --url https://api.cometapi.com/kling/v1/audio/text-to-audio \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "prompt": "Soft ambient ocean waves at sunrise.",
  "duration": 5
}
'
{
  "code": 0,
  "message": "SUCCEED",
  "data": {
    "task_id": "861254119619698760",
    "task_status": "submitted",
    "task_info": {},
    "created_at": 1773367502225,
    "updated_at": 1773367502225
  }
}
使用此端点可通过 Kling 根据文本提示生成一段简短的音频片段。

调用前须知

  • 保持 prompt 简洁直接
  • 建议将 duration 从 3 到 10 秒之间开始设置
  • callback_urlexternal_task_id 视为可选的集成辅助参数,而不是核心必需项

任务流程

1

提交音频任务

发送文本提示和时长,然后保存返回的任务 id。
2

轮询任务

使用 Kling 音频查询路径继续通过单项查询进行查询,直到任务进入终态。
3

存储音频输出

如果你需要在提供方交付窗口之外继续保留最终音频资源,请将其持久化存储。
在 2026-03-13 的实时验证中确认,仅包含 promptduration 的最小请求可被接受,并返回 task_status: submitted
完整参数说明请参阅官方 Kling 文档

授权

Authorization
string
header
必填

Bearer token authentication. Use your CometAPI key.

请求体

application/json
prompt
string
默认值:Hello
必填

Text prompt describing the audio to generate. Max 200 characters.

duration
integer
默认值:5
必填

Duration of the generated audio in seconds. Range: 3.0–10.0, supports one decimal place.

external_task_id
string
默认值:audio-text-task-001

Optional user-defined task ID for your own tracking. Does not replace the system-generated task ID. Must be unique per account.

callback_url
string
默认值:https://example.com/webhook

Webhook URL for task status notifications. The server sends a callback when the task status changes.

响应

200 - application/json

Task accepted.

code
integer
必填

Error code; specific error code definition

message
string
必填

Error message

data
object
必填