# Kling 4.0 API Documentation

Generate videos with Kling 4.0. Submit a request, save the task ID, then query for the finished video.

## Overview

Model ID: kling-4-0. Text to Video · Image to Video. Check the current price and availability before your first request.

`POST /v1/tasks` — Create a task

`GET /v1/tasks/{id}` — Get the result

- [Model pricing & playground](https://gikyapi.com/models/kling-4-0/)

## Authentication

Use Authorization: Bearer YOUR_API_KEY. For task creation, also send Content-Type: application/json and a unique Idempotency-Key. The example below includes all three headers.

## Request examples

Choose an operation and language. Replace YOUR_API_KEY and use a unique Idempotency-Key for each new generation; preserve it when retrying the same request.

### Text to Video

```json
{
  "model": "kling-4-0",
  "operation": "text-to-video",
  "input": {
    "prompt": "A blue ceramic cup on a white table, soft morning light",
    "resolution": "1080p",
    "duration_seconds": 3
  }
}
```

### Image to Video

```json
{
  "model": "kling-4-0",
  "operation": "image-to-video",
  "input": {
    "prompt": "A blue ceramic cup on a white table, soft morning light",
    "image_urls": [
      "https://example.com/reference.png"
    ],
    "resolution": "1080p",
    "duration_seconds": 3
  }
}
```

## Request parameters

The request body contains model, operation and input. Model-specific fields belong inside input; their accepted values are listed below.

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| model | string | Yes | kling-4-0 |
| operation | string | Yes | text-to-video / image-to-video |
| input | object | Yes | Parameters for your selected operation. |
| callback | object | No | Use an endpoint_id saved in your account’s Webhooks settings. Omit this field when polling. |

## Text to Video input

Fields inside input. Optional fields may be omitted; send only the fields listed here.

| Parameter | Type | Required | Description / accepted values |
| --- | --- | --- | --- |
| prompt | string | Yes | Describe the scene, style or edit you want to make. Minimum 2 characters. Maximum 1000 characters. |
| resolution | string | Yes | Output resolution. Choose a resolution listed in the model pricing. Accepted: 720p, 1080p. |
| aspect_ratio | string | No | Aspect ratio of the generated output. Accepted: 16:9, 9:16, 1:1, 21:9. |
| duration_seconds | integer | Yes | Length of the generated video, in seconds. Accepted: 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30. |

## Image to Video input

Fields inside input. Optional fields may be omitted; send only the fields listed here.

| Parameter | Type | Required | Description / accepted values |
| --- | --- | --- | --- |
| prompt | string | Yes | Describe the scene, style or edit you want to make. Minimum 2 characters. Maximum 1000 characters. |
| image_urls | array | Yes | Public HTTPS URLs of reference images. Each URL must be accessible without signing in. Maximum 1 items. |
| resolution | string | Yes | Output resolution. Choose a resolution listed in the model pricing. Accepted: 720p, 1080p. |
| aspect_ratio | string | No | Aspect ratio of the generated output. Accepted: 16:9, 9:16, 1:1, 21:9. |
| keyframe_urls | array | No | keyframe urls. Maximum 8 items. |
| last_image_urls | array | No | last image urls. Maximum 1 items. |
| duration_seconds | integer | Yes | Length of the generated video, in seconds. Accepted: 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30. |

## Create response

HTTP 202 means the task was accepted. Save id and use it to query the result. The response below is illustrative; generation has not finished at this stage.

```
{
  "id": "00000000-0000-4000-8000-000000000001",
  "status": "queued",
  "outputs": [],
  "error_code": null,
  "created_at": "2026-11-02T00:00:00Z",
  "updated_at": "2026-11-02T00:00:00Z"
}
```

## Query the result

Replace TASK_ID with the returned id. Use the same API key and poll every five seconds or more. When status is succeeded, read the file URLs from outputs.

`GET /v1/tasks/{id}` — Retrieve a task

```
curl --fail-with-body 'https://gikyapi.com/v1/tasks/TASK_ID' -H 'Authorization: Bearer YOUR_API_KEY'
```

## Response parameters

Creation and status queries return the same task structure.

| Field | Type | Description |
| --- | --- | --- |
| id | string | Task ID used in subsequent status queries. |
| status | string | queued / submitting / running / succeeded / failed / needs_review |
| outputs | string[] | Generated file URLs when the task succeeds. Save files to your own storage. |
| error_code | string | null | Failure code when available; null if there is no error. |
| created_at | string | Time the task was created. |
| updated_at | string | Time of the last task update. |

```
{
  "id": "00000000-0000-4000-8000-000000000001",
  "status": "succeeded",
  "outputs": [
    "https://example.com/result.mp4"
  ],
  "error_code": null,
  "created_at": "2026-11-02T00:00:00Z",
  "updated_at": "2026-11-02T00:00:00Z"
}
```

## Webhooks (optional)

Add an endpoint in Dashboard → Webhooks and save the signing secret on your server. Include its ID in the task request. You can also poll task status without configuring a callback.

| Parameter | Type | Required with callback | Description |
| --- | --- | --- | --- |
| callback.endpoint_id | string | Yes | ID of a callback endpoint owned by your account. |

```
{
  "callback": {
    "endpoint_id": "YOUR_ENDPOINT_ID"
  }
}
```

- [Configure callback endpoints](https://gikyapi.com/dashboard/webhooks/)
- [Signature verification & delivery retries](https://gikyapi.com/docs/webhooks/)

## Webhook parameters

Completion events use task.succeeded or task.failed. Verify the signature before processing and deduplicate by event id. A missing callback does not mean the task failed; query its status.

| Field | Type | Description |
| --- | --- | --- |
| id | string | Unique event ID; use it to deduplicate deliveries. |
| type | string | task.succeeded or task.failed |
| task_id | string | The generation task ID. |
| status | string | Task status at the time of the event. |
| outputs | string[] | Generated file URLs for a successful task. |

## Errors & retries

If a submission times out, retry with the same Idempotency-Key and identical body. If you already have a task ID, query that task instead of creating another one.

| Status | What to do |
| --- | --- |
| 400 | Check required fields, accepted values and the priced configuration. |
| 401 | Check your API key, expiry and restrictions. |
| 409 | Check the error code: refresh changed configurations or resolve a reused request key. |
| 429 | Wait at least 60 seconds before retrying. |
| failed | Read error_code and check the consumption record. |
| needs_review | Keep the task ID and stop automatic resubmission. |

- [All error codes](https://gikyapi.com/docs/errors/)
- [Billing & refunds](https://gikyapi.com/docs/billing/)
