Tổng quan/OpenAPI/QuickStart khởi động

QuickStart khởi động

Xác thực, tạo ra một sáng tạo đầu tiên, và lấy lại kết quả của nó.

QuickStart khởi động

Đi bộ này tạo ra một Video Explainer tối thiểu. Cơ sở sản xuất URL là:

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

1.Cung cấp một API Key

Tạo và sao chép khóa của bạn từ API Trang chủ, sau đó giữ nó trong một môi trường thay đổi bên máy chủ. Đừng bao giờ gửi nó trong mã trình duyệt hoặc sổ ghi chép.

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

2) Kiểm tra tài khoản

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

3. đọc kỹ năng hiện tại

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

Chọn thời gian, giọng nói, mẫu và phong cách biểu hiện từ câu trả lời này. Đừng coi các giá trị ví dụ như cấu hình vĩnh viễn.

4. tạo nội dung

curl -s "$KPAINTER_BASE_URL/creations" \  -H "Authorization: Bearer $KPAINTER_API_KEY" \  -H "Content-Type: application/json" \  -d '{    "type": "video",    "prompt": "Explain the customer escalation process to new employees",    "instructions": "Use a concise professional tone and preserve source terminology",    "max_credits": 300,    "video": {      "duration_seconds": 120,      "aspect_ratio": "16:9",      "language": "en"    }  }'

5 – tiến bộ

Tạo và chỉnh sửa là không đồng bộ. Giữ ID tạo trở lại và khảo sát cùng một kết quả.

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/ Đọc kết quả

Đọc outputs chỉ khi trạng thái đã sẵn sàng hoặc has_usable_delivery là đúng:

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

Trình xử lý trả về URL như là ủy quyền. Đừng xây dựng đường lưu trữ.

Thêm nguồn file

Tải lên mỗi nguồn với POST /file, sau đó bao gồm file_id của nó trong input_file_ids. Tất cả 3 sản phẩm chấp nhận các tập tin được tải lên. xem Tạo và thu hồi cho một ví dụ.