> ## 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 API：Standard、Pro 和 Master 视频模式

> 快手 Kling 2.1 视频生成 API，适用于标准、专业和主视频工作流程

## 概览

Kling 2.1 是快手的视频模型，提供多个质量档位，支持图生视频，也支持以 Master 画质进行文生视频。在 APIXO Playground 试用后，可以按本页示例调用 API。

| 功能 | 值 |
| - | - |
| 模型 ID | `kling-2-1` |
| 模式 | `standard-image-to-video`, `pro-image-to-video`, `master-text-to-video`, `master-image-to-video` |
| 提示词长度 | 1 至 5000 个字符 |
| 时长 | `5` 或 `10` 秒 |
| 参考图片 | `master-text-to-video` 无限制；`standard-image-to-video` 和 `master-image-to-video` 为 1；`pro-image-to-video` 为 1-2 |
| 纵横比 | 仅适用于 `master-text-to-video`：`16:9`、`9:16`、`1:1` |
| 输出格式 | MP4 视频的 URL 位于 `resultJson.resultUrls` 中 |

## 接口与身份验证

API 基础地址：

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

| 方法 | 端点 | 用途 |
| - | - | - |
| `POST` | `/generateTask/kling-2-1` | 提交生成任务 |
| `GET` | `/statusTask/kling-2-1?taskId={taskId}` | 查询任务状态并获取结果 |

每个请求都必须携带 APIXO API 密钥：

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

提交任务时，还需要设置以下请求头：

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

## 异步请求示例

此最小请求提交标准图生视频任务并返回 `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"
      ]
    }
  }'
```

成功响应：

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

保存 `taskId`，后续轮询结果时需要用到它。

## 轮询结果

```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"
```

任务处理中的响应示例：

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

成功响应：

```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
  }
}
```

任务失败时的响应示例：

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

等 `state` 变为 `success` 后，再解析 `resultJson`：

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

## 请求体

### 标准图生视频

```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
  }
}
```

### 专业图像转视频

```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
  }
}
```

### 母版文本转视频

```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
  }
}
```

### 母版图生视频

```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"
    ]
  }
}
```

## 参数

**request\_type** `string` (default: async)

结果获取方式。选择 `async` 时，通过 `statusTask` 轮询结果；选择 `callback` 时，通过 Webhook 接收结果。

**callback\_url** `string`

当 `request_type` 为 `callback` 时必填。请提供公网可访问的 HTTPS 地址，用于接收任务的最终结果。详见 [Webhook](https://apixo.ai/docs/zh/api-reference/webhooks.md)。

**input** `object` *required*

Kling 2.1 的输入参数。

**属性**

**mode** `string` *required*

生成模式。可选值为 `standard-image-to-video`、`pro-image-to-video`、`master-text-to-video`、`master-image-to-video`。

**prompt** `string` *required*

描述视频的文字提示。必须是非空字符串，长度为 1-5000 个字符。

**duration** `integer` *required*

视频时长（以秒为单位）。支持的值：`5` 或 `10`。

**image\_urls** `string[]`

参考图像 URL。对于 `master-text-to-video` 不需要发送此字段。对于 `standard-image-to-video` 和 `master-image-to-video`，需精确发送 1 个 URL。对于 `pro-image-to-video`，可发送 1-2 个 URL；第二个 URL 作为支持尾帧连续性的路由中的结束帧参考。每个图像必须为 JPG、JPEG 或 PNG 格式，大小不超过 10 MB，且每边分辨率至少为 300 像素。

**aspect\_ratio** `string` (default: 16:9)

`master-text-to-video` 的输出纵横比。支持的值：`16:9`、`9:16`、`1:1`。若在 `master-text-to-video` 中未指定，则后端默认返回 `16:9`。图生视频模式不会转发此字段。

**negative\_prompt** `string`

对不需要的视觉元素进行负面提示。最大长度为 500 个字符。空值将不会被转发。

**cfg\_scale** `number`

提示引导强度。支持范围为 `0` 至 `1`，步长为 `0.1`。推荐范围为 `0.3` 至 `0.7`。

## 响应格式

### 提交任务时的响应

任务受理后，`POST /generateTask/kling-2-1` 会返回任务 ID：

**code** `integer`

API 状态码。`200` 表示任务已受理。

**message** `string`

状态说明。

**data.taskId** `string`

任务的唯一 ID，用于查询任务状态。

### 状态响应字段

**taskId** `string`

任务的唯一标识符。

**state** `string`

当前任务状态，可能的值为 `pending`、`processing`、`success`、`failed`。

**resultJson** `string`

包含生成视频 URL 的 JSON 字符串。当 `state` 为 `success` 时返回。

**failCode** `string`

供程序处理的错误码，仅在 `state` 为 `failed` 时返回。

**failMsg** `string`

失败原因说明，仅在 `state` 为 `failed` 时返回。

**createTime** `integer`

任务创建时的 Unix 时间戳，单位为毫秒。

**completeTime** `integer`

任务完成时的 Unix 时间戳，单位为毫秒。任务完成后返回。

**costTime** `integer`

处理持续时间（以毫秒为单位）。成功完成后出现，且经常在失败后出现。

## Webhook 回调模式

如果希望服务端自动收到最终结果，可以使用回调模式，无需轮询。

```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"
    }
  }'
```

回调有效负载使用与状态端点相同的统一响应格式。请参阅 [Webhooks](https://apixo.ai/docs/zh/api-reference/webhooks.md) 了解传送要求和重试行为。

## 计费

新提交的非 LLM 请求按 **1 积分 = `$0.001`** 计费。先按用量和附加项目计算总额，再应用账号折扣，最后将请求总额向上取整到整数积分。如果约定了固定单价，则按该单价的原始精度计算，不再使用标准价或另行打折；最终积分仍向上取整。详见[积分换算与取整](https://apixo.ai/docs/zh/pricing.md#credit-conversion-and-rounding)。

Kling 2.1 按生成的视频计费。所选的`mode`决定等级，`duration`决定单价。

| 模式 | 等级 | 5秒 | 10秒 |
| - | - | - | - |
| `standard-image-to-video` | Standard | `$0.20 / video` | `$0.40 / video` |
| `pro-image-to-video` | 专业版 | `$0.35 / video` | `$0.70 / video` |
| `master-text-to-video` | 高级版 | `$1.00 / video` | `$2.00 / video` |
| `master-image-to-video` | 高级版 | `$1.00 / video` | `$2.00 / video` |

最新的美元费率见 [API 价目表](https://apixo.ai/pricing/api)。

## 延迟与轮询

实际延迟可能因提示复杂性、所选层级、输入图像大小、路由和当前队列负载而异。

| 时长 | 通常生成耗时 | 建议首次查询时间 | 轮询间隔 |
| - | - | - | - |
| `5`秒 | 60s-90s | 任务创建 60 秒后 | 5s-10s |
| `10`秒 | 90s-120s | 任务创建 60 秒后 | 5s-10s |

> [!TIP]
>
> 对于生产视频工作负载，请使用回调模式以避免频繁轮询。结果 URL 通过 APIXO 存储，通常可用 15 天，因此请立即下载重要输出。

请求频率和并发上限因账号、API 密钥和路由而异。收到 `429` 时，请降低请求频率，逐步延长重试间隔。账号级限制见[系统 API](https://apixo.ai/docs/zh/api-reference/system.md)。

## 错误与排查

### HTTP 错误

| 代码 | 含义 | 处理方式 |
| - | - | - |
| `400` | 请求体无效、缺少必填字段、模式不受支持或输入被拒绝 | 在重试前修复请求 |
| `401` | 缺少 API 密钥，或密钥无效 | 检查 `Authorization` 请求头 |
| `402` | 余额或配额不足 | 充值或更换账号或API密钥 |
| `403` | 密钥或路由无权访问该模型 | 检查权限和路由设置 |
| `429` | 已达到速率或并发限制 | 按指数退避策略重试 |
| `500` | 服务器错误 | 逐步延长间隔后重试 |
| `502` | 服务错误 | 逐步延长间隔后重试 |
| `504` | 服务超时 | 重试；耗时较长的任务可改用回调模式 |

### 任务失败错误码

`failCode` 标识任务失败。确切的值可能因故障而异。

| 错误码 | 含义 | 处理方式 |
| - | - | - |
| `Missing required parameter` | 缺少 `input`、`mode`、`prompt`、`duration`、`image_urls` 或 `callback_url` 等必填字段 | 添加缺失的字段 |
| `Invalid parameter type` | 字段的 JSON 类型错误 | 检查`prompt`、`duration`、`image_urls`、`aspect_ratio`、`negative_prompt`和`cfg_scale` |
| `Invalid parameter value` | 字段具有不受支持的值 | 检查`mode`、`duration`、`aspect_ratio`和`cfg_scale` |
| `Param length exceeded` | 提示、负提示或图片数量超出后端限制 | 缩短文本或减少图像数量 |
| `ImageNotAccess` | 无法获取输入图像 URL | 使用公开的直接 HTTP(S) 图像 URL |
| `SensitiveContent`, `PromptInvalid`, `ProhibitedContentDetected`, `NSFW` | 提示、输入图像或输出未通过安全检查 | 更改提示或图像 |
| `RateLimited` | 请求频率达到上限 | 逐步延长间隔后重试 |
| `Timeout` | 任务超时 | 重试、降低输入复杂度或使用回调模式 |
| `Unknown error` | 任务因未知原因失败 | 逐步延长间隔后重试，或联系支持团队并提供 `taskId` |

### 常见请求问题

| 问题表现 | 可能的原因 | 解决办法 |
| - | - | - |
| `mode` 被拒绝 | 该模式缺失或不是四个支持值之一 | 使用`standard-image-to-video`、`pro-image-to-video`、`master-text-to-video`或`master-image-to-video` |
| 文本转视频拒绝 `image_urls` | `master-text-to-video` 不允许参考图像 | 删除`image_urls` |
| 图像转视频拒绝请求 | 缺少所需的图像或发送的图像过多 | 标准/主图像模式精确发送 1 图像，专业模式精确发送 1-2 图像 |
| `aspect_ratio` 似乎被忽略 | 该字段仅适用于`master-text-to-video` | 当需要控制纵横比时使用`master-text-to-video` |
| 图像 URL 在生成之前失败 | 后端验证公共 URL 可达性 | 使用直接、可访问的 HTTP(S) URL 并避免私有或本地主机链接 |

完整列表见[错误码](https://apixo.ai/docs/zh/api-reference/errors.md)。

## MCP 集成

[完整模型 Schema](https://apixo.ai/docs/models/schemas/video/kling-2-1.json) 中的 `mcp.result` 指定了结果的解析方式，`mcp.attachments` 列出支持绑定文件的字段。这些元数据供客户端集成使用，无需作为生成参数提交。附件字段为 `image_urls`。请保留用户指定的文件顺序。API 负责校验模型参数。

## 相关链接

* [生成 API 概览](https://apixo.ai/docs/zh/models.md)
* [视频模型](https://apixo.ai/docs/zh/models/video)
* [提交生成任务](https://apixo.ai/docs/zh/api-reference/generate-task.md)
* [查询任务状态](https://apixo.ai/docs/zh/api-reference/status-task.md)
* [Webhook](https://apixo.ai/docs/zh/api-reference/webhooks.md)
* [错误码](https://apixo.ai/docs/zh/api-reference/errors.md)
* [参数规范](https://apixo.ai/docs/zh/api-reference/parameters.md)
* [路由策略](https://apixo.ai/docs/zh/concepts/routing-strategies.md)
* [在 APIXO Playground 尝试 Kling 2.1](https://apixo.ai/models/kling-2-1)
* [API定价](https://apixo.ai/pricing/api)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.