API dokumentasyon
Tawagan ang lahat ng AI tampok sa pamamagitan ng API key, bayad per paggamit, integrasyon sa ilang linya ng code.
Autentikasyon
Lahat ng API request ay dapat maglaman ng header Authorization.
Authorization: Bearer sk-xxxxxxxxxxxxxxxx
Kunin ang API key sa pahina ng „Mga API Key" sa konsol. Isang key kada account. Reset sa konsol; ang luma ay agad na nawalang bisa.
Gumawa ng gawain
https://nsfwrouter.xyz/api/v1/tasks/create
Magpadala ng AI gawain sa GPU cluster. Ang mga gawain ay async, nagbabalik ng ID. Resulta sa API o Webhook.
| Parameter | Uri | Kinakailangan | Deskripsyon |
|---|---|---|---|
| tool_id | int | Oo | ID ng tool, mula sa listahan ng tool |
| params | object | Oo | Mga parameter ng gawain, JSON object, field ay nakadepende sa tool |
| webhook_url | string | Hindi | Callback URL para sa notification ng pagkumpleto |
| priority | int | Hindi | Prioridad ng gawain 1-10, default 5 |
| idempotency_key | string | Hindi | Idempotency key, pinipigilan ang duplicate |
| execution_options | object | Hindi | Mga opsyon sa pagpapatupad, 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"
}
}
Tinitingnan ang balanse bago tawag. Kulang = error insufficient_coins. Binabawasan ang coins sa matagumpay na pagpapadala.
Query ng gawain
https://nsfwrouter.xyz/api/v1/tasks/query
Query ng detalye at status ayon sa ID. Habang pinoproseso, ang status ay mula sa GPU cluster. Paulit-ulit na query sa loob ng 10 segundo ay nagbabalik ng DB cache.
| Parameter | Uri | Kinakailangan | Deskripsyon |
|---|---|---|---|
| id | int | Oo | ID ng gawain |
{
"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 | Kahulugan |
|---|---|
| 0 | Pinoproseso |
| 1 | Tapos na |
| -1 | Nakansela |
| -2 | Nabigo |
Listahan ng gawain
https://nsfwrouter.xyz/api/v1/tasks
Paginated na query ng mga gawain ng account, na may filter sa tool, status at panahon.
| Parameter | Uri | Kinakailangan | Deskripsyon |
|---|---|---|---|
| page | int | Hindi | Numero ng pahina, default 1 |
| page_size | int | Hindi | Laki ng pahina, default 20, max 50 |
| tool_id | int | Hindi | I-filter ayon sa tool |
| status | int | Hindi | I-filter ayon sa status (0/1/-1/-2) |
| days | int | Hindi | Panahon sa araw, default 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
}
}
| Field | Uri | Deskripsyon |
|---|---|---|
| type | string | Uri ng resulta: image o video |
| url | string | CDN URL para sa resulta file |
| file_name | string | Pangalan ng file |
| file_size | int | Laki ng file (bytes) |
| mime_type | string | MIME type, hal. image/png, video/mp4 |
| width | int | Lapad (pixels) |
| height | int | Taas (pixels) |
Balanse ng account
https://nsfwrouter.xyz/api/v1/account/balance
Suriin ang coin balanse, kabuuang load at kabuuang konsumo.
{
"code": 0,
"message": "success",
"data": {
"remain_coins": 5000,
"total_coins": 10000,
"used_coins": 5000
}
}
Webhook callback
Kung tinukoy ang webhook_url, POST ay ipinapadala sa pagkumpleto, kabiguan o pagkansela. Body ay 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
}
}
Dapat magbalik ng HTTP 2xx ang server mo. Sa non-2xx o timeout (10 sec), sinusubukan ng sistema hanggang 5 beses na may exponential backoff.
Mga error code
Lahat ng error response ay gumagamit ng pormal na format: {"code": code, "message": "identifier", "data": {}}
| Error code | message | Deskripsyon |
|---|---|---|
| 20001 | api_key_required | Hindi ibinigay ang API key |
| 20001 | invalid_api_key | Hindi wastong API key |
| 20001 | ip_not_allowed | IP ay hindi sa whitelist |
| 20001 | permission_denied | Tinanggihan ang access |
| 30001 | tool_not_found | Hindi nahanap ang tool |
| 30001 | task_not_found | Hindi nahanap ang gawain |
| 30001 | insufficient_coins | Hindi sapat na coin balanse |
| 30001 | task_submit_failed | Nabigo ang pagpapadala ng gawain |
| 30001 | task_query_failed | Nabigo ang query ng gawain |
| 30001 | task_already_exists | Mayroon nang gawain (idempotency) |
| 40001 | tool_id_required | Parameter tool_id ay nawawala |
| 40001 | param_error | Error sa parameter |
| 40001 | webhook_url_invalid | Hindi wastong format ng webhook_url |
| 40001 | params_must_be_json_object_or_array | params ay dapat na JSON object o array |
| 40001 | execution_options_must_be_json_object_or_array | execution_options ay dapat na JSON object o array |
| Saklaw | Kategorya |
|---|---|
| 1xxxx | Error sa antas ng sistema |
| 2xxxx | Error sa autentikasyon |
| 3xxxx | Error sa lohika ng negosyo |
| 4xxxx | Error sa parameter |
| 5xxxx | Error sa panlabas na dependency |