# Key security

How to store your Maxy keys, rotate them, change where a publishable key works, and revoke one. Read it before launch, and keep the last section for the day a key leaks. Which key does what is on [Authentication](https://maxy.co/docs/authentication).

A key cannot move funds or sign anything: every order needs the user's wallet. A leaked secret key still lets someone spend your rate limit, read your order list and statements, register webhooks and manage your keys, so treat it as a password.

## Store keys

| Do | Why |
| --- | --- |
| Keep the secret key on your server, in your secret store or an environment variable | Anyone who can read a web page can read a key in it. The SDK refuses a secret key in a browser page |
| Use a publishable key in pages, bound to your origins | It reads, quotes and places the user's own signed order, nothing else |
| Send keys in the `x-maxy-key` header, never in a URL | A URL lands in logs and history; a secret key in one answers `400 invalid_input` |
| Keep keys out of logs and error reports | The SDK's `redact` masks keys and signatures before you log |
| Use a test key everywhere but production | It reaches only the sandbox |

Maxy keeps only a hash of each key, so it can show a key once and never again. A test key unused for 30 days is revoked.

## See your keys

`GET /account` lists every key of your account by prefix, never whole, with `you: true` on the key you called with. `GET /usage?days=30` gives your calls and errors per day: a rise you did not cause is the first sign of a leak.

```sh
curl -s -H "x-maxy-key: $MAXY_API_KEY" "$BASE/account"
```

```json
{
  "partner": "Your company",
  "selfServe": true,
  "environment": "test",
  "keys": [
    { "prefix": "mxk_pk_test_gIBes9", "kind": "publishable", "environment": "test", "origins": ["http://localhost:3000"], "orderCapUsd": 100, "createdAt": "2026-11-20T01:39:12.554424+00:00", "revokedAt": null, "you": false },
    { "prefix": "mxk_test_scuGmr", "kind": "secret", "environment": "test", "origins": [], "orderCapUsd": 100, "createdAt": "2026-11-20T01:39:12.499079+00:00", "revokedAt": null, "you": true }
  ],
  "usage": [{ "day": "2026-11-20", "calls": 20, "errors": 0 }],
  "limitRequests": []
}
```

## Rotate a secret key

Rotate on a schedule, when someone with access leaves, and at once after a leak.

1. `POST /keys/rotate` answers a new secret key with the same order size cap. It is shown once: store it.
2. Deploy the new key everywhere the old one runs. Both work in the meantime.
3. Revoke the old key with `DELETE /keys/{prefix}`, calling with the new key.

A rotated key records the key it was rotated from. Revoking a key also revokes every key rotated from it, and from those, except the key you call with and the keys rotated from that one: the answer lists them in `alsoRevoked`. So step 3 keeps the new key, and revoking a leaked key (with itself, `?confirm=self`, or with another key of yours) also revokes any key someone rotated from it. An account holds at most 10 active secret keys and 10 active publishable keys per environment; past that, `POST /keys/rotate` and `POST /keys` answer `409 conflict` until you revoke one. Every key made or revoked is listed in `GET /account` under `keyEvents`: check it after a leak.

`rotated.json` holds the new key: delete it once the key is in your secret store.

```sh
curl -s -X POST "$BASE/keys/rotate" -H "x-maxy-key: $MAXY_API_KEY" > rotated.json
NEW_KEY=$(jq -r .key rotated.json); OLD_PREFIX=$(jq -r .rotatedFrom rotated.json)
```

```json
{
  "key": "mxk_test_…",
  "prefix": "mxk_test_p7UKQC",
  "rotatedFrom": "mxk_test_b1skME",
  "orderCapUsd": 100,
  "note": "Shown once. mxk_test_b1skME… keeps working until you revoke it: DELETE /keys/mxk_test_b1skME."
}
```

## Revoke a key

`DELETE /keys/{prefix}` revokes any key of your account. It stops working within a minute, and then answers `403 key_revoked`. To revoke the key you are calling with, add `?confirm=self`; without it the answer is `409 conflict`, so a script cannot lock you out by mistake.

```sh
curl -s -X DELETE "$BASE/keys/$OLD_PREFIX" -H "x-maxy-key: $NEW_KEY"
export MAXY_API_KEY=$NEW_KEY
```

```json
{
  "revoked": true,
  "prefix": "mxk_test_b1skME",
  "note": "It stops working within a minute."
}
```

## Change a publishable key's origins

A publishable key works only from its origins. `POST /keys` with `{ "kind": "publishable", "origins": [...] }` makes one; `POST /keys/{prefix}/origins` replaces its list, and the change applies within a minute. List each origin in full, with its scheme and no path: `https://app.example.com`.

```sh
PK_PREFIX=$(curl -s -H "x-maxy-key: $MAXY_API_KEY" "$BASE/account" | jq -r '[.keys[] | select(.kind == "publishable" and .revokedAt == null)][0].prefix')
curl -s -X POST "$BASE/keys/$PK_PREFIX/origins" -H "x-maxy-key: $MAXY_API_KEY" -H "content-type: application/json" \
  -d '{ "origins": ["https://app.example.com", "https://www.example.com"] }'
```

```json
{
  "prefix": "mxk_pk_test_ae1lJR",
  "origins": ["https://app.example.com", "https://www.example.com"],
  "note": "Applies within a minute."
}
```

## If a key leaks

1. Rotate it now, as above, and deploy the new key.
2. Revoke the leaked key.
3. Read `GET /usage` and `GET /orders` for calls and orders you did not make.
4. If a webhook secret leaked too, delete that endpoint and register a new one: [Webhooks](https://maxy.co/docs/webhooks).
5. Tell your Maxy contact, with the key's prefix and when it leaked.

A leaked publishable key needs only steps 2 and 5: make a new one with `POST /keys` and revoke the old. Every route on this page takes the secret key. Their full reference is on [Account routes](https://maxy.co/docs/account-routes).

---
Source: https://maxy.co/docs/key-security (Maxy Docs › Partners › Keys and access)
