> ## Documentation Index
> Fetch the complete documentation index at: https://apixo.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Kling 2.1

> Kuaishou Kling 2.1 video generation API for standard, pro, and master video workflows

## Overview

Kling 2.1 is a tiered Kuaishou video model for image-to-video generation and master-quality text-to-video generation. Use this page when you are ready to call the API after trying the model in the APIXO playground.

| Capability       | Value                                                                                                                              |
| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| Model ID         | `kling-2-1`                                                                                                                        |
| Modes            | `standard-image-to-video`, `pro-image-to-video`, `master-text-to-video`, `master-image-to-video`                                   |
| Prompt length    | 1-5000 characters                                                                                                                  |
| Duration         | `5` or `10` seconds                                                                                                                |
| Reference images | None for `master-text-to-video`; exactly 1 for `standard-image-to-video` and `master-image-to-video`; 1-2 for `pro-image-to-video` |
| Aspect ratios    | `16:9`, `9:16`, `1:1` for `master-text-to-video` only                                                                              |
| Output format    | MP4 URLs in `resultJson.resultUrls`                                                                                                |

## Endpoint and authentication

Base URL:

```text theme={null}
https://api.apixo.ai/api/v1
```

| Method | Endpoint                                | Purpose                               |
| ------ | --------------------------------------- | ------------------------------------- |
| `POST` | `/generateTask/kling-2-1`               | Submit a generation task              |
| `GET`  | `/statusTask/kling-2-1?taskId={taskId}` | Poll task status and retrieve results |

All requests require your APIXO API key:

```http theme={null}
Authorization: Bearer YOUR_API_KEY
```

Submit requests also require:

```http theme={null}
Content-Type: application/json
```

## Copy-paste async quickstart

This minimal request submits a standard image-to-video task and returns a `taskId`.

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/kling-2-1" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "async",
    "input": {
      "mode": "standard-image-to-video",
      "prompt": "animate this still life scene with subtle camera movement",
      "duration": 5,
      "image_urls": [
        "https://example.com/source.jpg"
      ]
    }
  }'
```

Successful response:

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678"
  }
}
```

Save the `taskId`; you need it to poll for the final result.

## Poll for result

```bash theme={null}
curl -X GET "https://api.apixo.ai/api/v1/statusTask/kling-2-1?taskId=task_12345678" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

Processing response:

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "processing",
    "createTime": 1767965610929
  }
}
```

Success response:

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "success",
    "resultJson": "{\"resultUrls\":[\"https://file.apixo.ai/xxx.mp4\"]}",
    "createTime": 1767965610929,
    "completeTime": 1767965710132,
    "costTime": 99203
  }
}
```

Failed response:

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "failed",
    "failCode": "SensitiveContent",
    "failMsg": "Content violates upstream policy, please adjust the prompt",
    "createTime": 1767965610929,
    "completeTime": 1767965620132,
    "costTime": 9203
  }
}
```

Parse `resultJson` after `state` becomes `success`:

```javascript theme={null}
const payload = JSON.parse(data.resultJson);
const videoUrls = payload.resultUrls;
```

## Request body

### Standard image-to-video

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "standard-image-to-video",
    "prompt": "animate this still life scene with subtle camera movement",
    "duration": 5,
    "image_urls": [
      "https://example.com/source.jpg"
    ],
    "negative_prompt": "blur, low quality",
    "cfg_scale": 0.6
  }
}
```

### Pro image-to-video

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "pro-image-to-video",
    "prompt": "city skyline timelapse from day to night",
    "duration": 10,
    "image_urls": [
      "https://example.com/start.jpg",
      "https://example.com/end.jpg"
    ],
    "cfg_scale": 0.4
  }
}
```

### Master text-to-video

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "master-text-to-video",
    "prompt": "a futuristic drone flying through neon-lit streets at night",
    "duration": 5,
    "aspect_ratio": "9:16",
    "negative_prompt": "grainy, noisy, static",
    "cfg_scale": 0.3
  }
}
```

### Master image-to-video

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "master-image-to-video",
    "prompt": "turn this product photo into a premium cinematic reveal",
    "duration": 5,
    "image_urls": [
      "https://example.com/product.jpg"
    ]
  }
}
```

## Parameters

<ParamField body="request_type" type="string" default="async">
  Result delivery mode. Use `async` for polling with `statusTask`, or `callback` for webhook delivery.
</ParamField>

<ParamField body="callback_url" type="string">
  Required when `request_type` is `callback`. Must be a public HTTPS URL that can receive the final task payload. See [Webhooks](/api-reference/webhooks).
</ParamField>

<ParamField body="input" type="object" required>
  Kling 2.1 input parameters.

  <Expandable title="properties">
    <ParamField body="mode" type="string" required>
      Generation mode. Supported values: `standard-image-to-video`, `pro-image-to-video`, `master-text-to-video`, `master-image-to-video`.
    </ParamField>

    <ParamField body="prompt" type="string" required>
      Text prompt describing the video. Must be a non-empty string with 1-5000 characters.
    </ParamField>

    <ParamField body="duration" type="integer" required>
      Video duration in seconds. Supported values: `5` or `10`.
    </ParamField>

    <ParamField body="image_urls" type="string[]">
      Reference image URLs. Do not send this field for `master-text-to-video`. Send exactly 1 URL for `standard-image-to-video` and `master-image-to-video`. Send 1-2 URLs for `pro-image-to-video`; the second URL is accepted as an end-frame reference on routes that support tail-frame continuity.
    </ParamField>

    <ParamField body="aspect_ratio" type="string" default="16:9">
      Output aspect ratio for `master-text-to-video`. Supported values: `16:9`, `9:16`, `1:1`. If omitted in `master-text-to-video`, the backend sends `16:9`. Image-to-video modes do not forward this field.
    </ParamField>

    <ParamField body="negative_prompt" type="string">
      Negative prompt for unwanted visual elements. Maximum length is 500 characters. Blank values are not forwarded.
    </ParamField>

    <ParamField body="cfg_scale" type="number">
      Prompt guidance scale. Supported range is `0` to `1` with step `0.1`. Recommended range: `0.3`-`0.7`.
    </ParamField>
  </Expandable>
</ParamField>

## Response format

### Submit task response

`POST /generateTask/kling-2-1` returns a task ID when the task is accepted:

<ResponseField name="code" type="integer">
  API status code. `200` means the task was accepted.
</ResponseField>

<ResponseField name="message" type="string">
  Human-readable status message.
</ResponseField>

<ResponseField name="data.taskId" type="string">
  Unique task identifier used with the status endpoint.
</ResponseField>

### Status response fields

<ResponseField name="taskId" type="string">
  Unique task identifier.
</ResponseField>

<ResponseField name="state" type="string">
  Current task state: `pending`, `processing`, `success`, or `failed`.
</ResponseField>

<ResponseField name="resultJson" type="string">
  JSON string containing the generated video URLs. Present when `state` is `success`.
</ResponseField>

<ResponseField name="failCode" type="string">
  Machine-readable failure code. Present when `state` is `failed`.
</ResponseField>

<ResponseField name="failMsg" type="string">
  Human-readable failure message. Present when `state` is `failed`.
</ResponseField>

<ResponseField name="createTime" type="integer">
  Task creation timestamp in Unix milliseconds.
</ResponseField>

<ResponseField name="completeTime" type="integer">
  Task completion timestamp in Unix milliseconds. Present after completion.
</ResponseField>

<ResponseField name="costTime" type="integer">
  Processing duration in milliseconds. Present after successful completion and often present after failure.
</ResponseField>

## Webhook callback mode

Use callback mode when your backend should receive the final result automatically instead of polling.

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/kling-2-1" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "callback",
    "callback_url": "https://your-server.com/webhooks/apixo",
    "input": {
      "mode": "master-text-to-video",
      "prompt": "a futuristic drone flying through neon-lit streets at night",
      "duration": 5,
      "aspect_ratio": "16:9"
    }
  }'
```

The callback payload uses the same unified response format as the status endpoint. See [Webhooks](/api-reference/webhooks) for delivery requirements and retry behavior.

## Billing

Kling 2.1 is billed per generated video. The selected `mode` determines the tier, and `duration` determines the unit price.

| Mode                      | Tier     | 5 seconds       | 10 seconds      |
| ------------------------- | -------- | --------------- | --------------- |
| `standard-image-to-video` | Standard | `$0.20 / video` | `$0.40 / video` |
| `pro-image-to-video`      | Pro      | `$0.35 / video` | `$0.70 / video` |
| `master-text-to-video`    | Master   | `$1.00 / video` | `$2.00 / video` |
| `master-image-to-video`   | Master   | `$1.00 / video` | `$2.00 / video` |

For current route and market comparison pricing, see [Pricing](https://apixo.ai/pricing).

## Latency and polling

Actual latency may vary by prompt complexity, selected tier, input image size, route, and current queue load.

| Duration     | Typical generation time | Recommended first poll  | Poll interval |
| ------------ | ----------------------- | ----------------------- | ------------- |
| `5` seconds  | 60s-90s                 | 60s after task creation | 5s-10s        |
| `10` seconds | 90s-120s                | 60s after task creation | 5s-10s        |

<Tip>
  For production video workloads, use callback mode to avoid frequent polling. Result URLs are stored through APIXO and are generally available for 15 days, so download important outputs promptly.
</Tip>

Rate limits and concurrency can vary by account, API key, and route. If you receive `429`, slow down requests and retry with backoff. For account-level details, see [System APIs](/api-reference/system).

## Errors and troubleshooting

### HTTP errors

| Code  | Meaning                                                                           | What to do                                       |
| ----- | --------------------------------------------------------------------------------- | ------------------------------------------------ |
| `400` | Invalid request body, missing required field, unsupported mode, or rejected input | Fix the request before retrying                  |
| `401` | Missing or invalid API key                                                        | Check the `Authorization` header                 |
| `402` | Insufficient balance or quota                                                     | Add balance or switch account/key                |
| `403` | Key or route cannot access the model                                              | Check permissions and routing settings           |
| `429` | Rate limit or concurrency limit reached                                           | Retry with exponential backoff                   |
| `500` | Server error                                                                      | Retry with backoff                               |
| `502` | Upstream service error                                                            | Retry with backoff                               |
| `504` | Upstream timeout                                                                  | Retry or use callback mode for long-running jobs |

### Task failure codes

Exact `failCode` values can vary because upstream errors are normalized before they are returned.

| Fail code                                                                | Meaning                                                                                                    | What to do                                                                                   |
| ------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| `Missing required parameter`                                             | A required field such as `input`, `mode`, `prompt`, `duration`, `image_urls`, or `callback_url` is missing | Add the missing field                                                                        |
| `Invalid parameter type`                                                 | A field has the wrong JSON type                                                                            | Check `prompt`, `duration`, `image_urls`, `aspect_ratio`, `negative_prompt`, and `cfg_scale` |
| `Invalid parameter value`                                                | A field has an unsupported value                                                                           | Check `mode`, `duration`, `aspect_ratio`, and `cfg_scale`                                    |
| `Param length exceeded`                                                  | Prompt, negative prompt, or image count exceeds the backend limit                                          | Shorten text or reduce image count                                                           |
| `ImageNotAccess`                                                         | An input image URL could not be fetched                                                                    | Use a public, direct HTTP(S) image URL                                                       |
| `SensitiveContent`, `PromptInvalid`, `ProhibitedContentDetected`, `NSFW` | Prompt, input image, or output failed safety checks                                                        | Change the prompt or image                                                                   |
| `RateLimited`                                                            | Upstream rate limit was reached                                                                            | Retry with backoff                                                                           |
| `Timeout`                                                                | Upstream service timed out                                                                                 | Retry, reduce input complexity, or use callback mode                                         |
| `Unknown error`                                                          | Upstream service returned an unmapped error                                                                | Retry with backoff or contact support with the `taskId`                                      |

### Common request issues

| Symptom                            | Likely cause                                                | Fix                                                                                                     |
| ---------------------------------- | ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| `mode` is rejected                 | The mode is missing or not one of the four supported values | Use `standard-image-to-video`, `pro-image-to-video`, `master-text-to-video`, or `master-image-to-video` |
| Text-to-video rejects `image_urls` | `master-text-to-video` does not allow reference images      | Remove `image_urls`                                                                                     |
| Image-to-video rejects the request | Required image is missing or too many images were sent      | Send exactly 1 image for standard/master image modes, or 1-2 images for pro mode                        |
| `aspect_ratio` appears ignored     | The field only applies to `master-text-to-video`            | Use `master-text-to-video` when aspect ratio control is required                                        |
| Image URL fails before generation  | The backend validates public URL reachability               | Use a direct, reachable HTTP(S) URL and avoid private or localhost links                                |

See [Error Codes](/api-reference/errors) for the full error reference.

## Related links

* [Generation API Overview](/models)
* [Generate Task](/api-reference/generate-task)
* [Status Task](/api-reference/status-task)
* [Webhooks](/api-reference/webhooks)
* [Error Codes](/api-reference/errors)
* [Parameter Specification](/api-reference/parameters)
* [Routing Strategies](/concepts/routing-strategies)
* [Pricing](https://apixo.ai/pricing)
