概覽/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。三種產品都支持附件。完整示例見 創建與查詢

下一步