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:
Poll the task with:
Authenticate with a Bearer token:

Code examples

Use the tabs below for copyable examples in cURL, Python, and Node.js.

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

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

Last modified on June 30, 2026