# Kling V2.1 API

> Kling V2.1 — high-quality AI video generation.

- **Provider**: Kling
- **Model id**: `kling-v2-1-pro`
- **Modality**: video
- **Price**: 35.88–71.75 credits

## Overview

Kling V2.1 is called in two steps: create a generation task, then poll the task until the result is ready.

## Authentication

All requests require a Bearer Token in the request header:

```
Authorization: Bearer YOUR_API_KEY
```

## Create Task

`POST https://you.bot/api/v1/generate`

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| modelId | string | Yes | Model id: `kling-v2-1-pro` |
| input | object | Yes | Input parameters object (see below) |
| callbackUrl | string | No | https URL we POST the finished task to. Signed with `X-Webhook-Signature` once you create a webhook signing key in Dashboard → Settings |

### input object parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| prompt | string | Yes | Text prompt describing the video to generate Max 5000 characters. (example: Animate the still: honey drizzles in a slow golden ribbon over a warm stack of pancakes, melting butter sliding down the sides as the camera eases in and faint… — full value in the request example) |
| image_url | string | Yes | URL of the image to be used for the video (image URL) |
| duration | string | No | The duration of the generated video in seconds (options: 5 \| 10) (default: 5) |
| negative_prompt | string | No | Terms to avoid in the generated video Max 500 characters. (default: blur, distort, and low quality) |
| cfg_scale | number | No | The CFG (Classifier Free Guidance) scale is a measure of how close you want the model to stick to your prompt (range 0-1) (default: 0.5) |
| tail_image_url | string | No | URL of the image to be used for the end of the video (image URL) |
| nsfw_checker | boolean | No | A configurable parameter. Defaults to true in the Playground. (true/false) (default: true) |

### Request example

```json
{
  "modelId": "kling-v2-1-pro",
  "input": {
    "prompt": "Animate the still: honey drizzles in a slow golden ribbon over a warm stack of pancakes, melting butter sliding down the sides as the camera eases in and faint steam drifts across the frame.",
    "image_url": "https://you.bot/examples/grok-imagine-text-to-image.jpg",
    "duration": "5",
    "negative_prompt": "blur, distort, and low quality",
    "cfg_scale": 0.5,
    "tail_image_url": "https://you.bot/examples/grok-imagine-text-to-image.jpg",
    "nsfw_checker": true
  }
}
```

### Response example

```json
{
  "taskId": "281e5b0…f39b9",
  "creditsCharged": 35.88
}
```

## Query Task

`GET https://you.bot/api/v1/task/{taskId}?model=kling-v2-1-pro`

When `state` is `success`, the output is in `resultUrls`: `{ "state": "success", "resultUrls": [ ... ] }`. (Text models return inline in the create response.)

## Error Codes

| Code | Description |
|------|-------------|
| 200 | Request successful |
| 400 | Invalid request parameters |
| 401 | Authentication failed — check API Key |
| 402 | Insufficient account balance |
| 403 | IP not allowed for this key, or the key is restricted to other models |
| 404 | Task not found, or it has expired |
| 409 | Duplicate request — an identical submit arrived moments ago. Nothing was charged; retry is safe |
| 413 | Payload too large — see the character and file-size limits for this model |
| 429 | Rate limit exceeded — retry after the Retry-After header |
| 500 | Internal server error |
| 504 | Upstream timed out — nothing was delivered; retry is safe |
