The API
An orientation to Flaq's HTTP and WebSocket API for people building clients or scripts: finding a server, derived sign-in and bearer tokens, the main routes, and live events.
The desktop app, and the phone apps to come, are built on one HTTP and WebSocket API under /api/v1. This page is a short map of it for anyone writing a client or a script. The full reference, with every route and field, is API.md on GitHub.
The one rule: the server can't read#
Messages and files are end-to-end encrypted, so a client does the cryptography itself. It never sends a password, message text, a file's name or a search word, and the server never sends them back. API.md says where each piece travels; ENCRYPTION.md says how each is made, and tools/flaqcrypto.py in the repository is the reference implementation to test against.
Everything is JSON. Times are ISO 8601 in UTC with a Z; ids are integers.
Finding the server#
GET /.well-known/flaq needs no sign-in and says what an address is. A Messaging Server answers with its id, name, icon and whether it takes new accounts:
{"kind": "server", "id": "<id>", "name": "...", "icon_url": "/api/v1/server/icon?v=3", "registration": "open"}
registration is "open" when the server takes new accounts and "closed" when it doesn't. The answer also says whether the server is a home for accounts, which homes it takes accounts from, and email_resets, true when it emails a link for a forgotten password. A Flaq Connect answers {"kind": "connect", ...} instead.
Signing in#
A client derives a sign-in secret from the password, exchanges it for a bearer token once, and sends the token with every request.
GET /api/v1/auth/prelogin?email=ana@example.com → {"salt": "...", "iterations": 600000}
POST /api/v1/auth/token {"email": "...", "auth": "<derived>", "device": "Ana's MacBook"}
→ 201 {"token": "flaq_...", "user": {me}, "identity": {identity},
"device_id": 12, "route_secret": "<32 bytes, base64url>"}
Authorization: Bearer flaq_...
- Prelogin gives the salt and iteration count for the address. An address with no account gets the same kind of answer, so it doesn't reveal who has one.
- The client runs PBKDF2-SHA256 on the password with that salt, and derives
authfrom the result with HKDF. It also derives the key that opens the person's key backup, which is never sent. POST /api/v1/auth/tokenwithauthreturns the token, shown only in this answer, and the identity to open.
A password sent as it is, rather than derived, is refused. Bearer requests need no CSRF token. Repeated wrong passwords and sign-ups from one address are throttled with 429. POST /api/v1/auth/register makes a new account the same way, when the server takes them.
Accounts from another home sign in with a passport from their home and a signature over the server's challenge instead of a password, through /api/v1/auth/passport.
Errors#
A refusal is a 4xx with {"error": "..."}, written for a person: show it as it is. 401 means signed out, 403 not allowed, 404 also covers what the person may not know exists (a private channel they aren't in), 409 a clash, 413 a file too large, 429 too many attempts.
The main route groups#
| Group | Routes | What for |
|---|---|---|
| Starting up | GET /api/v1/bootstrap |
Everything for the first screen: you, everyone, your conversations with unread counts, presence, saved ids, custom emoji, commands, limits, the server's name and icon |
| Conversations | /api/v1/conversations, /api/v1/channels, /api/v1/dms |
Listing, making, joining, leaving, members, read positions, pins, files |
| Messages | /api/v1/conversations/<id>/messages, /api/v1/messages/<id> |
Sending sealed messages, editing, deleting, replies, reactions, pins, saves |
| Keys | /api/v1/keys/..., /api/v1/conversations/<id>/keys, /epochs |
Your identity, the envelopes that carry conversation keys, sharing keys with members who lack them |
| Files | POST /api/v1/files, GET /files/<id> |
Uploading a sealed blob, then sending a message that names it |
| People | /api/v1/me, /api/v1/users |
Your profile, preferences, status, away and Do Not Disturb; everyone else |
| Lists and search | /api/v1/threads, /api/v1/activity, /api/v1/saved, POST /api/v1/search |
Followed threads, mentions and reactions, saved messages; search over hashed words |
| Custom emoji | /api/v1/emoji |
Listing, adding and removing |
Beside a sealed message, the client declares what the server needs and can't read: who it mentions, and its search hashes. Text uses Slack-style markup, with mentions as tokens such as <@7> and <#3>.
Live events#
Open a WebSocket to /api/v1/ws, with the bearer token as ?token= or in the Authorization header, and ?client= naming the app. The server says hello, then sends events as they happen:
→ {"type": "hello", "user_id": 7, "presence": {"active": [1, 7]}}
← {"type": "typing", "conversation_id": 3, "thread_id": null}
← {"type": "ping"} → {"type": "pong"}
Events include message.new, message.updated, reactions, conversations added, updated, removed and read, typing, presence, keys.added and keys.needed for key sharing, and session.ended when the account is deactivated. A socket refused for want of a sign-in closes with code 4401. After a reconnect, fetch GET /api/v1/conversations again and reload whatever is on screen.
Through Flaq Connect#
A server without a domain is reached through Flaq Connect over QUIC, but the API is the same: each HTTP request is one stream over the connection, and the WebSocket one long-lived stream. The device_id and route_secret from signing in are what a client proves to reach the server that way later. The protocol is in CONNECT.md.
Not in the API yet#
Phone push notifications through APNs and FCM, carrying no message content, are planned. A desktop app notifies from the socket's events while it runs.