Protocol guide
Messages and attachments
How to post, read, edit, delete and react to messages in both security modes, keep a timeline in sync, upload files, and use read state, typing, presence and webhooks.
Specification: 11 Messages, attachments, read state and presence
Everything a context's timeline holds goes through the endpoints on this page: messages, edits, reactions, deletes and the files attached to them. A context is a channel, a DM or a group DM. Both security modes use the same content schema and the same posting endpoint; only the wrapper around the content (the carrier) changes. The full rules are in document 11.
The SealedMessage format is on Secure messages (MLS), the event envelope and resume on Event WebSocket, permissions and moderator deletion on Roles and moderation, and SVF1 file encryption on Cryptography.
Entries and kinds
Every accepted write to a timeline is an entry with a client-generated mid, a kind and its own seq (11 §2.1). There are four kinds (11 §3.1):
kind |
Content object | What it does | Target |
|---|---|---|---|
message |
MessageContent | A new root message: what users see as "a message". | none |
edit |
EditContent | Replaces the content of the author's own root message. | a root message |
reaction |
ReactionContent | Adds one reaction. | a root message |
delete |
DeleteContent | Deletes the author's own root message or reaction. | a root message or a reaction entry |
Removing a reaction is a delete of the reaction entry's mid, so the server can see adds and removes even in secure contexts and enforce per-account caps. v1 has no other kind: a server refuses one with 422 sealed.kind_unsupported in a secure carrier and 400 core.invalid_request in an insecure one. A receiver that meets an unknown kind ignores the entry and doesn't show it, but still advances its sync position past its seq (11 §3.1).
The content object
The content object holds what an entry means. In an insecure context it travels as content; in a secure context its JSON, padded to a multiple of 256 bytes, is the plaintext of a SealedMessage. You write one content model and two carriers.
| Member | Rules |
|---|---|
text |
Required. At most 4,000 Unicode scalar values. Empty (or only white space) only when attachments is non-empty. |
mentions |
Canonical addresses mentioned in text, no duplicates, at most 50. Default []. |
mentionAll |
true if and only if text contains <@everyone>. Default false. |
replyTo |
A ReplyRef or null. |
attachments |
At most 10 AttachmentRef objects. Default []. |
{
"text": "Hi <@bob@b.com>, the notes are attached. **Please** check by Friday.",
"mentions": ["bob@b.com"],
"mentionAll": false,
"replyTo": { "mid": "01938f2f-77aa-7c10-9b2e-0c1d2e3f4a5b", "author": "bob@b.com", "ping": true },
"attachments": [
{ "id": "01938f31-0a0b-7c0d-8e0f-101112131415", "name": "notes.pdf", "mime": "application/pdf", "size": 482113 }
]
}Before sending, convert CR LF and lone CR to LF, and send none of U+0000 to U+001F other than TAB and LF, and no U+007F, U+2028 or U+2029, because an insecure server refuses them with 400 message.invalid_content (11 §3.2). When you display a decrypted secure text, replace those characters with U+FFFD, because no server checked it. Send NFC and trim leading and trailing white space; neither servers nor receivers normalize or trim text for you.
Formatting
text is always SV-Markdown, a fixed subset of CommonMark 0.31.2 (11 §3.3): emphasis, strong, ~~strikethrough~~, ||spoiler||, code spans, fenced code, one level of block quote, lists up to three levels, every LF as a hard break, bare https://, http:// and sloppyv:// autolinks, mention tokens and backslash escapes. Everything else renders as literal text, including headings, tables, HTML, images and masked links such as [text](url), which are the most common phishing trick in chat apps.
A client never loads a remote resource because of message text, and never fetches link previews automatically in a secure context, because that would tell third-party sites what members read and reveal the reader's IP address. In an insecure context it fetches previews only if the user turned them on, and then from the client, never through the hosting server (11 §3.3).
Mention tokens
Mentions live inside text as tokens, so they survive display-name changes (11 §3.4):
user-mention = "<@" token-addr ">"
channel-ref = "<#" token-addr ">"
everyone = "<@everyone>"- The address must be canonical (Addresses);
<@Bob@B.com>is literal text. - Tokens inside code, and escaped tokens such as
\<@erin@e.com>, are literal. - The user-mention tokens outside code must equal
mentionsexactly. An insecure server refuses a mismatch; a secure receiver trusts the decrypted tokens and ignoresmentionsentries without one.
Test your tokenizer against 11 §19.4.
Replies and attachment references
A ReplyRef has mid, author (so the client can show "Replying to Bob" before loading the parent) and ping (default true). Replies are one level deep; there are no threads in v1. An insecure server checks the parent and answers 400 message.invalid_content if it isn't a visible root message in the context sent by author; a deleted parent is allowed. A secure server can't check, so the receiving client checks that the loaded parent is in the same context and was sent by author, and drops the preview if not. A parent that is a tombstone or has expired shows "Original message was deleted" (11 §3.5).
An AttachmentRef has id, name (1 to 255 bytes of UTF-8, no /, \ or control characters), mime (lowercase, no parameters), size (1 to maxAttachmentBytes; empty files aren't supported), and optionally width, height, durationMs, spoiler, voice and a ThumbnailRef as thumb (11 §3.6). An insecure server checks that size equals the stored blob length and mime the declared upload mime. In a secure context sha256 and key (the 32-byte file key, base64url) are required; in an insecure context key must be absent. All IDs in one content object, files and thumbnails together, must be distinct.
Operation content
- EditContent:
target, plus the complete newtext,mentions,mentionAll, an unchanged copy of the root'sreplyTo, and theattachmentsthat remain. An edit is a full replacement, not a diff (11 §3.7.1). - ReactionContent:
targetandkey, exactly one emoji of at most 64 bytes of UTF-8. - DeleteContent:
targetonly.
Posting an entry
Every entry, of every kind and in both modes, goes to POST /v1/contexts/{ctx}/messages (11 §4.1):
POST {base}/v1/contexts/{ctx}/messages
Authorization: Bearer <session token>
Content-Type: application/jsonThe server takes the sender from the session, never from the body. A bot uses Bot <token> at its home server and a remote session elsewhere (03 §3.1).
The body is a PostEntry (11 §4.2): mid; kind (default message); target for operations; and exactly one of content (insecure) or sealed (secure). Secure message and edit entries add mentions and mentionAll, and attachmentIds: on a message when the content has attachments, and on an edit whenever the target has bound attachments, where [] means "remove them all". Both or neither of content and sealed, a member that must be absent (such as a hint member in an insecure carrier), or a secure edit of a target with bound attachments that lacks attachmentIds gets 400 core.invalid_request.
Insecure carrier
POST {base}/v1/contexts/ch:01938a11-2b3c-7d4e-8f90-112233445566/messages
{ "mid": "01938f30-1b2c-7d4e-8f90-a1b2c3d4e5f6",
"content": { "text": "Hello", "replyTo": null, "attachments": [] } }The server validates the content, checks for an operation that content.target equals target, and measures the size as the length of the JCS (RFC 8785) serialization, so white space and escape choices in your request don't count. Over maxMessageBytes (default 16,384, floor 8,192; assume the floor if ServerMetadata doesn't advertise it) gets 413 message.too_large (11 §2.3, 11 §3.8); 11 §19.1 has vectors.
Secure carrier
Secure contexts only
The body carries a SealedMessage as sealed, and next to it only what the server needs: kind and target to apply each kind's rules and cascade deletes, attachmentIds to bind and expire uploads, and the mention hint for notifications. Reply structure, reaction values and file names stay encrypted (11 §4.3).
A secure edit, from 11 §4.3:
{ "mid": "01938f35-2c3d-7e4f-8a5b-6c7d8e9fa0b1",
"kind": "edit",
"target": "01938f30-1b2c-7d4e-8f90-a1b2c3d4e5f6",
"sealed": {
"v": 1,
"ctx": "ch:01938a11-2b3c-7d4e-8f90-112233445566",
"gen": 1,
"mid": "01938f35-2c3d-7e4f-8a5b-6c7d8e9fa0b1",
"epoch": 42,
"ekid": "q83vEjRWeJA",
"kind": "edit",
"ref": "01938f30-1b2c-7d4e-8f90-a1b2c3d4e5f6",
"did": "q2bS9xVg3m0yJpQe1vT0Aw",
"nonce": "Hq2w9b0AAAAAAAAA",
"kc": "Xb2kP0aL9qR2sT5uV8wZ1A",
"ct": "8fQ…",
"sig": "c2Vh…"
},
"mentions": [],
"mentionAll": false }sealed.ctx, sealed.mid, sealed.kind and sealed.ref must match the path, mid, kind and target, or you get 400 sealed.header_mismatch. ref is signed, so a server can't move an edit or reaction to another message.
Check that the unpadded content JSON is at most maxMessageBytes, then pad it with spaces to the next multiple of 256 bytes. Pad every kind: an unpadded reaction's length would reveal the emoji. A reaction or delete always pads to exactly 256 bytes. The server can't see the unpadded length; it only refuses a ct whose length minus its 16-byte tag exceeds roundUp256(maxMessageBytes), with 413 message.too_large (11 §3.8, vectors in 11 §19.2).
Which carrier
The context's current mode decides (11 §4.7):
- Insecure:
contentonly.sealedgets 409 sealed.not_secure. - Secure:
sealedonly.contentgets 409 channel.plaintext_rejected in a channel (also in any channel while a server upgrade is being applied) or 409 sealed.required in a DM or group DM. A DM that isupgradingrefuses plaintext earlier, with 409dm.upgrade_in_progress. Aneeds_encryptionmember can't post at all. - An
editmust use its target's carrier type, else 409 message.not_editable withreason: "security_changed". Reactions and deletes always use the current carrier.
Response
HTTP/1.1 201 Created
Content-Type: application/json
{ "mid": "01938f30-1b2c-7d4e-8f90-a1b2c3d4e5f6", "kind": "message", "seq": 4182, "createdAt": "2026-12-04T18:22:31.512Z" }The EntryAck gives the assigned seq. The server checks in a fixed order and stops at the first failure: session, body shape, idempotency, access, secure-account checks, DM state, carrier, moderation and permissions, size, content (or 14's SealedMessage checks), target rules, mentions, attachments, rate limits (11 §4.5).
The client mid and idempotency
The client generates the mid when the user creates the entry: a lowercase hyphenated UUIDv7 (11 §2.4). Anything else gets 400 core.invalid_request; 11 §19.3 has valid and invalid examples.
mid = 8lhex "-" 4lhex "-" "7" 3lhex "-" variant 3lhex "-" 12lhex
variant = "8" / "9" / "a" / "b"
lhex = DIGIT / %x61-66 ; 0-9 a-f, lowercase onlyThe server never checks the timestamp against its clock, because a message composed offline can be sent days later. Ordering always uses seq, and the server sets createdAt itself, never earlier than the previous entry's (11 §4.5).
The mid is the idempotency key, scoped to the context; Idempotency-Key isn't used here. The server compares a fingerprint of the sender account (canonical address and incarnation), kind and target, not the body bytes (11 §4.6):
- Same fingerprint: 201 with the stored EntryAck. Idempotency runs before access and permission checks, so this holds even if you were timed out or the context changed mode since.
- Different
kindortarget, or themidbelongs to another sender in this context: 409 core.idempotency_conflict withreason: "mismatch". - Original still processing: 409 with
reason: "in_progress"andretryAfterMsof at least 500.
Because bytes aren't compared, re-sealing a queued entry under a newer epoch with the same mid is safe. The server remembers every mid for at least 30 days, even after deletion, so a late resend never recreates a deleted message.
Mentions and @everyone
An insecure server reads mentions from content. A secure one can't, so the carrier carries a cleartext mention hint (11 §4.4): mentions is the content's mentions plus the reply's author when ping is true (unless you are the author), at most 50, and mentionAll equals the content's. In an insecure carrier the hint members must be absent.
Secure contexts only
If the user turned off the AccountVault setting mention_hints ("Send mention notifications in encrypted chats"), send mentions: []. mentionAll is always sent truthfully, because the server must check the permission for it.
The server, in both modes:
- refuses more than 50 entries (duplicates and invalid addresses count), or more distinct addresses than the AntiSpamPolicy
mentionLimit(default 20), with 400 message.too_many_mentions anddata.limitset to the limit you exceeded; - refuses a non-canonical address with 400 address.non_canonical, and silently drops duplicates and addresses that can't see the context, without changing insecure
content; - accepts
mentionAll: truefrom a sender withoutmention_everyonebut records it asfalseand notifies nobody, so the message never fails because of it.
Read mentionLimit from GET /v1/moderation/policy and say so in the composer before sending (11 §4.4).
As a receiver, treat yourself as mentioned by a secure message when the decrypted content mentions you (the tokens decide, §3.4) or replies to you with ping: true. Honour <@everyone> only when the content contains it and the server-validated mentionAll is true; otherwise render it as plain text. Silently suppress a notification the decrypted content doesn't support. Mentions, replies with ping, a validated mentionAll, DM messages and newly added mentions in edits trigger notifications, never for an account that can't see the entry; reactions, deletes, typing, read state and presence trigger none (11 §16, Notifications).
The Message object
A Message is the folded, current view of one root message, returned over HTTP and carried by message.created (11 §5.2). Its members follow the root's own carrier type, not the context's current mode, because an upgraded channel holds both kinds.
| Member | plain |
sealed |
|---|---|---|
content |
current content | absent |
sealed |
absent | root SealedMessage, until the first edit |
edit |
absent | latest EditEntry or null |
mentions, attachmentIds |
absent | validated hint, bound IDs |
reactions |
ReactionSummary list of the plain reactions |
the same |
reactionEntries |
when it has sealed reactions |
when it has sealed reactions |
reactionEntries holds up to 100 sealed ReactionEntry objects, oldest first, with reactionEntryCount giving the total. A plain message can have them: a pre-upgrade plaintext message in an upgraded channel receives sealed reactions afterwards. Render both lists, merging counts per normalized key and counting each account once per key.
Both carry mid, carrier, sender, createdAt, mentionAll, editedAt, deleted and updatedSeq, the seq of the latest entry that changed the message. HTTP responses add ctx and seq; events omit them because the envelope carries them. Treat an unknown carrier as sealed and show the placeholder.
{
"type": "message",
"mid": "01938f30-1b2c-7d4e-8f90-a1b2c3d4e5f6",
"ctx": "ch:01938a11-2b3c-7d4e-8f90-112233445566",
"seq": 4182,
"carrier": "plain",
"sender": { "addr": "alice@a.com", "name": "Alice", "did": "q2bS9xVg3m0yJpQe1vT0Aw", "kind": "user" },
"createdAt": "2026-12-04T18:22:31.512Z",
"content": { "text": "Hello, everyone in **Lobby**", "replyTo": null, "attachments": [] },
"mentionAll": false,
"editedAt": "2026-12-04T18:23:02.004Z",
"deleted": null,
"reactions": [ { "key": "👍", "count": 3, "me": true }, { "key": "🎉", "count": 1, "me": false } ],
"updatedSeq": 4190
}Check the Sender name against addr with the display-name rule (11 §5.1). A webhook sender (kind: "webhook") has no addr or did; show it with a "Webhook" badge and never link it to an account. Treat an unknown kind as bot. In a secure context the bot badge comes from the IdentityCertificate's kind, not from this member.
Secure contexts only
To show a sealed message (11 §5.5): decrypt sealed if edit is null; otherwise decrypt edit.sealed, check same author, target equal to ref and attachment IDs equal to attachmentIds, and mark it "(edited)". If the edit can't be decrypted yet or fails those checks, show the root content if you still hold it, otherwise the placeholder, and retry when keys arrive. Once you show an edit, delete the old plaintext from storage. Decrypt sealed reactions, add the plain summaries, and count each account once per key. A failing root message shows "This message can't be shown"; a failing operation is ignored. Neither is a security warning (11 §3.9).
Listing and paging
Timeline items are root messages, tombstones included, and system items registered by other documents, such as membership lines (11 §7.1). Edits, reactions and deletes change a Message; they don't add items.
GET /v1/contexts/{ctx}/messages takes at most one of before, after, around or changedAfter, plus limit (1 to 100, default 50); through is allowed only with changedAfter. Any other combination gets 400 core.invalid_request. With none, it returns the newest page. around=N returns up to floor(limit / 2) items before N, the item at N if there is one, and the rest after it, with hasMoreBefore and hasMoreAfter.
GET {base}/v1/contexts/ch:01938a11-2b3c-7d4e-8f90-112233445566/messages?before=4183&limit=3
{
"items": [
{ "type": "event", "seq": 4180, "t": "member.joined", "ts": "2026-12-04T18:21:40.002Z",
"d": { "…": "as 09 defines" } },
{ "type": "message", "seq": 4181, "mid": "01938f2f-77aa-7c10-9b2e-0c1d2e3f4a5b", "ctx": "ch:01938a11-2b3c-7d4e-8f90-112233445566",
"carrier": "plain", "sender": { "addr": "bob@b.com", "name": "Bob", "did": "Yx3kP0aL9qR2sT5uV8wZ1A" },
"createdAt": "2026-12-04T18:21:59.001Z", "content": { "text": "hi" }, "mentionAll": false,
"editedAt": null, "deleted": null, "reactions": [], "updatedSeq": 4181 },
{ "type": "message", "seq": 4182, "mid": "01938f30-1b2c-7d4e-8f90-a1b2c3d4e5f6", "ctx": "ch:01938a11-2b3c-7d4e-8f90-112233445566",
"carrier": "plain", "sender": { "addr": "alice@a.com", "name": "Alice", "did": "q2bS9xVg3m0yJpQe1vT0Aw" },
"createdAt": "2026-12-04T18:22:31.512Z", "content": { "text": "Hello", "replyTo": null, "attachments": [] }, "mentionAll": false,
"editedAt": null, "deleted": null, "reactions": [], "updatedSeq": 4182 }
],
"hasMore": true,
"headSeq": 4190,
"ranges": [[1, null]],
"grants": [],
"withheldBeforeSeq": null,
"purgedThroughSeq": 0
}The MessagePage also gives headSeq, the ranges you may read, grants (shared secure history, sealed items only), withheldBeforeSeq (where to show marker K6, see Client requirements) and purgedThroughSeq. Render a SystemItem you know as its owner says, and count the seq of one you don't as covered.
Coverage. A page proves there are no other visible items in the interval it covers; for before=N, from the first item's seq up to N − 1 (11 §7.1). Keep covered intervals per context and fill holes with after=. On every page, drop cached root messages at or below purgedThroughSeq and those outside both ranges and grants, with one exception: in a secure context keep what this device stored during an earlier membership of the account (items below withheldBeforeSeq), and show it above K6 (11 §7.5 rule 6). A range you can't see returns an empty page with hasMore: false, not an error.
To show a reply's parent or jump to a message, fetch GET /v1/contexts/{ctx}/messages/{mid}, read its seq, and page with around (11 §7.2). It answers 404 message.target_not_found for a mid that isn't a visible root message, has expired or been purged, or whose tombstone was dropped.
Visibility is per account, never per device (11 §7.5). Insecure channels serve the whole stored history; DMs serve from the participant's joinedSeq; secure contexts never serve sealed content from before the account's current membership unless a VisibilityGrant covers it. An operation is visible only if its target is. See Communities and channels and 11 §19.5.
Edits
Post kind: "edit" with the complete new content (11 §6.2):
{ "mid": "01938f38-4d5e-7f60-8a71-b2c3d4e5f607",
"kind": "edit",
"target": "01938f30-1b2c-7d4e-8f90-a1b2c3d4e5f6",
"content": { "target": "01938f30-1b2c-7d4e-8f90-a1b2c3d4e5f6",
"text": "Hello, everyone in **Lobby**", "replyTo": null, "attachments": [] } }| Rule | Insecure failure |
|---|---|
| Target is a visible root message in this context. | 404 message.target_not_found |
| It isn't deleted. | 409 message.target_deleted |
| You sent it. | 403 message.not_author |
| Same carrier type. | 409 message.not_editable |
replyTo unchanged; attachments a subset of the current ones. |
400 message.invalid_content |
In a secure carrier the first three fail with 422 sealed.ref_invalid instead, with reason not_found, deleted or not_author, and the last row becomes "attachmentIds is a subset of the target's bound IDs"; receivers check the rest (11 §3.9). A webhook message can't be edited. An edit can remove attachments but never add them, always targets the root, and has no time limit. New mentions in an edit notify only addresses that the root and earlier edits didn't already mention.
An insecure server replaces the stored content and never returns earlier versions. A secure server stores the edit and deletes the ciphertext of the root and of earlier edits, so nobody who loads the message later can read an earlier version. Devices that already decrypted it may still hold it. Show "(edited)" with the time on hover, and no history.
Deletes
{ "mid": "01938f37-0000-7a00-8b00-000000000002",
"kind": "delete",
"target": "01938f36-0000-7a00-8b00-000000000001",
"content": { "target": "01938f36-0000-7a00-8b00-000000000001" } }A delete targets your own root message or reaction entry (11 §6.3). The target must exist in this context (404 message.target_not_found), not be deleted already (409 message.target_deleted) and have been sent by your account (403 message.not_author); a secure carrier gets 422 sealed.ref_invalid for each. A delete needs no permission and is never blocked by a timeout. The delete entry isn't kept as a timeline item; its mid is remembered and its seq is the seq of the resulting event. If a queued delete gets message.target_deleted, or sealed.ref_invalid with reason: "deleted", treat it as done.
A deleted root message becomes a tombstone: a Message with deleted set to a Deletion (at, and by either author or moderator), mentionAll: false, editedAt: null, and no content, sealed data, mentions, attachments or reactions (11 §5.4). Treat an unknown by as moderator. The server deletes the content, edits, reactions and blobs at once, keeps the tombstone at least 30 days so late syncs learn of it, and emits message.deleted. After that it may drop the tombstone, and GET …/messages/{mid} then answers 404. Deleting someone else's message needs manage_messages and gives by: "moderator".
Remove an author-deleted message without a placeholder; a moderator's delete may show "Message removed by a moderator". "Delete for everyone" is the only delete: ask "Delete this message for everyone?" once, with a "Don't ask again" option, and never promise that copies are gone from other members' devices, because a modified client could keep them (11 §6.3).
Reactions
{ "mid": "01938f36-0000-7a00-8b00-000000000001",
"kind": "reaction",
"target": "01938f30-1b2c-7d4e-8f90-a1b2c3d4e5f6",
"content": { "target": "01938f30-1b2c-7d4e-8f90-a1b2c3d4e5f6", "key": "👍" } }A key is one extended grapheme cluster matching UTS #51 possible_emoji, at most 64 bytes. Compare keys after removing U+FE0F, so "❤" and "❤️" are one reaction (11 §3.7.2). The server checks (11 §6.5):
add_reactions, else 403 core.forbidden withdata.permission: "add_reactions";- a visible root message in this context as the target, else 404
message.target_not_found, or 409message.target_deletedif it was deleted (422sealed.ref_invalidin a secure carrier); - fewer than 20 of your live reactions on it, else 409 reaction.too_many;
- plain only: a valid key (400 reaction.invalid_key), no duplicate of yours (409 reaction.already_exists with
data.mid), and fewer than 20 distinctplainkeys on the message unless yours is already among them (409reaction.too_many).
Servers check only the key's structure, never the RGI list, so older Unicode data doesn't refuse newer emoji; offer only RGI emoji in your picker.
Treat reaction.already_exists for a queued reaction as sent, recording data.mid. Removing your own reaction is a delete of its mid and needs no permission.
Secure contexts only
The server can't read sealed keys, so your client must not send a second live reaction with the same key, and must count each account at most once per key when displaying.
The Message inlines up to 100 sealed entries. Fetch the rest, or "who reacted with 👍" for plain keys, from GET /v1/contexts/{ctx}/messages/{mid}/reactions, a cursor collection of ReactionEntry objects, oldest first, limit 1 to 100, default 50. With the URL-encoded key filter it returns only plain entries, because the server can't read sealed ones (11 §7.3).
Live events
These arrive on the Event WebSocket (11 §8.1):
| Event | Class | Stream | d |
|---|---|---|---|
| message.created | durable, timeline item | context | Message without ctx, seq |
| message.edited | durable | context | EditEvent |
| message.deleted | durable | context | DeleteEvent |
| message.purged | durable | context | PurgeEvent |
| reaction.added | durable | context | ReactionEntry without seq |
| reaction.removed | durable | context | ReactionRemovedEvent |
| read.updated | durable | me |
ReadState |
| typing.started, typing.stopped | ephemeral | context | TypingEvent |
| presence.updated | ephemeral | me |
Presence |
| presence.snapshot | ephemeral | context | PresenceSnapshot |
{
"v": 1,
"t": "reaction.removed",
"id": "01938f40-aaaa-7bbb-8ccc-dddddddddddd",
"ctx": "ch:01938a11-2b3c-7d4e-8f90-112233445566",
"seq": 4191,
"ts": "2026-12-04T18:30:00.000Z",
"d": {
"target": "01938f36-0000-7a00-8b00-000000000001",
"message": "01938f30-1b2c-7d4e-8f90-a1b2c3d4e5f6",
"by": "author",
"mid": "01938f37-0000-7a00-8b00-000000000002"
}
}Applying them (11 §7.6, 11 §8.3):
- Apply an edit, delete or reaction event only if its
seqis greater than the cached Message'supdatedSeq, then setupdatedSeq. Otherwise the cache already reflects it. - Deduplicate
message.createdbymid. Your own entry comes back this way; replace the outbox item with it. - On
message.deleted, remove the root message, its edit, all its reactions and its cached attachments. - On
message.purged, drop every root message at or belowthroughSeq. Treat an unknownreasonasadmin. dof{ "withheld": true }means you may not see the event, or (on replay) its content has since gone: advance past it and do nothing else. A replayedmessage.editedorreaction.addedwhose content was deleted carries{ "target": …, "withheld": true }; a replayedmessage.createdof a deleted message carries the tombstone (11 §8.3).- Ephemeral events carry no
seqand are never replayed.
Sync after reconnect
On reconnect, send your last seq per context in session.hello and the server replays what you missed. When it sends session.resync_required, or you have no socket history, resync the context (11 §7.6):
- Load the newest page and show it at once. Let
Hbe itsheadSeq. - With a cache holding sync cursor
C(highestseqapplied) andT(highest item held), requestchangedAfter=C&through=TuntilhasMoreisfalse, applying each item. Then setCtoH. - On 410 message.changes_expired, or with no cache, discard everything but the newest page and set
CtoH. - Fill the hole between
Tand the newest page withbefore=as the user scrolls, orafter=in the background.
Resync at most 4 contexts at once per server.
The changes feed returns items whose updatedSeq exceeds changedAfter, ordered by updatedSeq; use the last item's updatedSeq as the next changedAfter (11 §7.4). After 200 message.created (A), 201 message.created (B), 202 a reaction on A, 203 an edit of B and 204 a delete of A (11 §19.6):
| Request | Items, by updatedSeq |
|---|---|
changedAfter=199 |
B (203, edited), A (204, tombstone) |
changedAfter=202 |
B (203), A (204, tombstone) |
changedAfter=203 |
A (204, tombstone) |
changedAfter=204 |
none; hasMore: false |
A SystemItem's seq counts as its updatedSeq. The server answers for any changedAfter that is the seq of an event less than 30 days old; below its changesFloorSeq it answers 410 message.changes_expired with data.changesFloorSeq. Purged root messages don't appear as items; purgedThroughSeq tells you to drop them. through keeps resync cheap: you pay for what changed in the part you already hold, not for everything said while you were away.
The outbox
Every entry the user creates goes through a persistent outbox, so nothing is lost while a server is down or keys are being set up (11 §13). It applies to every client class that sends, bots included.
- Persist it across restarts (a database on native platforms, IndexedDB on the web) and keep items up to 7 days; an item that reaches that age is
failed. In secure contexts it holds plaintext: protect it like other message data and delete it at sign-out and when the device is revoked. On a shared computer, keep the secure-context outbox in memory only (11 §13.1). - Send in creation order, one request in flight per context. A waiting item blocks later ones in its context; a failed one doesn't. Different contexts are independent.
- Resend the same
midandlastBodybyte for byte, re-encoding only for a new epoch, an insecure-to-secure change or a re-upload afterattachment.expired. A retry in the same epoch resends the stored SealedMessage bytes. - Back off 1, 2, 4, 8, 16, 30, 60 s, then every 60 s, with ±20 % jitter, never sooner than
retryAfterMsorRetry-After. Retry at once when the event WebSocket reconnects, the network changes, or the user taps "Retry now". - If the user edits or deletes an item that was never attempted, rewrite or remove it in place; once attempted, queue the edit or delete behind it as a normal entry (11 §13.4).
11 §13.3 maps every error code to an item state. An item is failed only when nothing will fix it by itself, shown neutrally as "Not sent. Tap to retry or delete.", never as a security warning (11 §13.5).
Warning
Content composed in a secure context never leaves as plaintext without a user action. On sealed.not_secure the item fails, and before any plaintext retry the client verifies the downgrade itself instead of trusting the hosting server (11 §4.7). Insecure-to-secure is re-encoded automatically.
Read state
Read state is one number per account per context, readSeq, private to the account and shared by its devices (11 §9). There are no read receipts in v1.
PUT {base}/v1/contexts/ch:01938a11-2b3c-7d4e-8f90-112233445566/read
{ "readSeq": 4190 }{ "ctx": "ch:01938a11-2b3c-7d4e-8f90-112233445566", "readSeq": 4190, "updatedAt": "2026-12-04T18:31:12.400Z",
"headSeq": 4191, "lastMessageSeq": 4188, "unreadCount": 0, "unreadCapped": false, "mentionCount": 0 }- PUT /v1/contexts/{ctx}/read stores
max(old, readSeq), lowering a value aboveheadSeqtoheadSeq;markUnread: truelets it go down. A change emitsread.updatedto every session of the account on this server, the caller's included. Posting a root message also raises yourreadSeqto at least itsseq. - GET /v1/contexts/{ctx}/read returns one ReadState.
- GET /v1/me/read-states returns every context you can see on the server (
limitup to 1,000, default 200). Call it at start-up and after a resync of themestream instead of one request per channel;read.updatedandsession.headskeep it current after that.
Advance readSeq to the newest message shown in a focused window, at most every 2 s per context, and once more on leaving (11 §9.3). unreadCount counts visible, non-deleted root messages from other accounts with seq above readSeq, leaving out items visible only through a VisibilityGrant; mentionCount counts those of them that mention you by mentions, a validated mentionAll or a reply ping. Both are capped at 1,000, and unreadCapped is true when the true count is higher (11 §9.1). In secure contexts mentionCount is the server's estimate from hints; recompute it from decrypted content.
Typing
POST /v1/contexts/{ctx}/typing with { "typing": true } or { "typing": false } answers 204 (11 §10). true needs what posting a message needs and is refused with the same codes; false is never refused because of a timeout (11 §10.1). The server emits typing.started (expiresInMs: 8000) to other accounts, ignores more than one true per 3 s, and never emits typing.stopped when the 8 s mark expires or your message is accepted (11 §10.2).
- Send
trueon the first change to a non-empty draft and every 6 s while it keeps changing; sendfalsewhen it empties or the user leaves without sending. - Show a typist until
typing.stopped, theirmessage.created, or 10 s after the lasttyping.started, because ephemeral events can be dropped. - Show "Alice is typing…", "Alice and Bob are typing…", or "Several people are typing…".
- If the user turned off "Show when I'm typing" (AccountVault setting
typing_indicators, defaulttrue; stored on the device for an insecure account, which has no AccountVault), don't call the endpoint at all.
Presence
Presence is per server and never federated (11 §11.1). A server knows only what the account's own sessions there tell it, so "online" means "has an app connected to this server". Keep a socket open to every server whose contexts the user has open, so this rarely shows.
Effective status, in order: offline if no socket has been open for 30 s or the user chose invisible; dnd if chosen; idle if chosen or every session is idle; otherwise online. Treat an unknown effective status as online. 11 §19.7 has cases.
PUT {base}/v1/me/presence
{ "status": "dnd", "statusText": "In a meeting until 3", "statusEmoji": "📅", "clearAt": "2026-12-04T15:00:00.000Z", "idle": false }PUT /v1/me/presence needs all four of status, statusText, statusEmoji and clearAt if it has any, or it gets 400 core.invalid_request. A body with only idle sets just the calling session's flag (11 §11.2). statusText is at most 128 Unicode scalar values, statusEmoji one emoji, and clearAt null or a future time at most 30 days ahead. Both GET and PUT return an OwnPresence, including effective.
- Set
idle: trueafter 10 minutes without input on that device, andfalseon the next input, with anidle-only body. A mobile app that keeps its socket open in the background setsidle: truewhen backgrounded. - The home server holds the chosen status. Read it from GET /v1/me/presence at home and copy it to every other server; on a change, PUT home first, then elsewhere. When your home server sends
presence.updatedfor your own address, re-apply it to the other servers. These copies omitidle, so they never change a session's flag (11 §11.6). - Others see your Presence only if you are both active members of a community on that server or share a DM or group DM there that both accepted (11 §11.4). It never reveals
invisible, per-session idle flags, device counts or last-seen times. Missing presence shows as nothing, never "offline". - On subscribing to a context you should get one presence.snapshot of up to 1,000 accounts that aren't
offline(truncatedif there were more); changes then arrive aspresence.updated(11 §11.5). - Say in the status picker that the custom status is visible to everyone who shares a community or conversation with the user, on every server they use.
Retention
A channel's retentionDays sets a period; DMs have unlimited retention in v1 (11 §12). A root message expires at createdAt plus the period, with its edits, reactions, tombstone and files. createdAt never decreases with seq, so expiry removes a prefix of the timeline, tracked as purgedThroughSeq.
The server stops serving at expiry, deletes within 24 h, then advances purgedThroughSeq and emits message.purged with reason: "retention", at most once per hour per context. Shortening the period takes effect within 24 h; lengthening it never brings back deleted content. Deleting pre-upgrade history during a channel upgrade uses reason: "pre_upgrade_deleted", and an operator's purge uses admin (11 §12.4).
Stop showing expired messages, delete their plaintext and cached files (never files the user saved outside the app), and state the period plainly: "Messages are deleted after 30 days. People in the channel can still keep copies." Never present retention as a guarantee (11 §12.5).
Attachments
Files are uploaded to the context's hosting server before the entry that references them (11 §14.2).
1. Create. POST /v1/contexts/{ctx}/attachments with purpose (file or thumbnail, default file), blobBytes, mime and sha256 of the blob. It runs the same checks as posting a message, with attach_files in place of send_messages, and checks the limits below. In a secure context purpose must be file and mime must be application/octet-stream; thumbnail there gets 400 core.invalid_request. The spec's example uploads a file of unknown type:
POST {base}/v1/contexts/ch:01938a11-2b3c-7d4e-8f90-112233445566/attachments
{ "purpose": "file", "blobBytes": 524288, "mime": "application/octet-stream", "sha256": "n4bQgYhMfWWaL-qgxVrQFaO_TxsrC4Is0V1sFbDwCgg" }HTTP/1.1 201 Created
{
"attachment": {
"id": "01938f31-0a0b-7c0d-8e0f-101112131415",
"ctx": "ch:01938a11-2b3c-7d4e-8f90-112233445566",
"purpose": "file", "state": "pending", "blobBytes": 524288, "mime": "application/octet-stream",
"sha256": "n4bQgYhMfWWaL-qgxVrQFaO_TxsrC4Is0V1sFbDwCgg", "uploader": "alice@a.com",
"createdAt": "2026-12-04T18:20:00.000Z", "expiresAt": "2026-12-05T18:20:00.000Z", "mid": null
},
"upload": {
"url": "https://chat.b.com/server/v1/contexts/ch:01938a11-2b3c-7d4e-8f90-112233445566/attachments/01938f31-0a0b-7c0d-8e0f-101112131415/content",
"method": "PUT",
"headers": {},
"expiresAt": "2026-12-04T18:30:00.000Z"
}
}2. Send the bytes. PUT the blob to upload.url with Content-Type: application/octet-stream, Content-Length and every header in upload.headers, before upload.expiresAt (at most 10 minutes). The URL is either the server's own PUT /v1/contexts/{ctx}/attachments/{id}/content, which accepts only the uploader's session and answers 204, or a pre-signed object-store URL that answers CORS for web clients. One outside {base}/ is a capability URL: at least 128 bits of randomness, bound to one blob, never logged. Uploads aren't resumable; if the window passes, start over.
Warning
Send Authorization only if upload.url starts with {base}/. A capability URL needs no credentials, and sending a session token there hands it to a third party.
3. Complete. POST /v1/contexts/{ctx}/attachments/{id}/complete checks the length (422 attachment.size_mismatch) and hash (422 attachment.hash_mismatch); on a mismatch the server discards the bytes and the upload stays pending, so upload once more; a second mismatch fails the outbox item. On success the state is uploaded; completing an uploaded attachment again returns it unchanged. A secure server should also check the SVF1 structure it can see without the key and refuse a bad blob with 400 crypto.malformed. An insecure server may refuse the file here with 403 attachment.blocked.
Note
11 §14.2 says complete "returns the Attachment" without a status code. Accept any 2xx.
4. Reference it within 24 h. Accepting the entry binds the attachment. In an insecure context, an image uploaded with purpose: "file" and mime: "image/jpeg", and its thumbnail uploaded with purpose: "thumbnail" and mime: "image/webp", are referenced like this; each size and mime must match the upload:
{ "mid": "01938f32-5e6f-7a8b-9c0d-1e2f3a4b5c6d",
"content": {
"text": "Site photo",
"attachments": [
{ "id": "01938f31-5a5b-7c5d-8e5f-606162636465", "name": "site.jpg", "mime": "image/jpeg",
"size": 524288, "width": 3024, "height": 4032,
"thumb": { "id": "01938f31-6b6c-7d6e-8f70-717273747576", "mime": "image/webp",
"size": 18342, "width": 384, "height": 512 } }
] } }Each ID must exist in this context, have been uploaded by your account and be uploaded (11 §14.5):
- not yours or not found: 404 attachment.not_found, without saying which;
- still
pending: 409 attachment.not_uploaded; - already
bound: 409 attachment.already_bound; - past
expiresAt: 410 attachment.expired; upload again, with new IDs and, in a secure context, new keys.
An entry binds at most 20 IDs, 10 files and their thumbnails, else 400 message.invalid_content; in an insecure context thumb.id values must have purpose thumbnail and the others file, with the same error. An edit binds nothing new. A blob binds to one message only; to share a file again, upload it again. DELETE /v1/contexts/{ctx}/attachments/{id} by the uploader cancels a pending or uploaded attachment (204); a bound one gets 409 attachment.already_bound. When an edit drops a file, or its message is deleted or expires, the server stops serving the blob at once and deletes it within 24 h.
Encryption in secure contexts
Secure contexts only
Every file and thumbnail is encrypted with SVF1 under its own fresh 32-byte key, never reused (11 §14.3). Compute sha256 of the plaintext, encrypt, and upload with purpose: "file" and mime: "application/octet-stream", thumbnails included, so the server can't tell previews apart. key, size, sha256, name and the real mime go in the encrypted AttachmentRef; every file and thumbnail ID goes in the cleartext attachmentIds.
{ "mid": "01938f33-6f70-7a81-9b92-a3b4c5d6e7f8",
"sealed": { "v": 1, "ctx": "ch:01938a11-2b3c-7d4e-8f90-112233445566", "kind": "message", "…": "…" },
"mentions": [],
"mentionAll": false,
"attachmentIds": ["01938f31-7c7d-7e7f-8a80-818283848586", "01938f31-8d8e-7f8f-9a90-919293949596"] }The receiver decrypts with SVF1, checks the exact size and sha256, and on failure shows the generic attachment failure with a retry action, never a security warning. IDs that don't match attachmentIds show as "This file isn't available". A key per blob means a key revealed in a report opens only that file (Cryptography).
Thumbnails, metadata and limits
Make a thumbnail for images and video: at most 512 px on the longer side, WebP, JPEG or PNG, at most 256 KiB, uploaded as its own attachment (purpose: "thumbnail" insecure, file and encrypted under its own key secure). In a secure context the server can't check those limits, so a receiver ignores a thumbnail whose size or dimensions exceed them. Receivers download the thumbnail first, and the full file only when it is opened or, for images within 2 MiB, automatically on Wi-Fi. Strip EXIF GPS and similar location data before upload unless the user turned that off, because one photo can reveal where someone lives (11 §14.3).
- File size:
maxAttachmentBytesfrom ServerMetadata, default 26,214,400 (25 MiB), floor 8,388,608. A secure blob may be up to 27,269,675 bytes for the default; over gets 413 attachment.too_large. Check before encrypting (11 §14.6). - A secure
blobBytesthat SVF1 can't produce gets 400 crypto.malformed. - An insecure thumbnail upload over 256 KiB gets 413
attachment.too_large. - At most 50 unbound uploads per account per server, else 429 attachment.quota_exceeded. A server may also cap upload volume (2 GiB per account per server per 24 h is RECOMMENDED), with the same code and
retryAfterMs.
Check the size before uploading and say so, for example "This file is too large. Files here can be up to 25 MB."; never start an upload you know will fail.
Downloading
GET /v1/contexts/{ctx}/attachments/{id}/content returns the blob with 200 (single-range Range supported), or a 302 or 307 to a capability URL that needs no credentials and expires within 10 minutes (11 §14.4). Anyone who can see the message can fetch a bound blob, including through a VisibilityGrant; a pending or uploaded one only its uploader. Anything else answers 404 attachment.not_found. GET /v1/contexts/{ctx}/attachments/{id} returns the Attachment object.
Never send Authorization to a redirect target outside {base}/. Web clients fetch with fetch(), display through blob: URLs, and never put a session token in a URL. Blobs carry nosniff, Content-Security-Policy: sandbox; default-src 'none' and Content-Disposition: attachment, so an uploaded HTML or SVG file can't run script. Content-Type is the stored mime only in an insecure context and only for image/png, image/jpeg, image/gif, image/webp, video/mp4, video/webm, audio/ogg, audio/mpeg, audio/mp4 and audio/webm; otherwise it is application/octet-stream. Show those image, video and audio types inline, everything else as a card with its name, size and "Save", and never open or run a file automatically. In a DM that is still a message request, don't fetch attachments until the user accepts; the card says "Accept to see this file".
Webhooks
Warning
Webhooks exist only in insecure channels. In a secure channel, creating, enabling, rotating or executing one answers 403 security.context_secure_unsupported; listing, reading and deleting still work, and PATCH may still rename one, so admins can remove webhooks an upgrade disabled. In a DM or group DM every webhook endpoint answers 404 core.not_found (11 §15.1).
A webhook lets an outside service post into one insecure channel with a secret token, without being a member; to read or react, use a bot account (Accounts). The feature is optional: check for webhooks in ServerMetadata features rather than probing. A server without webhooks answers 404 core.not_found with data.reason: "unknown_endpoint"; one that has them turned off answers 501 core.unsupported_feature with data.feature: "webhooks".
Management needs manage_channels (11 §15.3): create (at most 15 per channel, else 409 message.webhook_limit), list, read, update, rotate the token and delete. A Webhook name is 1 to 80 Unicode scalar values with no @, <, >, control characters or line breaks, so it can't pass as an account. PATCH with state: "disabled" sets disabledReason: "admin"; rotation stops the old token at once, and deleting a webhook leaves its messages in place. The token is whk_ plus base64url of 32 random bytes, returned only on create and rotate; the server stores only a hash, so show it once, with the line "Anyone with this token can post in this channel."
Execute with the token as a Bearer token, never in the URL (11 §15.4):
POST {base}/v1/contexts/ch:01938a11-2b3c-7d4e-8f90-112233445566/webhooks/01938f50-1a2b-7c3d-8e4f-5a6b7c8d9e0f/messages
Authorization: Bearer whk_…
Content-Type: application/json
{ "mid": "01938f51-2b3c-7d4e-9f50-6b7c8d9e0f1a",
"content": { "text": "Build 1432 passed on main.", "mentions": [], "mentionAll": false } }- Send a
midif you retry; without one the request isn't idempotent. - Only
text,mentionsandmentionAll; no replies or attachments. - A bad token, or a missing or disabled webhook, gets 401 without saying which.
- At most 30 executions per minute per webhook.
mentionAllnotifies only withallowMentionAll; without it the message is still accepted and notifies nobody.
The answer is 201 with an EntryAck (POST /v1/contexts/{ctx}/webhooks/{id}/messages). The message's Sender is { "kind": "webhook", "webhook": id, "name": name }. It can be reacted to, replied to and deleted by moderators like any other message, but never edited. When a channel is upgraded to secure, its webhooks are disabled permanently with disabledReason: "secure_context" and their tokens invalidated, because channels never downgrade (11 §15.5).
Recommended rate limits for every endpoint on this page are in 11 §17.3, and the full error table in 11 §17.