跳转到主要内容

接口

MethodEndpointDescription
POST/api/v1/generateTask/kling-2-1创建生成任务
GET/api/v1/statusTask/kling-2-1查询任务状态

认证

所有请求需在请求头中携带 API 密钥:
Authorization: Bearer YOUR_API_KEY

请求体

{
  "request_type": "async",
  "callback_url": "https://...",
  "provider": "auto",
  "input": {
    "mode": "standard-image-to-video",
    "prompt": "...",
    "duration": 5,
    "image_urls": ["..."],
    "aspect_ratio": "16:9",
    "negative_prompt": "...",
    "cfg_scale": 0.5
  }
}

参数

request_type
string
默认值:"async"
async(轮询)或 callback(webhook)
callback_url
string
回调 URL,当 request_type=callback 时必填(条件必填)
provider
string
默认值:"auto"
路由策略:auto、value 或 official
input
object
必填
模型输入参数
模式选项:
  • standard-image-to-video — Standard 级图生视频,需 1 张图
  • pro-image-to-video — Pro 级图生视频,支持 1-2 张(尾帧)
  • master-text-to-video — Master 级文生视频
  • master-image-to-video — Master 级图生视频,需 1 张图

示例

Standard 图生视频
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",
    "provider": "value",
    "input": {
      "mode": "standard-image-to-video",
      "prompt": "animate this still life scene with subtle camera movement",
      "duration": 5,
      "image_urls": ["https://example.com/std_ref.jpg"],
      "negative_prompt": "blur, low quality",
      "cfg_scale": 0.6
    }
  }'
Pro 图生视频(含尾帧)
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/callback",
    "provider": "official",
    "input": {
      "mode": "pro-image-to-video",
      "prompt": "city skyline timelapse from day to night",
      "duration": 10,
      "image_urls": [
        "https://example.com/pro_start.jpg",
        "https://example.com/pro_end.jpg"
      ],
      "cfg_scale": 0.4
    }
  }'
Master 文生视频
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": "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
    }
  }'

响应

POST /api/v1/generateTask/kling-2-1

成功时返回 taskId,用于后续查询状态。 成功:
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678"
  }
}
错误:
{
  "code": 400,
  "message": "Insufficient credits",
  "data": null
}

GET /api/v1/statusTask/kling-2-1

通过 taskId 查询任务执行状态与结果。
curl -X GET "https://api.apixo.ai/api/v1/statusTask/kling-2-1?taskId=task_12345678" \
  -H "Authorization: Bearer YOUR_API_KEY"
成功:
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "success",
    "resultJson": "{\"resultUrls\":[\"https://r2.apixo.ai/video.mp4\"]}",
    "createTime": 1767965610929,
    "completeTime": 1767965652317,
    "costTime": 41388
  }
}
失败:
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "failed",
    "failCode": "CONTENT_VIOLATION",
    "failMsg": "Content does not meet safety guidelines"
  }
}

状态响应字段

taskId
string
任务唯一标识。
state
string
当前任务状态:pendingprocessingsuccessfailed
resultJson
string
包含 resultUrls 数组的 JSON 字符串。仅在成功时存在。使用 JSON.parse() 解析。
failCode
string
错误码。仅当 statefailed 时存在。详见错误码
failMsg
string
可读的错误信息。仅当 statefailed 时存在。
createTime
integer
任务创建时间戳(Unix 毫秒)。
completeTime
integer
任务完成时间戳(Unix 毫秒)。
costTime
integer
处理耗时(毫秒)。

错误码

CodeDescription
400参数无效或请求错误
401API 密钥无效或缺失
429超过速率限制
Fail CodeDescription
CONTENT_VIOLATION内容违反安全准则
INVALID_IMAGE_URL无法访问提供的图片 URL

速率限制

LimitValue
Requests10000 / minute
Concurrent tasks1000
超出限制返回 429 错误。请稍后重试。

提示

  • 生成时间
    • 5 秒视频:约 60-90 秒
    • 10 秒视频:约 90-120 秒
    • 提交任务后等待 60 秒,再每隔 5 秒轮询
  • 回调模式:视频生成耗时,强烈建议使用 callback 模式。
  • 视频有效期:结果 URL 有效期为 15 天。请及时下载。
  • 内容审核:prompt 需符合内容安全准则。
  • 层级选择
    • standard:性价比高,适合批量
    • pro:支持首尾帧控制,适合精确创作
    • master:质量最高,适合专业生产
  • 尾帧功能pro 模式支持 2 张图,第一张为起始帧,第二张为结束帧。
  • 负面 prompt:用 negative_prompt 排除不想要的元素。
  • CFG Scale
    • 值越高:越严格遵循 prompt,创意可能减少
    • 值越低:越有创意,可能偏离 prompt
    • 建议:0.3-0.7
  • 图片格式image_urls 支持 JPG、PNG、WebP,单张最大 10MB。

视频生成比图像耗时更长 — 生产环境请使用 callback 模式。结果 URL 15 天后失效,请及时下载重要输出。

相关