תיעוד API
קרא לכל תכונות ה-AI דרך מפתח API, תשלום לפי שימוש, אינטגרציה במספר שורות קוד.
אימות
כל בקשות ה-API חייבות לכלול כותרת Authorization.
Authorization: Bearer sk-xxxxxxxxxxxxxxxx
קבל מפתח API בדף „מפתחות API" בקונסול. מפתח אחד לחשבון. איפוס בקונסול; הישן מבוטל מיידית.
יצירת משימה
https://nsfwrouter.xyz/api/v1/tasks/create
שלח משימת AI לקלאסטר GPU. משימות אסינכרוניות, מחזירות ID. תוצאות דרך API או Webhook.
| פרמטר | סוג | חובה | תיאור |
|---|---|---|---|
| tool_id | int | כן | מזהה כלי, מרשימת הכלים |
| params | object | כן | פרמטרי משימה, JSON object, שדות תלויים בכלי |
| webhook_url | string | לא | URL callback להודעה על השלמה |
| priority | int | לא | עדיפות משימה 1-10, ברירת מחדל 5 |
| idempotency_key | string | לא | מפתח idempotency, מונע כפילויות |
| execution_options | object | לא | אפשרויות ביצוע, JSON object |
curl -X POST https://nsfwrouter.xyz/api/v1/tasks/create \
-H "Authorization: Bearer sk-xxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"tool_id": 1,
"params": {
"image": "https://example.com/photo.jpg",
"prompt": "a beautiful landscape"
},
"webhook_url": "https://your-server.com/webhook"
}'
{
"code": 0,
"message": "success",
"data": {
"task": {
"id": 123,
"status": 0,
"consume_coins": 5
},
"message": "task_submitted"
}
}
יתרה נבדקת לפני קריאה. לא מספיק = שגיאה insufficient_coins. מטבעות מנוכים בשליחה מוצלחת.
שאילתת משימה
https://nsfwrouter.xyz/api/v1/tasks/query
שאל פרטים וסטטוס לפי ID. במהלך עיבוד, הסטטוס מגיע מקלאסטר GPU. שאילתות חוזרות תוך 10 שנ' מחזירות DB cache.
| פרמטר | סוג | חובה | תיאור |
|---|---|---|---|
| id | int | כן | מזהה משימה |
{
"code": 0,
"message": "success",
"data": {
"task": {
"id": 123,
"status": 1,
"task_output_json": [
{
"type": "image",
"url": "https://cdn.example.com/outputs/abc123.png",
"file_name": "abc123.png",
"file_size": 1024000,
"mime_type": "image/png",
"width": 1024,
"height": 1024
}
],
"consume_coins": 5,
"created_at": 1718200000,
"completed_at": 1718200015
}
}
}
| status | משמעות |
|---|---|
| 0 | בעיבוד |
| 1 | הושלם |
| -1 | בוטל |
| -2 | נכשל |
רשימת משימות
https://nsfwrouter.xyz/api/v1/tasks
שאילתה ממוספרת של משימות חשבון, עם מסננים לכלי, סטטוס ותקופה.
| פרמטר | סוג | חובה | תיאור |
|---|---|---|---|
| page | int | לא | מספר עמוד, ברירת מחדל 1 |
| page_size | int | לא | גודל עמוד, ברירת מחדל 20, מקס 50 |
| tool_id | int | לא | סינון לפי כלי |
| status | int | לא | סינון לפי סטטוס (0/1/-1/-2) |
| days | int | לא | תקופה בימים, ברירת מחדל 30 |
{
"code": 0,
"message": "success",
"data": {
"list": [
{
"id": 123,
"tool_id": 1,
"status": 1,
"task_output_json": [
{
"type": "image",
"url": "https://cdn.example.com/outputs/abc123.png",
"file_name": "abc123.png",
"file_size": 1024000,
"mime_type": "image/png",
"width": 1024,
"height": 1024
}
],
"error": null,
"consume_coins": 5,
"created_at": 1718200000,
"completed_at": 1718200015
},
{
"id": 122,
"tool_id": 3,
"status": 0,
"task_output_json": [],
"error": null,
"consume_coins": 10,
"created_at": 1718199000,
"completed_at": 0
}
],
"page": 1,
"page_size": 20
}
}
| שדה | סוג | תיאור |
|---|---|---|
| type | string | סוג תוצאה: image או video |
| url | string | URL CDN לקובץ התוצאה |
| file_name | string | שם קובץ |
| file_size | int | גודל קובץ (בתים) |
| mime_type | string | סוג MIME, לדוגמה image/png, video/mp4 |
| width | int | רוחב (פיקסלים) |
| height | int | גובה (פיקסלים) |
יתרת חשבון
https://nsfwrouter.xyz/api/v1/account/balance
בדוק יתרת מטבעות, סך טעינה וסך צריכה.
{
"code": 0,
"message": "success",
"data": {
"remain_coins": 5000,
"total_coins": 10000,
"used_coins": 5000
}
}
Webhook callback
אם צוין webhook_url, נשלח POST בהשלמה, כישלון או ביטול. Body ב-JSON.
Content-Type: application/json
Accept: application/json
User-Agent: OpenAPI-Webhook/1.0
{
"event": "task.finished",
"task": {
"id": 123,
"status": 1,
"task_output_json": [
{
"type": "image",
"url": "https://cdn.example.com/outputs/abc123.png",
"file_name": "abc123.png",
"file_size": 1024000,
"mime_type": "image/png",
"width": 1024,
"height": 1024
}
],
"consume_coins": 5,
"created_at": 1718200000,
"completed_at": 1718200015
}
}
השרת שלך חייב להחזיר HTTP 2xx. ב-non-2xx או timeout (10 שנ'), המערכת מנסה עד 5 פעמים עם backoff מעריכי.
קודי שגיאה
כל תגובות השגיאה משתמשות בפורמט: {"code": קוד, "message": "identifier", "data": {}}
| קוד שגיאה | message | תיאור |
|---|---|---|
| 20001 | api_key_required | מפתח API לא סופק |
| 20001 | invalid_api_key | מפתח API לא תקין |
| 20001 | ip_not_allowed | IP לא ב-whitelist |
| 20001 | permission_denied | גישה נדחתה |
| 30001 | tool_not_found | כלי לא נמצא |
| 30001 | task_not_found | משימה לא נמצאה |
| 30001 | insufficient_coins | יתרת מטבעות לא מספיקה |
| 30001 | task_submit_failed | שליחת משימה נכשלה |
| 30001 | task_query_failed | שאילתת משימה נכשלה |
| 30001 | task_already_exists | משימה כבר קיימת (idempotency) |
| 40001 | tool_id_required | פרמטר tool_id חסר |
| 40001 | param_error | שגיאת פרמטר |
| 40001 | webhook_url_invalid | פורמט webhook_url לא תקין |
| 40001 | params_must_be_json_object_or_array | params חייב להיות JSON object או array |
| 40001 | execution_options_must_be_json_object_or_array | execution_options חייב להיות JSON object או array |
| טווח | קטגוריה |
|---|---|
| 1xxxx | שגיאת מערכת |
| 2xxxx | שגיאת אימות |
| 3xxxx | שגיאת לוגיקה עסקית |
| 4xxxx | שגיאת פרמטר |
| 5xxxx | שגיאת תלות חיצונית |