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:4000

A 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_case fields.
  • 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#

ConceptDetail
IDsConversations 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).
TimeAll timestamps are RFC 3339 / ISO 8601 UTC strings.
PaginationList responses return { items, next_cursor? }. next_cursor is currently always absent (single-page).
RealtimeMutations broadcast events to every participant's WebSocket.

Method index#

EndpointPurpose
POST /api/signInExchange a username for a token
POST /api/getMe · getUser · getUsersAccounts
POST /api/getChats · getChat · startChatConversations
POST /api/sendMessage · getChatHistory · deleteMessages · deleteMessagesForMeMessages
POST /api/setMessageReaction · sendChatAction · sendComponentActionReactions & actions
POST /api/getMyAgents · setAgentKey · removeAgentKeyAgents & keys
POST /api/getGroupAgents · addGroupAgent · removeGroupAgent · setGroupAgentModeAgents & keys
POST /api/uploadFileMedia
GET /api/wsWebSocket & events