---
title: "Store a key in the backup."
method: PUT
path: "/_matrix/client/v3/room_keys/keys/{roomId}/{sessionId}"
tags: ["End-to-end encryption"]
---

# Store a key in the backup.

`PUT /_matrix/client/v3/room_keys/keys/{roomId}/{sessionId}`

## Request

- Base URL: `https://matrix.org`
- URL: `https://matrix.org/_matrix/client/v3/room_keys/keys/{roomId}/{sessionId}`
- Auth: one of:
  - API key in query parameter `access_token`
  - HTTP bearer
- TypeScript: <https://skmtc.dev/matrix/apis/matrix-client-server-api/docs/_matrix/client/v3/room_keys/keys/:roomId/:sessionId/put.ts> (a function with typed inputs; its response is checked against the schema)

Store a key in the backup.

## Path parameters

- `roomId` string, required
- `sessionId` string, required

## Query parameters

- `version` string, required

## Request body

- object: The key data
  - `first_message_index` integer, required: The index of the first message in the session that the key can decrypt.
  - `forwarded_count` integer, required: The number of times this key has been forwarded via key-sharing between devices.
  - `is_verified` boolean, required: Whether the device backing up the key verified the device that the key is from.
  - `session_data` object, required: Algorithm-dependent data. See the documentation for the backup algorithms in [Server-side key backups](https://spec.matrix.org/v1.19/client-server-api/#server-side-key-backups) for more information on the expected format of the data.

## Response `200`

The update succeeded.

- object
  - `count` integer, required: The number of keys stored in the backup
  - `etag` string, required: The new etag value representing stored keys in the backup. See [`GET /room_keys/version/{version}`](client-server-api/#get_matrixclientv3room_keysversionversion) for more details.

## Other responses

- `403`: The version specified does not match the current backup version. The current version will be included in the `current_version` field.
- `429`: This request was rate-limited.

---

[API](https://skmtc.dev/matrix/apis/matrix-client-server-api.md) - [All operations](https://skmtc.dev/matrix/apis/matrix-client-server-api/llms.txt) - [OpenAPI document](https://skmtc.dev/matrix/apis/matrix-client-server-api/revisions/c7fe4072c681?raw)
