Dokumentasi API
Panggil semua fitur AI via kunci API, bayar per pakai, integrasi dalam beberapa baris kode.
Autentikasi
Semua permintaan API harus berisi header Authorization.
Authorization: Bearer sk-xxxxxxxxxxxxxxxx
Dapatkan kunci API di halaman „Kunci API" di konsol. Satu kunci per akun. Reset di konsol; yang lama langsung tidak berlaku.
Buat tugas
https://nsfwrouter.xyz/api/v1/tasks/create
Kirim tugas AI ke cluster GPU. Tugas asinkron, mengembalikan ID. Hasil via API atau Webhook.
| Parameter | Tipe | Wajib | Deskripsi |
|---|---|---|---|
| tool_id | int | Ya | ID alat, dari daftar alat |
| params | object | Ya | Parameter tugas, objek JSON, field bergantung pada alat |
| webhook_url | string | Tidak | URL callback untuk notifikasi selesai |
| priority | int | Tidak | Prioritas tugas 1-10, default 5 |
| idempotency_key | string | Tidak | Kunci idempotensi, mencegah duplikat |
| execution_options | object | Tidak | Opsi eksekusi, objek JSON |
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"
}
}
Saldo dicek sebelum panggilan. Tidak cukup = error insufficient_coins. Koin dipotong saat pengiriman berhasil.
Query tugas
https://nsfwrouter.xyz/api/v1/tasks/query
Query detail dan status berdasarkan ID. Saat pemrosesan, status diambil dari cluster GPU. Query berulang dalam 10 detik mengembalikan cache DB.
| Parameter | Tipe | Wajib | Deskripsi |
|---|---|---|---|
| id | int | Ya | ID tugas |
{
"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 | Arti |
|---|---|
| 0 | Memproses |
| 1 | Selesai |
| -1 | Dibatalkan |
| -2 | Gagal |
Daftar tugas
https://nsfwrouter.xyz/api/v1/tasks
Query paginasi tugas akun, dengan filter alat, status dan periode.
| Parameter | Tipe | Wajib | Deskripsi |
|---|---|---|---|
| page | int | Tidak | Nomor halaman, default 1 |
| page_size | int | Tidak | Ukuran halaman, default 20, max 50 |
| tool_id | int | Tidak | Filter berdasarkan alat |
| status | int | Tidak | Filter berdasarkan status (0/1/-1/-2) |
| days | int | Tidak | Periode dalam hari, 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 | Tipe | Deskripsi |
|---|---|---|
| type | string | Tipe hasil: image atau video |
| url | string | URL CDN untuk file hasil |
| file_name | string | Nama file |
| file_size | int | Ukuran file (byte) |
| mime_type | string | Tipe MIME, mis. image/png, video/mp4 |
| width | int | Lebar (piksel) |
| height | int | Tinggi (piksel) |
Saldo akun
https://nsfwrouter.xyz/api/v1/account/balance
Cek saldo koin, total top up dan total konsumsi.
{
"code": 0,
"message": "success",
"data": {
"remain_coins": 5000,
"total_coins": 10000,
"used_coins": 5000
}
}
Webhook callback
Jika webhook_url ditentukan, POST dikirim saat selesai, gagal atau dibatalkan. 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
}
}
Server Anda harus mengembalikan HTTP 2xx. Pada non-2xx atau timeout (10 det), sistem mencoba ulang hingga 5x dengan backoff eksponensial.
Kode error
Semua respons error menggunakan format: {"code": kode, "message": "identifier", "data": {}}
| Kode error | message | Deskripsi |
|---|---|---|
| 20001 | api_key_required | Kunci API tidak diberikan |
| 20001 | invalid_api_key | Kunci API tidak valid |
| 20001 | ip_not_allowed | IP tidak di whitelist |
| 20001 | permission_denied | Akses ditolak |
| 30001 | tool_not_found | Alat tidak ditemukan |
| 30001 | task_not_found | Tugas tidak ditemukan |
| 30001 | insufficient_coins | Saldo koin tidak cukup |
| 30001 | task_submit_failed | Pengiriman tugas gagal |
| 30001 | task_query_failed | Query tugas gagal |
| 30001 | task_already_exists | Tugas sudah ada (idempotensi) |
| 40001 | tool_id_required | Parameter tool_id hilang |
| 40001 | param_error | Error parameter |
| 40001 | webhook_url_invalid | Format webhook_url tidak valid |
| 40001 | params_must_be_json_object_or_array | params harus objek atau array JSON |
| 40001 | execution_options_must_be_json_object_or_array | execution_options harus objek atau array JSON |
| Rentang | Kategori |
|---|---|
| 1xxxx | Error sistem |
| 2xxxx | Error autentikasi |
| 3xxxx | Error logika bisnis |
| 4xxxx | Error parameter |
| 5xxxx | Error dependensi eksternal |