Client-Server API
The Client-Server (C-S) API is the HTTP+JSON API clients use to talk to their homeserver. This page is a map of the main parts; the spec is the reference.
Base URL and versions
The client finds the homeserver's base URL through server discovery (/.well-known/matrix/client). Endpoints live under /_matrix/client/, with a version per endpoint, not per API: most are v3, and newer ones are v1, for example:
/_matrix/client/v1/media/download/{serverName}/{mediaId}and the other authenticated media endpoints (v1.11)/_matrix/client/v1/auth_metadata(OAuth 2.0, v1.15)/_matrix/client/v1/room_summary/{roomIdOrAlias}(v1.15)/_matrix/client/v1/mutual_rooms(v1.19)
GET /_matrix/client/versions lists the spec versions and unstable features a server supports.
Authentication
Since v1.15 there are two authentication APIs. A server may offer one or both, and a client must keep using the API that issued its current token (client authentication):
| API | Discovery | Used by |
|---|---|---|
| OAuth 2.0 API | GET /_matrix/client/v1/auth_metadata | Servers using Matrix Authentication Service, including matrix.org (since 2025-04) |
| Legacy API | GET /_matrix/client/v3/login | Synapse and others without MAS |
See authentication API discovery for how a client decides. The OAuth 2.0 API covers the authorisation code flow (browser login), dynamic client registration and, since v1.18, the device authorization grant for devices without a browser.
A legacy password login:
POST /_matrix/client/v3/login
Content-Type: application/json
{
"type": "m.login.password",
"identifier": { "type": "m.id.user", "user": "alice" },
"password": "...",
"initial_device_display_name": "My client"
}
The response has access_token, device_id and user_id. Use identifier; the top-level user field is deprecated.
Send the token in a header on every request:
Authorization: Bearer <access_token>
Access tokens in the query string (?access_token=) have been deprecated since v1.11.
Sync
GET /_matrix/client/v3/sync returns everything new since the since token: joined, invited, knocked and left rooms (rooms.join and so on), presence, account_data, to_device messages, device_lists and one-time key counts for E2EE, and next_batch for the next call. Long-poll with timeout. Since v1.16, use_state_after=true returns state_after instead of state, which is easier to apply correctly. See syncing.
Simplified Sliding Sync (MSC4186), used by Element X, is accepted but not part of v1.19.
Common endpoints
| Action | Endpoint |
|---|---|
| Create a room | POST /_matrix/client/v3/createRoom |
| Join by ID or alias | POST /_matrix/client/v3/join/{roomIdOrAlias} |
| Send a message event | PUT /_matrix/client/v3/rooms/{roomId}/send/{eventType}/{txnId} |
| Set state | PUT /_matrix/client/v3/rooms/{roomId}/state/{eventType}/{stateKey} |
| Read history | GET /_matrix/client/v3/rooms/{roomId}/messages?dir=b |
| Redact | PUT /_matrix/client/v3/rooms/{roomId}/redact/{eventId}/{txnId} |
| Upgrade a room | POST /_matrix/client/v3/rooms/{roomId}/upgrade |
| Get a profile | GET /_matrix/client/v3/profile/{userId} |
| Set a profile field | PUT /_matrix/client/v3/profile/{userId}/{keyName} |
Sending a message:
PUT /_matrix/client/v3/rooms/!roomid/send/m.room.message/txn1
Authorization: Bearer <access_token>
Content-Type: application/json
{ "msgtype": "m.text", "body": "Hello" }
The txnId makes retries idempotent: reuse it when retrying the same request. Since v1.16, profiles hold custom fields, so displayname, avatar_url and m.tz are all set through /profile/{userId}/{keyName}.
Authenticated media
Since v1.11, media is downloaded with an access token from:
GET /_matrix/client/v1/media/download/{serverName}/{mediaId}GET /_matrix/client/v1/media/thumbnail/{serverName}/{mediaId}
The old unauthenticated /_matrix/media/v3 download and thumbnail endpoints are deprecated. Servers SHOULD "freeze" them, so media uploaded after the freeze is only served through the authenticated endpoints; matrix.org froze in 2024-09. Uploads still go to POST /_matrix/media/v3/upload. See content repository.
Errors and rate limits
Errors are JSON with an errcode and error. Common codes: M_FORBIDDEN, M_UNKNOWN_TOKEN, M_NOT_FOUND, M_LIMIT_EXCEEDED. Newer ones include M_USER_LOCKED (account locking, v1.12), M_USER_SUSPENDED (v1.13) and M_USER_LIMIT_EXCEEDED (v1.18). See standard error response.
When rate-limited, the server returns 429 with M_LIMIT_EXCEEDED. Wait for the time in the Retry-After header before retrying. The retry_after_ms body field is deprecated. See rate limiting.
Safety features
| Feature | Since | Spec |
|---|---|---|
| Report an event, room or user | event: long-standing; room: v1.13; user: v1.14 | reporting content |
| Account locking and suspension | v1.12 / v1.13 | account locking, suspension |
| Admin suspend/lock endpoints | v1.18 | PUT /_matrix/client/v1/admin/suspend/{userId}, PUT /_matrix/client/v1/admin/lock/{userId} |
| Invite blocking | v1.18 | invite permission |
| Policy servers | v1.18 | policy servers |
End-to-end encryption
The E2EE module covers device keys, Olm/Megolm, cross-signing, secret storage and key backup. Since v1.18 the spec recommends that clients not send room keys to, or show messages from, devices that are not cross-signed (MSC4153, recommended client behaviour). v1.19 added encrypted history sharing for new members (MSC4268).
Accepted but not yet in the spec as of 2026-10: Simplified Sliding Sync (MSC4186) and its extensions, delayed events (MSC4140) and bundled URL previews (MSC4095). Spec main already removes query-string access tokens (MSC4127). Sources: MSC repository, matrix-spec.
Resources
- Client-Server API, v1.19
- SDKs that implement it