Skip to main content

What you will build

You will submit a Kling text-to-video task, store the returned task ID, poll the matching Kling task endpoint, and decide when to add callback_url for push notifications.

Prerequisites

  • A CometAPI API key stored in COMETAPI_KEY
  • Python 3.10+ with requests, or Node.js 18+
  • A server-side worker for polling or an HTTPS callback endpoint for webhooks

API key, base URL, authentication

Create a Kling text-to-video task with:
POST https://api.cometapi.com/kling/v1/videos/text2video
Poll the task with:
GET https://api.cometapi.com/kling/v1/videos/text2video/<task_id>
Authenticate with a Bearer token:
Authorization: Bearer $COMETAPI_KEY

Code examples

Use the tabs below for copyable examples in cURL, Python, and Node.js.
curl https://api.cometapi.com/kling/v1/videos/text2video \
  -H "Authorization: Bearer $COMETAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A small ceramic cup on a wooden table, steam rising in soft morning light",
    "model_name": "kling-v3",
    "mode": "std",
    "duration": "5",
    "sound": "off"
  }'

curl "https://api.cometapi.com/kling/v1/videos/text2video/<task_id>" \
  -H "Authorization: Bearer $COMETAPI_KEY"

Flow explanation

Kling video generation is asynchronous. The create endpoint returns a data.task_id. Poll GET /kling/v1/videos/text2video/<task_id> until data.task_status reaches succeed or failed. When the task succeeds, copy the finished asset URL from data.task_result into your own storage if you need durable access. Add callback_url when you want task status updates pushed to an HTTPS endpoint you control. Keep polling available for reconciliation and missed callback delivery.

Common parameters

ParameterUse
promptText prompt for the video task.
model_nameKling model ID. The reference example uses kling-v3.
modeGeneration mode. Start with std before testing higher-cost modes.
durationOutput length. The reference page uses 5 for a first request.
soundUse off for a deterministic no-audio first request on supported model tracks.
callback_urlOptional HTTPS URL for task status callbacks.

Troubleshooting / FAQ

Kling uses provider-specific JSON fields such as data.task_id, data.task_status, and data.task_result. Do not parse it like the OpenAI-compatible /v1/videos routes.
Use bounded polling and inspect data.task_status_msg when a task fails. Store the task ID for later diagnostics.
Use polling as the baseline. Add callback_url for push delivery, then reconcile final state with polling.

Next steps