سريع البدء
هذا الممر يخلق أدنى شرح الفيديو. ويستند URL القاعدة الإنتاجية إلى:
https://api.kpainter.ai/openapi/v1
1- إعداد مفتاح API
قم بتنشيط ونسخ مفتاحك من 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 ـ التقدم
إن الإعداد والتحرير غير متزامن. الحفاظ على معرف الإبداع الذي تم إرجاعه وسؤال نفس النتيجة.
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 - قراءة النتائج
اقرأ النتائج فقط عندما يكون الوضع جاهزًا أو يكون_usable_delivery صحيحًا:
outputs = requests.get( f"{BASE_URL}/creations/{creation_id}/outputs", headers=HEADERS, timeout=30,)outputs.raise_for_status()print(outputs.json()["outputs"])
معالجة أعادت URLs كمسؤولية. لا تقم بإنشاء مسارات التخزين.
إضافة ملفات المصدر
قم بتحميل كل مصدر باستخدام POST /file ، ثم تضيف file_id في input_file_ids. جميع المنتجات الثلاثة تقبل الملفات التي تم تحميلها. انظر إنشاء واسترداد من أجل مثال.
