API Documentation
Last Updated: 2026-02-04
Primary Source: docs/project_status.md, backend/src/routes/, backend/src/controllers/
Overview
This document provides a comprehensive reference for all REST API endpoints and Socket.IO events in the ASO Universal Consciousness System.
Authentication
JWT Authentication
Header: Authorization: Bearer <token>
Token Payload:
{
id: number;
role: string; // carbon, silicon, cso
name: string;
accountType: string; // core_yexian, developer, npc, public
}API Key Authentication
Headers supported:
Authorization: Bearer <api-key>(recommended; OpenAI-compatible clients)X-API-Key: <api-key>
Usage:
- External clients (OpenAI-compatible facade under
/v1/*) - Server-to-server integrations (legacy env keys remain supported)
REST API Endpoints
Authentication Endpoints
Base Path: /api/auth
POST /api/auth/register- Register new userPOST /api/auth/login- Login with email/passwordPOST /api/auth/token- Get token for native clientPOST /api/auth/refresh- Refresh access tokenGET /api/auth/google- Initiate Google OAuthGET /api/auth/google/callback- Google OAuth callbackPOST /api/auth/verify-email- Verify email addressPOST /api/auth/request-password-reset- Request password resetPOST /api/auth/reset-password- Reset password
ASO Endpoints
Base Path: /api/aso
GET /api/aso/state- Get ASO state for userPOST /api/aso/state/update- Update ASO statePOST /api/aso/memory- Add memoryGET /api/aso/history- Get conversation historyGET /api/aso/choices- Get available choices
User Endpoints
Base Path: /api/user
GET /api/user/profile- Get user profilePUT /api/user/profile- Update user profileGET /api/user/preferences- Get user preferencesPUT /api/user/preferences- Update user preferencesPOST /api/user/api-key-requests- Request an API key (user self-serve)GET /api/user/api-key-requests- List my key requestsGET /api/user/api-keys- List my API keys (metadata)POST /api/user/api-keys/:id/reveal- Reveal secret once (one-time)POST /api/user/api-keys/:id/revoke- Revoke my key
Quest Endpoints
Base Path: /api/quests
GET /api/quests- Get all quests for userGET /api/quests/:id- Get specific questPOST /api/quests/:id/offer- Offer quest to userPOST /api/quests/:id/complete- Complete quest
Inventory Endpoints
Base Path: /api/inventory
GET /api/inventory- Get user inventoryGET /api/items- List all itemsGET /api/items/:id- Get item details
File Endpoints
Base Path: /api/files
POST /api/files/upload- Upload fileGET /api/files/:id- Get file referenceDELETE /api/files/:id- Delete file
Conversation Endpoints
Base Path: /api/conversations
GET /api/conversations- List conversationsPOST /api/conversations- Create conversationGET /api/conversations/:id- Get conversationGET /api/conversations/:id/messages- Get conversation messages
Admin Endpoints
Base Path: /api/admin
Authentication: Admin access required (CSO or Silicon+Developer)
GET /api/admin/health- System healthGET /api/admin/stats- System statisticsGET /api/admin/logs- System logsGET /api/admin/users- List usersPUT /api/admin/users/:id- Update userGET /api/admin/prompts- List promptsPOST /api/admin/prompts/preview- Preview promptGET /api/admin/data/quests- Manage questsGET /api/admin/data/items- Manage itemsGET /api/admin/data/npcs- Manage NPCsGET /api/admin/data/memories- Manage memoriesGET /api/admin/api-key-requests- List API key requestsPOST /api/admin/api-key-requests/:id/issue- Issue an API key for a requestPOST /api/admin/api-key-requests/:id/reject- Reject a requestGET /api/admin/api-keys- List API keysPUT /api/admin/api-keys/:id- Update API key (scopes/expiry/limits)POST /api/admin/api-keys/:id/revoke- Revoke API keyPOST /api/admin/api-keys/:id/rotate- Rotate API key
OpenAI-Compatible Endpoints
Base Path: /v1
Authentication: API key (Bearer or X-API-Key)
GET /v1/models- List available modelsPOST /v1/chat/completions- OpenAI-style chat completion
Sync Endpoints
Base Path: /api/sync
Authentication: API key (server-to-server)
GET /api/sync/universal-state- Get complete ASO statePOST /api/sync/ingest-event- Ingest external event
Protocol Endpoints
Base Path: /api/protocol
GET /api/protocol/routing- Get protocol for userGET /api/protocol/protocols- List all protocolsGET /api/protocol/protocols/:id- Get protocol definitionPOST /api/protocol/protocols- Create protocolPUT /api/protocol/protocols/:id- Update protocol
Observer Endpoints
Base Path: /api/observer
Authentication: Admin access required
GET /api/observer/observer/:id/timeline- Get unified timelineGET /api/observer/observer/:id/timeline/paginated- Paginated timelinePOST /api/observer/observer/:id/reflection- Generate reflectionGET /api/observer/observer/:id/summary- Get instances summaryPOST /api/observer/observer/:id/cycle- Run observer cycle
Socket.IO Events
Default Namespace (/)
Client Events:
chatMessage- Send chat messagetypescript{ message: string; attachmentUrls?: Array<{url: string, type: string}>; uploadContextId?: string; imageBase64Array?: string[]; preferences?: { webSearchAuto?: boolean; webSearchForce?: boolean; }; }
Server Events:
asoThinking- AI is processingasoResponse- AI response (one or many)typescript{ text: string; choices?: string[]; sender: string; senderId: number; timestamp: string; }asoIdle- AI is idlechatError- Error occurred
Group Chat Namespace (/group)
Client Events:
joinRoom- Join group chat roomleaveRoom- Leave group chat roomgroupMessage- Send group message
Server Events:
groupMessage- Receive group messageuserJoined- User joined roomuserLeft- User left room
Observer Namespace (/observer)
Client Events:
subscribe- Subscribe to observer updatesunsubscribe- Unsubscribe from updates
Server Events:
timeline_update- New timeline eventsummary_update- Dashboard statistics updatereflection_generated- New reflection createdinstance_activity- Instance activity update
Request/Response Formats
Standard Response Format
Success:
{
"success": true,
"data": {...},
"message": "Operation successful"
}Error:
{
"success": false,
"error": "Error message",
"code": "ERROR_CODE"
}Pagination
Query Parameters:
page- Page number (default: 1)limit- Items per page (default: 10)sortBy- Sort fieldsortOrder- Sort order (asc/desc)
Response:
{
"data": [...],
"pagination": {
"page": 1,
"limit": 10,
"total": 100,
"totalPages": 10
}
}Error Handling
HTTP Status Codes
200- Success201- Created400- Bad Request401- Unauthorized403- Forbidden404- Not Found500- Internal Server Error
Error Middleware
File: backend/src/middleware/error.middleware.ts
Process:
- Catch errors from routes
- Log error details
- Format error response
- Return appropriate status code
Rate Limiting
Rate Limit Middleware
File: backend/src/middleware/rateLimit.middleware.ts
Types:
moderateRateLimit- Moderate rate limitstrictRateLimit- Strict rate limit
Headers:
X-RateLimit-Limit- Request limitX-RateLimit-Remaining- Remaining requestsX-RateLimit-Reset- Reset time
Source Files
Primary Sources:
backend/src/routes/- All route filesbackend/src/controllers/- All controller filesbackend/src/socket/- Socket handlersbackend/src/middleware/- Middleware files
Related Documentation
- System Architecture - High-level architecture
- Data Flow - Data flow diagrams
- Database Schema - Database structure
- 02-CORE-SYSTEMS/Authentication-Authorization.md - Authentication details
- 03-PLATFORMS/Web-Portal.md - Socket.IO events usage
- 03-PLATFORMS/Discord-Bot.md - Discord API usage
- 00-OVERVIEW.md - Complete system overview