跳轉到主要內容
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 產生一段短音訊片段。

呼叫前須知

  • 保持 prompt 簡潔明確
  • 建議先將 duration 設定在 3 到 10 秒之間
  • callback_urlexternal_task_id 視為可選的整合輔助欄位,而非核心必要項目

任務流程

1

提交音訊任務

傳送文字 Prompt 與時長,然後保存回傳的 task id。
2

輪詢任務

透過 Kling 音訊查詢路徑,使用 Individual Queries 持續查詢,直到任務進入最終狀態。
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
必填