Skip to content

API Overview

NekoBot provides comprehensive RESTful API and WebSocket API for interacting with the backend services.

Basic Information

  • Base URL: http://localhost:6285/api
  • Authentication: JWT Bearer Token
  • Content Type: application/json

Authentication

All authenticated APIs require a JWT Token in the request header:

http
Authorization: Bearer <your_token>

Get Token:

http
POST /api/login
Content-Type: application/json

{
  "username": "nekobot",
  "password": "nekobot"
}

Response:

json
{
  "access_token": "eyJhbGciOiJIUzI1NiIs...",
  "token_type": "bearer"
}

API Endpoints

Authentication

EndpointMethodDescriptionAuth
/api/loginPOSTUser loginNo
/api/logoutPOSTUser logoutYes

Bot Configuration

EndpointMethodDescriptionAuth
/api/bot/configGETGet configurationYes
/api/bot/configPUTUpdate configurationYes

Plugin Management

EndpointMethodDescriptionAuth
/api/pluginsGETGet plugin listYes
/api/plugins/enablePOSTEnable pluginNo
/api/plugins/disablePOSTDisable pluginNo
/api/plugins/reloadPOSTReload pluginNo
/api/plugins/uploadPOSTUpload pluginNo
/api/plugins/deleteDELETEDelete pluginNo
/api/plugins/configGETGet plugin configurationYes
/api/plugins/configPUTUpdate plugin configurationYes

Platform Management

EndpointMethodDescriptionAuth
/api/platformsGETGet platform listYes
/api/platformsPOSTAdd platformYes
/api/platforms/<id>DELETEDelete platformYes
/api/platform/statsGETGet platform statisticsNo

LLM Management

EndpointMethodDescriptionAuth
/api/llm/providersGETGet LLM provider listYes
/api/llm/providersPOSTAdd LLM providerYes
/api/llm/providers/<id>DELETEDelete LLM providerYes
/api/llm/chatPOSTSend chat requestNo

Personality Management

EndpointMethodDescriptionAuth
/api/personalitiesGETGet personality listYes
/api/personalitiesPOSTCreate personalityYes
/api/personalities/<id>DELETEDelete personalityYes
/api/personalities/defaultPUTSet default personalityYes

Command Management

EndpointMethodDescriptionAuth
/api/commandsGETGet all commandsNo
/api/commands/conflictsGETCheck command conflictsNo

Log Management

EndpointMethodDescriptionAuth
/api/logsGETGet logsYes

MCP Management

EndpointMethodDescriptionAuth
/api/mcp/serversGETGet MCP server listYes
/api/mcp/serversPOSTAdd MCP serverYes
/api/mcp/servers/<id>DELETEDelete MCP serverYes

Settings Management

EndpointMethodDescriptionAuth
/api/settingsGETGet settingsYes
/api/settingsPUTUpdate settingsYes
EndpointMethodDescriptionAuth
/chat/sendPOSTSend chat messageNo
/chat/new_sessionPOSTCreate new sessionNo
/chat/sessionsGETGet session listNo
/chat/get_sessionGETGet session detailsNo
/chat/delete_sessionDELETEDelete sessionNo

WebSocket API

Connect WebSocket

javascript
const ws = new WebSocket("ws://localhost:6285/ws");

Subscribe to Channels

javascript
ws.send(JSON.stringify({
  action: "subscribe",
  channels: ["logs", "events"]
}));

Available Channels

ChannelDescription
logsReal-time logs
eventsEvent notifications

Response Format

Success Response

json
{
  "status": "success",
  "data": {...}
}

Error Response

json
{
  "status": "error",
  "message": "Error description"
}

Error Codes

Status CodeDescription
200Success
400Invalid request parameters
401Unauthorized
403Forbidden
404Resource not found
500Server error

Rate Limiting

Some APIs may have rate limiting, please check the response headers:

X-RateLimit-Limit: 100
X-RateLimit-Remaining: 99
X-RateLimit-Reset: 1234567890

Common Parameters

Pagination Parameters

For list-returning APIs, you can use the following pagination parameters:

ParameterTypeDefaultDescription
pageinteger1Page number
page_sizeinteger20Items per page

Sorting Parameters

ParameterTypeDescription
sort_bystringSort field
orderstringSort direction: asc or desc

Best Practices

  1. Error Handling: Always check the status field in the response
  2. Token Management: Keep JWT Token secure and refresh it in time
  3. Concurrency Control: Observe rate limits, avoid excessive concurrent requests
  4. Caching: Use caching for frequently accessed data
  5. HTTPS: Use HTTPS to protect data transmission in production

基于 AGPL-3.0 与 MIT 许可发布