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"
import requests BASE_URL = "https://api.kpainter.ai/openapi/v1"HEADERS = { "Authorization": "Bearer <your_api_key>",}
2) Kiểm tra tài khoản
curl -s "$KPAINTER_BASE_URL/me" \ -H "Authorization: Bearer $KPAINTER_API_KEY"
me = requests.get(f"{BASE_URL}/me", headers=HEADERS, timeout=30)me.raise_for_status()print(me.json())
3. đọc kỹ năng hiện tại
curl -s "$KPAINTER_BASE_URL/capabilities" \ -H "Authorization: Bearer $KPAINTER_API_KEY"
capabilities = requests.get( f"{BASE_URL}/capabilities", headers=HEADERS, timeout=30,).json()print(capabilities["products"])
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" } }'
payload = { "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", },}response = requests.post( f"{BASE_URL}/creations", headers=HEADERS, json=payload, timeout=30,)response.raise_for_status()creation_id = response.json()["id"]
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ụ.
