Skip to content

Key rotation

Rotating a key gives it a new version and makes that version the one all new ciphertext is made under. Rotation is manual: a key rotates only when you call POST /v1/keys/{id}/rotate or press Rotate in the dashboard, and rypt never rotates a key by itself. An old version keeps decrypting until it is retired. A retired version keeps decrypting for 7 days, and then rypt destroys it, and ciphertext still under it can never be decrypted again.

A paid key, on the Extra wrapped (wrapped), Software (software) or Hardware (hsm) tier, keeps every version it is rotated to until you retire one: by hand, or by setting the key to keep at most a number of versions. Each tier's fee includes some versions, and from December 1, 2026 each version beyond them is billed by the day. A Free (free) key keeps one version, so every rotation of it retires the version before. To keep your data, rewrap everything still under a retired version within its 7 days.

A rotation, in this order:

  1. creates a new version of the key and makes it the primary version, so that from then on encrypt, wrap and rewrap make ciphertext under it;
  2. on a Free key, retires the version that was primary until then;
  3. on a paid key set to keep at most a number of versions, retires the oldest until the key has that many that are not retiring, the new primary among them. A paid key with no such setting, which is the default, has nothing retired.

The key keeps its id, name, tier and container. Ciphertext names the version it was made under, so decrypt, unwrap and rewrap keep working on ciphertext under any version the key still has, a retired version included until it is destroyed. On this page, ciphertext includes wrapped data keys.

A version is retired by a rotation, as above, or by you, as retire a version by hand shows. Either way it keeps working for 7 days after it is retired: decrypt, unwrap and rewrap open ciphertext under it as before. It is never primary again, so nothing new is made under it. The key lists it in retiring_versions, with destroy_after, the time after which rypt destroys it. A later rotation or retirement does not move that time. On a paid key you can restore it until then.

rypt destroys a retired version after its destroy_after, not exactly at it: a sweep that runs every 5 minutes, and later while rypt is idle, destroys each version that is due and writes a destroy_version row to the key's audit log. Until the sweep reaches it, the version is still listed and still decrypts, but do not count on that. Once it is destroyed, a decrypt, unwrap or rewrap of a ciphertext under it is refused with 400 invalid_ciphertext:

{
  "error": "invalid_ciphertext",
  "message": "ciphertext refers to a key version that is not enabled",
  "request_id": "5b0e7c1a-9d3f-4e2b-8a6c-1f4d2e3b5a79"
}

Nothing in the API or the dashboard brings back a destroyed version. Its key material is erased 24 hours after that. On Free and Extra wrapped keys, database backups can still hold it, wrapped, until they expire, and unwrapped copies can remain in rypt's freed memory; see storage and plaintext in memory. Those 24 hours are not a grace period for you: the version opens nothing from the moment rypt destroys it. Only the operator can restore a version during them; there is no API call or dashboard control for it, and rypt makes no promise to do it.

You cannot choose which version encrypt or wrap uses, retire the primary version, keep more than one version on a Free key, or change the 7 days. A key's tier is fixed when it is created.

Tier Versions it keeps Versions its fee includes What a rotation retires
Free (free) 1 1 The version that was primary until then, every time
Extra wrapped (wrapped) Every version, until you retire it 1 Nothing, unless the key is set to keep at most a number of versions
Software (software) Every version, until you retire it 3 Nothing, unless the key is set to keep at most a number of versions
Hardware (hsm) Every version, until you retire it 2 Nothing, unless the key is set to keep at most a number of versions

A paid key's versions beyond the number its fee includes are its extra versions, and from December 1, 2026 each one is billed: see what extra versions cost. The key reports both numbers, as included_versions and extra_versions.

A new key has one version. On a Free key, a ciphertext still decrypts for 7 days after the next rotation. On a paid key, it decrypts until the version it is under is retired, and for 7 days after that. rewrap moves it onto the primary version.

A key can have at most 10 versions retiring at once. A rotation that would retire another, or a version you retire by hand when 10 are retiring, is refused with 409 too_many_retiring_versions, before anything changes, and the message says when the next retiring version is destroyed, after which the key can be rotated again, or another version retired:

{
  "error": "too_many_retiring_versions",
  "message": "the key already has 10 old versions waiting to be destroyed, the most it may have; the next is destroyed after 2026-10-21T09:15:00Z, and the key can be rotated again then",
  "request_id": "c4a1e9d2-7b3f-4e8a-9d61-2f5b8c0e7a14"
}

A version whose destroy_after has passed no longer counts, even while it is still listed. A rotation that retires nothing is never refused for this. Rotating a key once a day stays under the limit.

A rotation is refused in the same way when it would retire more versions at once than the 10 leave room for, which happens on a key whose keep_at_most was lowered a long way. Its message says how many versions the rotation would retire and to raise keep_at_most. Waiting does not help: raise the setting, or retire the oldest versions by hand first, then rotate.

curl -sS -X POST "https://api.rypt.dev/v1/keys/$KEY_ID/rotate" \
  -H "Authorization: Bearer $RYPT_TOKEN"

It takes no request body and answers 200 with the key. For a Software key that had versions 1, 2 and 3 and is set to keep at most 3:

{
  "id": "0f1e2d3c-4b5a-6978-8796-a5b4c3d2e1f0",
  "container_id": "3e2d1c0b-9a87-4654-b321-0fedcba98765",
  "name": "prod-database",
  "tier": "software",
  "versions": ["1", "2", "3", "4"],
  "primary_version": "4",
  "retiring_versions": [
    {"version": "1", "destroy_after": "2026-10-21T09:15:00.250000Z"}
  ],
  "included_versions": 3,
  "extra_versions": 1,
  "extra_version_monthly_cents": 25,
  "keep_at_most": 3,
  "created_at": "2026-09-16T10:00:00.123456Z",
  "state": "active",
  "delete_requested_at": null,
  "destroy_after": null
}

versions lists the key's enabled versions, oldest first: every version that still decrypts, retiring ones included. primary_version is the one new ciphertext is made under, and is never retiring. retiring_versions lists the versions that have been retired, by a rotation or by hand, oldest first, each with its destroy_after as an RFC 3339 timestamp in UTC; it is [] when none is retiring. included_versions is how many versions the tier's fee includes, and extra_versions how many of versions, retiring ones included, are beyond that; it is always 0 on a Free key. extra_version_monthly_cents is the price of one extra version for a whole month, in US cents before tax, and 0 on a Free key. keep_at_most is the key's setting, or null when it keeps every version; it is always null on a Free key. The key's own destroy_after, at the end, is about deleting the key, not its versions.

Here the rotation retired version 1, which rypt destroys after 2026-10-21T09:15:00.250000Z, 7 days after the rotation. Until then version 1 still counts: the key has 4 versions and its fee includes 3, so extra_versions is 1. With keep_at_most set to null, the same rotation would have retired nothing, and retiring_versions would be [].

  • A rotation is not an operation. It does not count toward the key's monthly operations and does not reset that count. It is not billed itself, but on a paid key the version it adds can be an extra version, which is billed from December 1, 2026.
  • On a Free key that has used its 10,000 operations this month, a rotation is refused with 429 ops_cap_reached until the cap resets, with the same body, cap and resets_at included, as an encrypt gets. rewrap says why.
  • On a paid key, a rotation needs your tenant's billing in good standing, and is refused with 402 billing_required otherwise, even one that would retire nothing, because it adds a version that can be billed. rewrap says why.
  • An API token needs the rotate action; see access control. A dashboard session needs no action.
  • A key pending deletion is refused with 409 key_pending_deletion. Restore it first, with POST /v1/keys/{id}/restore (an API token needs the restore action) or Restore in the dashboard.
  • Deleting a key does not stop its retired versions' 7 days. Each is still destroyed after its destroy_after, and restoring the key does not restore them. On a paid key you can restore a retiring version yourself once the key is restored, while that version's 7 days last.
  • A successful rotation writes a rotate row to the key's audit log, with the new primary version as kms_version. A rotation that fails after rypt has found the key, or that is refused by the API token's key list or actions, writes one without a version.
  • On Software and Hardware keys, a rotation waits for Cloud KMS to generate the new version's key material, for up to 60 seconds.
Response Cause
401 unauthorized The credential is missing or invalid.
402 billing_required The key is on a paid tier, and your tenant's billing is not in good standing.
403 ip_not_allowed The API token has a firewall, and the request came from outside it.
403 key_not_allowed, 403 action_not_allowed The API token's key list or actions do not allow it. See access control.
404 not_found The id is not a UUID, was never issued, names a destroyed key, or names a key in another container or tenant.
409 key_pending_deletion The key is pending deletion.
409 too_many_retiring_versions The rotation would retire a version, and the key already has 10 versions retiring, or would have more than 10. See at most 10 versions retiring.
429 ops_cap_reached The key is a Free key that has used its 10,000 operations this UTC month. Rotate it after resets_at.
429 rate_limited The rate limit. See limits.
503 unavailable rypt could not verify the API token or check its actions, or no slot came free within 30 seconds because too many key changes were in flight (too many key lifecycle operations in flight; retry shortly). Nothing changed, and a retry is safe.
500 internal_error Cloud KMS or rypt failed, before, part-way through or after the rotation took effect. See below.

A 500 does not tell you how far the rotation got. It can come before anything changed; after the new version was created, or made primary; or after the whole rotation succeeded and only its audit row could not be written. If you get no answer at all, assume the same. Either way nothing stops decrypting at once: a version the rotation retired keeps working for 7 days, as after any rotation.

rypt's own record of the key's versions, which GET /v1/keys/{id} and the dashboard read, is written only when a rotation finishes. Until the next successful rotation, it can show versions and primary_version as they were before. If the key still shows the versions it had before, that does not tell you whether the rotation took effect. If it shows a new primary_version, the rotation finished.

encrypt, wrap and rewrap use the primary version the key really has, which can already be the new one while GET still shows the old one. Their audit rows name the version they used as kms_version.

The next rotation that succeeds counts every enabled version that exists by then, and puts the record right. On a Free key, or a paid key set to keep at most a number of versions, it can therefore retire more versions than one rotation would, and they can include the version you have just rewrapped onto. After it, read retiring_versions and rewrap whatever is still under those versions within their 7 days, as after any rotation, or, on a paid key, restore the versions you still need.

curl -sS -X POST "https://api.rypt.dev/v1/keys/$KEY_ID/versions/2/retire" \
  -H "Authorization: Bearer $RYPT_TOKEN"

It takes no request body and answers 200 with the key, the version now in retiring_versions. The version in the path is its short id, as versions lists it, such as 2. You can retire any version but the primary: to retire the primary, rotate first, then retire the version that was primary. A version you retire keeps decrypting, unwrapping and rewrapping for 7 days, as one a rotation retires does, and rypt then destroys it, with whatever is still under it. Rewrap what you need before its destroy_after.

  • Retiring a version that is already retiring changes nothing: its destroy_after stays where it was, the answer is the same 200, and no audit row is written.
  • A retiring version is still billed as an extra version until it is destroyed, the day it is destroyed included. Retiring a version lowers a paid key's bill only from the day after that.
  • On a paid key, retiring needs your tenant's billing in good standing, and is refused with 402 billing_required otherwise, because rewrap, the only way to move data off the version, needs it too. On a Free key at its monthly cap it is refused with 429 ops_cap_reached, for the same reason, though a Free key seldom has a version to retire by hand: the only one that is not retiring is normally the primary.
  • An API token needs the retire action, which no API token has unless you give it; see access control. A dashboard session needs no action.
  • A successful retirement writes a retire_version row to the key's audit log, naming the version as kms_version.
Response Cause
402 billing_required The key is on a paid tier, and your tenant's billing is not in good standing.
403 key_not_allowed, 403 action_not_allowed The API token's key list or actions do not allow it. See access control.
404 not_found The key id names no key you can reach, as for a rotation, or the key has no such version, or no longer decrypts with it, or the version is not a short id.
409 key_pending_deletion The key is pending deletion.
409 primary_version The version is the primary. Rotate the key first, then retire the version that was primary.
409 too_many_retiring_versions The key already has 10 versions retiring. The message says when the next one is destroyed, after which another version can be retired.
429 ops_cap_reached The key is a Free key that has used its 10,000 operations this UTC month.

Every other answer is as for a rotation.

curl -sS -X POST "https://api.rypt.dev/v1/keys/$KEY_ID/versions/2/restore" \
  -H "Authorization: Bearer $RYPT_TOKEN"

It takes no request body and answers 200 with the key. The version leaves retiring_versions, works as it did before it was retired, and is never destroyed unless it is retired again. You can restore a version of a paid key until its destroy_after, whether a rotation retired it or you did. From that time on, a restore is refused with 409 restore_window_closed, even while the version is still listed, because its destruction may already have begun.

  • A Free key keeps exactly one version, so its retiring version cannot be restored: 409 free_key_one_version.
  • Restoring is never refused because of billing, because keeping a version destroys nothing. The version is billed as an extra version all along, while it was retiring too.
  • On a key set to keep at most a number of versions, a restored version counts toward that number again, so the next rotation retires it again if it is among the oldest beyond the number.
  • An API token needs the restore action, the same action that restores a deleted key. A dashboard session needs no action.
  • A successful restore writes a restore_version row to the key's audit log, naming the version as kms_version.
Response Cause
404 not_found The key id names no key you can reach, or the key has no such version, or no longer decrypts with it, or the version is not a short id.
409 key_pending_deletion The key is pending deletion. Restore the key first.
409 not_retiring The version is not retiring, so there is nothing to restore.
409 restore_window_closed The version's destroy_after has passed. It can no longer be restored.
409 free_key_one_version The key is a Free key.

Every other answer is as for a rotation, apart from 402 billing_required, 409 too_many_retiring_versions and 429 ops_cap_reached, which a restore never gets.

A paid key keeps every version until you retire it. To have its rotations retire old versions instead, set how many versions the key keeps:

curl -sS -X POST "https://api.rypt.dev/v1/keys/$KEY_ID/retention" \
  -H "Authorization: Bearer $RYPT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"keep_at_most": 3}'

It answers 200 with the key, its keep_at_most now 3. From then on, each rotation keeps the newest 3 versions that are not retiring, the new primary among them, and retires the oldest beyond them, each for 7 days before rypt destroys it. Versions already retiring do not count toward the 3. Send {"keep_at_most": null} to go back to the default, in which rotations retire nothing.

  • Setting it retires nothing by itself. It takes effect at the key's next rotation, so lowering it never starts a version's 7 days on its own, but that next rotation retires every version beyond the new number at once. If that would be more than the 10 a key may have retiring, the rotation is refused; see at most 10 versions retiring.
  • Any whole number from 1 up is allowed, a number below the versions the tier includes too. keep_at_most is required: a body without it, or with 0, a negative number or a number over 2147483647, is refused with 400 invalid_keep_at_most, and one with a string or a fraction with 400 invalid_request.
  • A Free key has no such setting: 409 free_key_one_version. A key pending deletion is refused with 409 key_pending_deletion.
  • An API token needs the retire action, because the setting lets rotations retire versions. A dashboard session needs no action.
  • Setting the number the key already has changes nothing and writes no audit row. A change writes a set_retention row to the key's audit log, which records neither the old number nor the new one.

Each paid tier's fee includes some versions: 1 on Extra wrapped, 3 on Software and 2 on Hardware. Each version a paid key has beyond that number is an extra version, with a monthly price of its own, which the key gives as extra_version_monthly_cents and rypt.dev lists. From December 1, 2026, extra versions are billed by the day, the way keys are:

  • On each UTC day the key itself is billed, each extra version that existed that day, even for part of it, is billed one day's share of its monthly price.
  • A version counts from the day it was created through the day rypt destroys it, both included. A retiring version still counts, since it still decrypts, until it is destroyed.
  • What counts is how many versions the key has, the primary and retiring ones included: a Software key with 5 versions has 2 extra versions, whichever they are.
  • Extra versions are billed only on the days the key is billed, so they stop with the key's own fee when its deletion is requested.
  • Extra versions do not change a key's included operations.
  • No day before December 1, 2026 is billed for extra versions, and a Free key has none.

A Software key that has 5 versions for all of December is billed its monthly fee and the monthly price of 2 extra versions. Each paid tier's extra versions are a line of their own on the invoice. A key you rotate often gains a version each time, so retire old versions by hand, or set the key to keep at most a number of versions, to keep the count down.

Which version a ciphertext is under

Section titled "Which version a ciphertext is under"

No call reports it. The decrypt and unwrap responses do not say which version opened a ciphertext, and rypt keeps no copy of the ciphertext it returns, so it cannot list what is still under an old version. When a version is retired, by a rotation or by you, assume that anything you hold under the key may be under it. If you want to track versions yourself, the audit log row of each encrypt, wrap and rewrap names the version it used, under the same request id as the call's x-request-id response header.

rewrap moves ciphertext to the primary version

Section titled "rewrap moves ciphertext to the primary version"

rewrap is how you move ciphertext from an older version of a key to its primary. rewrap shows the call, how to send a wrapped data key, and why the aad cannot change. For rotation, what matters:

  • It always re-encrypts under the key's current primary version, whatever version the ciphertext is under, the primary included.
  • It takes one ciphertext per call, and each call is one operation. There is no batch call and no call that rewraps everything under a version.
  • It works within one key. It cannot move ciphertext to another key.
  • It opens the old ciphertext first, so it works on a retired version until rypt destroys that version, and fails with 400 invalid_ciphertext from then on. Finish before the version's destroy_after.
  • On a paid key whose billing is not in good standing it is 402 billing_required, and so are rotation and retiring a version. On a Free key whose monthly cap is used up it is 429 ops_cap_reached, like encrypt and wrap, and so are rotation and retiring a version.

A Free key keeps one version, so every rotation retires the version that was primary until then, and everything still under it stops decrypting when rypt destroys that version, after 7 days. A Free key's retiring version cannot be restored. To keep what you need:

  1. Rotate.
  2. rewrap every ciphertext and wrapped data key you hold under the key, and store the results in place of the old values. Finish before the retired version's destroy_after, which GET /v1/keys/{id} lists under retiring_versions.

This costs one operation per value. On a Free key each counts toward its 10,000 operations a month, so check how many the key has left before you rotate. Limits explains the cap.

An Extra wrapped, Software or Hardware key keeps every version until you retire it, so a rotation by itself leaves all your ciphertext readable. To move off an old version and stop paying for it:

  1. Rotate.
  2. rewrap every ciphertext and wrapped data key you hold under the key, and store the results in place of the old values.
  3. Retire the old versions by hand. Each keeps decrypting for 7 days, and you can restore it in that time if something still needs it.

If the key is set to keep at most a number of versions, its rotations retire the oldest versions beyond that number themselves. Then finish step 2 before the destroy_after of each version retiring_versions lists, or restore the version. If you finish step 2 after every rotation, nothing is left under a version when it is retired, and nothing is lost when rypt destroys it.

  1. In the dashboard, open Encryption keys, then the key.

  2. Press Rotate, in the key's header. It is there on every tab while the key is active; a key pending deletion has no Rotate.

  3. The dialog, Rotate "{name}", reads the key again and says what the rotation will do:

    • A paid key that keeps every version, or one whose setting leaves room for the new version: that the rotation retires nothing, so everything already encrypted keeps decrypting, and, if the key will then have more versions than its fee includes, what its extra versions will cost a month from December 1, 2026.
    • A Free key, or a paid key whose setting means the rotation retires versions: the versions the rotation retires, the time after which each is destroyed, and a rewrap snippet with Copy snippet, to run after the rotation. Type the key's name in "Type the key's name to rotate it" before Rotate can be pressed.
    • A key that already has 10 versions retiring, or a rotation that would retire more than the 10 allow: that rypt refuses the rotation, and when the next one is destroyed or that you must keep more versions first.
    • A paid key while your billing is not in good standing: that rypt refuses the rotation, and a link to the Billing page.

    It also lists the versions retired earlier, each with the time after which it is destroyed.

  4. Press Rotate.

The snippet is for your terminal: rewrap needs an API token, and the dashboard cannot run it. A key's Versions tab lists its enabled versions, newest first, retiring ones included, and which of them are extra. On a paid key you can retire a version there, after a confirmation that says data still under it becomes unreadable once it is destroyed unless you rewrap it first, and restore a retiring version. On a paid key you can also set how many versions to keep at most; the dashboard warns that rotations will then retire old versions, destroyed 7 days later. Its Overview tab shows the Primary version and Enabled versions.

The dialog reads the same record as GET /v1/keys/{id}, so after a failed rotation the version it says it will retire can be wrong. If a rotation fails with internal_error, the dialog's "The rotation did not happen." may not be true; see if a rotation fails. The dashboard does not repeat a failed rotation by itself, and pressing Rotate again starts a new one.