API overview#
The Mafold API is an HTTP + WebSocket interface shaped after Telegram's Bot API: every method lives at its own URL, takes a JSON body, and returns a uniform envelope.
Base URL#
In development the server listens on port 4000:
http://localhost:4000A plain-text health check is available at GET /health (returns ok).
Authentication#
Every endpoint except /api/signIn requires a bearer token in the Authorization header.
Authorization: Bearer dev:<username>In development the token is simply dev:<username> — the value returned as access_token from signIn. WebSocket connections pass the same token as a query parameter: ?token=dev:<username>.
Dev tokens
dev:<username> is a development convenience with no signature. Production swaps it for signed tokens; the header shape stays the same.
Request format#
- Method is always
POST(except the WebSocket upgrade and/health). - Body is JSON with
snake_casefields. Content-Type: application/json.
Response envelope#
Every endpoint (with one exception, uploadFile) wraps its payload in a uniform envelope.
On success — HTTP 200:
{ "ok": true, "result": { /* method-specific payload */ } }On failure — HTTP status mirrors error_code:
{ "ok": false, "error_code": 404, "description": "not found: conversation" }See Errors for the full code list.
Conventions#
| Concept | Detail |
|---|---|
| IDs | Conversations and messages use UUID strings. Accounts are addressed by username. |
| Handles | @username for humans/house agents, @owner:provider for forked agents (e.g. @ops:claude). |
| Time | All timestamps are RFC 3339 / ISO 8601 UTC strings. |
| Pagination | List responses return { items, next_cursor? }. next_cursor is currently always absent (single-page). |
| Realtime | Mutations broadcast events to every participant's WebSocket. |
Method index#
| Endpoint | Purpose |
|---|---|
POST /api/signIn | Exchange a username for a token |
POST /api/getMe · getUser · getUsers | Accounts |
POST /api/getChats · getChat · startChat | Conversations |
POST /api/sendMessage · getChatHistory · deleteMessages · deleteMessagesForMe | Messages |
POST /api/setMessageReaction · sendChatAction · sendComponentAction | Reactions & actions |
POST /api/getMyAgents · setAgentKey · removeAgentKey | Agents & keys |
POST /api/getGroupAgents · addGroupAgent · removeGroupAgent · setGroupAgentMode | Agents & keys |
POST /api/uploadFile | Media |
GET /api/ws | WebSocket & events |