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 addcallback_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: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 adata.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
The response shape is different from OpenAI video routes
The response shape is different from OpenAI video routes
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.The task never reaches succeed
The task never reaches succeed
Use bounded polling and inspect
data.task_status_msg when a task fails. Store the task ID for later diagnostics.Should I use callback_url or polling
Should I use callback_url or polling
Use polling as the baseline. Add
callback_url for push delivery, then reconcile final state with polling.Next steps
- Read the Kling text-to-video API reference.
- Poll with Get a Kling task.
- Configure callbacks with Use Kling callback URLs.
- Find Kling video models in Models.
- Review Use polling and webhooks for video generation.
- Estimate task cost with Estimate request cost before calling a model.