การเริ่มต้นอย่างรวดเร็ว
การเดินนี้สร้างวิดีโออธิบายขั้นต่ํา ฐานการผลิต URL คือ:
https://api.kpainter.ai/openapi/v1
1. การเตรียม API Key
เปิดใช้งานและคัดลอกคีย์ของคุณจาก หน้าหลัก API, จากนั้นเก็บไว้ในสภาพแวดล้อมด้านเซิร์ฟเวอร์ที่เปลี่ยนแปลง อย่าส่งมันในรหัสเบราว์เซอร์หรือบันทึก
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. ตรวจสอบบัญชี
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. อ่านความสามารถปัจจุบัน
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"])
เลือกระยะเวลาเสียงรูปแบบและรูปแบบการแสดงออกจากคําตอบนี้ อย่าใช้ค่าตัวอย่างเป็นการกําหนดค่าที่คงที่
4. สร้างเนื้อหา
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. ปลั๊กขั้นสูง
การสร้างและการแก้ไขเป็นแบบไม่ซิงโครน รักษา 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. อ่านผลลัพธ์
อ่านผลลัพธ์เฉพาะเมื่อสถานะพร้อมหรือ has_usable_delivery เป็นจริง:
outputs = requests.get( f"{BASE_URL}/creations/{creation_id}/outputs", headers=HEADERS, timeout=30,)outputs.raise_for_status()print(outputs.json()["outputs"])
การรักษาได้ส่ง URL เป็นที่รับอนุญาต อย่าสร้างเส้นทางจัดเก็บ
เพิ่มไฟล์แหล่งข้อมูล
ดาวน์โหลดแต่ละแหล่งข้อมูลด้วย POST /file แล้วรวมไฟล์_id ใน input_file_ids ทั้งหมด 3 ผลิตภัณฑ์ยอมรับไฟล์ที่อัปโหลด ดู สร้างและรับ สําหรับตัวอย่าง
