概览/OpenAPI/快速开始

快速开始

从鉴权开始,完成第一次创建并取得结果。

快速开始

下面用一个最小解说视频请求演示完整流程。正式环境基础地址为:

https://api.kpainter.ai/openapi/v1

1. 准备 API Key

在 API Key 页面 激活并复制你的 Key,然后保存到服务端环境变量。不要把 Key 放进网页前端或日志。

export KPAINTER_API_KEY="<your_api_key>"export KPAINTER_BASE_URL="https://api.kpainter.ai/openapi/v1"

2. 校验账号

curl -s "$KPAINTER_BASE_URL/me" \  -H "Authorization: Bearer $KPAINTER_API_KEY"

3. 读取当前能力

curl -s "$KPAINTER_BASE_URL/capabilities" \  -H "Authorization: Bearer $KPAINTER_API_KEY"

从返回结果选择视频时长、音色、模板和表达风格。不要把页面示例里的值当成永久配置。

4. 创建内容

curl -s "$KPAINTER_BASE_URL/creations" \  -H "Authorization: Bearer $KPAINTER_API_KEY" \  -H "Content-Type: application/json" \  -d '{    "type": "video",    "prompt": "面向新员工解释一次客户问题升级流程",    "instructions": "使用简洁、专业的表达,保留原有术语",    "max_credits": 300,    "video": {      "duration_seconds": 120,      "aspect_ratio": "16:9",      "language": "zh"    }  }'

5. 查询进度

创建和编辑都是异步任务。保存返回的 creation id,并持续查询同一个结果即可。

import time while True:    response = requests.get(        f"{BASE_URL}/creations/{creation_id}",        headers=HEADERS,        timeout=30,    )    response.raise_for_status()    creation = response.json()     print(        creation["status"],        creation["progress_pct"],        creation.get("estimated_remaining_seconds"),        creation.get("estimated_credits"),    )     if creation["status"] in {"ready", "failed", "paused"}:        break     time.sleep(5)

6. 获取结果

只有 ready 或 has_usable_delivery 为 true 时才读取输出:

outputs = requests.get(    f"{BASE_URL}/creations/{creation_id}/outputs",    headers=HEADERS,    timeout=30,)outputs.raise_for_status()print(outputs.json()["outputs"])

返回的 URL 才是可交付结果。不要自行拼接存储路径。

带附件时

先调用 POST /files 上传文件,取得 file_id,再把它放入 input_file_ids。三种产品都支持附件。完整示例见 创建与查询。

下一步