API ডকুমেন্টেশন
API কী দিয়ে সব AI ফিচার কল করুন, ব্যবহার অনুযায়ী পেমেন্ট, কয়েক লাইন কোডে ইন্টিগ্রেশন।
প্রমাণীকরণ
সব API অনুরোধে Authorization হেডার থাকতে হবে।
Authorization: Bearer sk-xxxxxxxxxxxxxxxx
কনসোলে „API কী" পেজ থেকে API কী পান। প্রতি অ্যাকাউন্ট এক কী। কনসোলে রিসেট; পুরনো তৎক্ষণাৎ বাতিল।
কাজ তৈরি
https://nsfwrouter.xyz/api/v1/tasks/create
GPU ক্লাস্টারে AI কাজ পাঠান। কাজ অ্যাসিঙ্ক্রোনাস, ID ফেরত দেয়। API বা Webhook থেকে ফলাফল।
| প্যারামিটার | ধরন | আবশ্যক | বিবরণ |
|---|---|---|---|
| tool_id | int | হ্যাঁ | টুল ID, টুল তালিকা থেকে |
| params | object | হ্যাঁ | কাজের প্যারামিটার, JSON object, ফিল্ড টুলের উপর নির্ভর |
| webhook_url | string | না | সম্পন্ন হওয়ার বিজ্ঞপ্তির জন্য callback URL |
| 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 ক্লাস্টার থেকে। ১০ সেকেন্ডের মধ্যে পুনরাবৃত্ত ক্যোয়ারি DB cache ফেরত দেয়।
| প্যারামিটার | ধরন | আবশ্যক | বিবরণ |
|---|---|---|---|
| id | int | হ্যাঁ | কাজ ID |
{
"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 | ফলাফল ফাইলের জন্য CDN URL |
| 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 বার পুনঃচেষ্টা করে exponential 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 | বাহ্যিক নির্ভরতা ত্রুটি |