Schnellstart
Dieser Spaziergang schafft ein minimales Explainer Video. Die Produktionsbasis URL ist:
https://api.kpainter.ai/openapi/v1
1. Bereiten Sie einen API-Schlüssel vor
Aktivieren und kopieren Sie Ihren Schlüssel aus dem API Key Seite, dann halten Sie es in einem Server-Side-Umfeld variabel. Senden Sie es niemals in Browser-Code oder Logs.
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. Überprüfen Sie das Konto
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. Lesen Sie aktuelle Fähigkeiten
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"])
Wählen Sie Dauer, Stimme, Template und Ausdruckstil aus dieser Antwort aus. Betrachten Sie nicht Beispielewerte als dauerhafte Konfiguration.
4. Erstellen von Content
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. Poll Fortschritt
Erstellung und Bearbeitung sind asynchronisch. Halten Sie das zurückgegebene Creation ID und überprüfen Sie das gleiche Ergebnis.
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. Lesen Sie die Ergebnisse
Lesen Sie Ausgänge nur dann, wenn der Status bereit ist oder hat_usable_delivery wahr ist:
outputs = requests.get( f"{BASE_URL}/creations/{creation_id}/outputs", headers=HEADERS, timeout=30,)outputs.raise_for_status()print(outputs.json()["outputs"])
Die URLs wurden als autorisativ zurückgegeben. Konstruieren Sie keine Speicherwege.
Quelldateien hinzufügen
Laden Sie jede Quelle mit POST /Dateien hoch und fügen Sie dann ihre Datei_ID in input_file_ids ein. Alle drei Produkte akzeptieren hochgeladenen Dateien. Sehen Sie Erstellen und abrufen Für ein Beispiel.
