跳转到主要内容
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

存储音频输出

如果你需要在提供商交付窗口之外继续保留音频资源,请持久化保存最终的音频资源。
完整参数说明请参阅 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
必填