> ## Documentation Index
> Fetch the complete documentation index at: https://docs.olympex.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Rotate and revoke keys

> Replace an API key without downtime, retire old keys, and lock out an exposed key with the key-management endpoints.

An API account can hold several API keys over its life. Each API key is an API key ID with its own secret key, and every key of the account signs with the same passphrase. You rotate the active key to get a new one, keep the old one working for a grace period while you deploy, then revoke it. Three signed endpoints do this: [`GET /accounts/me/keys`](https://docs.olympex.io/api-reference/accounts/list-api-keys), [`POST /accounts/me/keys/rotate`](https://docs.olympex.io/api-reference/accounts/rotate-api-key) and [`POST /accounts/me/keys/{apiKeyId}/revoke`](https://docs.olympex.io/api-reference/accounts/revoke-api-key).

Rotation replaces the API key ID and the secret key. It doesn't change the passphrase, and there is no endpoint that does.

## Key statuses

| `status` | How a key gets there | Signs requests |
| - | - | - |
| `active` | Created with the account, or by a rotation. An account has one `active` key. | Yes |
| `rotating` | The old key of a `graceful` rotation. | Until `expiresAt`, the end of the grace period |
| `expired` | A `rotating` key past `expiresAt`. | No |
| `revoked` | Revoked through the API, or by a `compromised` rotation. | No |

`expired` and `revoked` are final: neither can be restored. The gateway rejects a request signed with either one with `403 Forbidden`, like any other invalid credential.

## Rotate without downtime

**1. Save the rotation before you send it**

Generate an `Idempotency-Key`, for example a UUID, and save it with the request body, such as `{"gracePeriodSeconds":86400,"mode":"graceful","reason":"scheduled rotation"}`. Choose a grace period longer than your deploy: from 60 seconds to 7 days, 24 hours by default.

**2. Rotate**

Call `POST /accounts/me/keys/rotate`, signed with the key you rotate. If the call times out or returns a `5xx`, send it again with the same `Idempotency-Key`, the same body and the same key: you get the same new key back, for 15 minutes. Never start a second rotation to recover from an unknown outcome.

**3. Store the new key**

Write `apiKeyId` and `secretKey` to your secrets manager before anything else. The secret key isn't returned again after `secretRecoverableUntil`, and the list endpoint never returns it.

**4. Confirm that the new key signs**

Call `GET /accounts/me/keys` with the new API key ID, the new secret key and your passphrase. The new key is `active` and the old one is `rotating`.

**5. Deploy the new key**

Deploy the new key to every service that signs requests.

**6. Revoke the old key**

Call `POST /accounts/me/keys/{apiKeyId}/revoke` with the old API key ID, signed with the new key. Don't wait for the grace period to end: a revoked key stops working at once.

[Rotate an API key](https://docs.olympex.io/api-reference/accounts/rotate-api-key.md) has runnable code for the rotation and its retries.

## If a credential is exposed

If a secret key may have been exposed, act as if an attacker holds it and your passphrase.

**1. Stop open orders first**

If the exposed key has open limit orders or DCA strategies, whoever holds it can change them, including their prices and amounts. Set each maker wallet's allowance to the Olympex order contract to `0` for every token the orders sell: that takes effect on-chain at once. Then cancel the orders you don't want to keep.

**2. Rotate in compromised mode**

Call `POST /accounts/me/keys/rotate` with `{"mode":"compromised"}`, signed with the exposed key. The old key is revoked in the same call, so store the new key from the response before anything else: if you lose the response, you can't retry the call with the revoked key. In that case, email [partners@olympex.io](mailto:partners@olympex.io) with the API key IDs, never a secret key or the passphrase.

**3. Revoke any other key that still signs**

List your keys with the new key, and revoke every other key that is still `rotating`.

**4. Deploy the new key**

Replace the API key ID and the secret key in your secrets manager, and redeploy every service that signs requests.

**5. Clean up the leak**

Remove the exposed values from wherever they leaked: logs, tickets, chats or repository history.

**If the passphrase was exposed.** Signing needs a secret key that is still valid, so after the compromised rotation the exposed passphrase alone can't sign. It stays exposed, though, because rotation doesn't change it. To replace it, create a new API account, move your integration and your orders to it, and ask [partners@olympex.io](mailto:partners@olympex.io) to deactivate the old account.

## Build a key-management screen

If your own operators manage keys from a web interface, your backend does the work and the browser never holds a credential.

* **Your backend signs.** The browser calls your backend, and your backend signs and calls Olympex. Never send a secret key or the passphrase to the browser, and never keep them in browser storage, analytics, error reports or client logs.
* **Store before you confirm.** Write a new secret key to your secrets manager from the backend before the screen reports success. If the screen must show it, show it once, and never render it again from application state.
* **Show every status.** Render `active`, `rotating`, `expired` and `revoked`, and show `expiresAt` and `revokedAt` in UTC. Offer revocation for `rotating` and `expired` keys, not for the `active` one.
* **One Idempotency-Key per rotation.** Create it when the operator confirms the rotation, store it with the body on the backend, and reuse it for every retry of that rotation.
* **Hide what isn't available.** If the key endpoints return `404 NOT_FOUND`, mark key management as unavailable: it doesn't mean the account is missing.

Map errors to safe messages: `401` and `403` mean a credential problem on your server, so show no details to the operator; `409` means a conflicting rotation, so refresh the key list; `429` means the account reached its [key management limits](https://docs.olympex.io/authentication/limits.md#key-management-limits) (5 rotation and 10 revocation requests per hour, retries included), so disable the action and retry with the same `Idempotency-Key` up to an hour later; `503` `SERVICE_UNAVAILABLE` means retry after a few seconds; for any other `5xx`, keep `meta.requestId` for [support](https://docs.olympex.io/resources/support.md). [Errors and retries](https://docs.olympex.io/authentication/errors-and-retries.md) covers every code.

## What this means for your integration

* Rotate on a schedule with `graceful` mode, and revoke the old key as soon as the new one is deployed.
* Save the `Idempotency-Key` and the body before you rotate, and retry only with those same values.
* Store a new secret key before you do anything else: after 15 minutes, nothing returns it again.

## Related

> [card] [Rotate an API key](https://docs.olympex.io/api-reference/accounts/rotate-api-key.md)
>
> The rotation endpoint, its modes and retries, with code.

> [card] [Credentials](https://docs.olympex.io/authentication/credentials.md)
>
> The API key ID, secret key and passphrase, and how to store them.

> [card] [Order signatures and allowances](https://docs.olympex.io/concepts/order-authorization.md)
>
> The allowance that limits what any order can spend.

> [card] [Security model](https://docs.olympex.io/concepts/security-model.md)
>
> What Olympex protects, and what you are responsible for.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.