واجهة API المفتوحة
واجهة REST API لإنشاء مهام توليد الصور / الفيديو. قم بالمصادقة باستخدام مفتاح sk- من صفحة حسابك.
إدارة مفاتيح APIالمصادقة
جميع الطلبات تتطلب رمز حامل. أنشئ واحداً من صفحة حسابك.
Authorization: Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxالنماذج المتاحة
قيم model_id أدناه هي الوحيدة المقبولة من واجهة API المفتوحة.
| model_id | القدرة | الناتج |
|---|---|---|
seedance-2 | Seedance 2.0 (text / image to video) | video_url |
gpt-image-2 | ChatGPT Image 2 (text / image to image) | image_url |
nano-banana-2 | Nano Banana 2 (text / image to image) | image_url |
إنشاء مهمة
قدّم طلب توليد. ستتلقى task_id يمكنك متابعته.
POST
/api/v1/tasks/createجسم الطلب
{
"model_id": "gpt-image-2",
"prompt": "a serene zen garden at sunrise, ultra detailed",
"image_urls": [],
"aspect_ratio": "16:9"
}مثال cURL
curl -X POST https://your-site.com/api/v1/tasks/create \
-H "Authorization: Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model_id": "gpt-image-2",
"prompt": "a serene zen garden at sunrise",
"aspect_ratio": "16:9"
}'الاستجابة
{
"code": 200,
"msg": "提交成功,等待生成",
"data": {
"task_id": "abcdef123456",
"request_id": "kie_xxxxxxxxxxxx",
"credits": 15
}
}يتم خصم الرصيد عند الإرسال. المهام الفاشلة يتم استردادها تلقائياً.
استعلام عن مهمة
استعلم عن المهمة بواسطة المعرف حتى يصل task_status إلى 3 (نجاح) أو 4 (فشل).
GET
/api/v1/tasks/{task_id}مثال cURL
curl https://your-site.com/api/v1/tasks/abcdef123456 \
-H "Authorization: Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"الاستجابة
{
"code": 200,
"msg": "ok",
"data": {
"task_id": "abcdef123456",
"task_status": 3,
"task_type": "image",
"model_id": "gpt-image-2",
"image_url": "https://your-cdn.com/...",
"video_url": null,
"audio_url": null,
"credits": 15,
"created_at": 1730000000
}
}task_status: 1 في الانتظار، 2 قيد التنفيذ، 3 نجاح، 4 فشل.
الأخطاء
code: 200— نجاحcode: 0— فشل في العمل (راجع حقل msg للتفاصيل)HTTP 401— مفتاح API غير صالح أو مفقود