# Issue and revoke keys

> The command that creates, lists and revokes API keys.

Keys are managed with a command on the server that runs the API. There is no web page or endpoint for it, so only someone with access to the server can issue one.

How you run the command depends on how the API is deployed:

| Deployment | Command |
| --- | --- |
| Docker | `docker compose exec api node dist/cli/keys` |
| Built, without Docker | `npm run keys:prod --` |
| Local development | `npm run keys --` |

The examples below use the Docker form.

## Issue a key

Name the key for the client or environment it is for. The name is only a label for you.

```sh
docker compose exec api node dist/cli/keys create "Acme Re, production"
```

```
Key for Acme Re, production:

  twr_9cP0fK3...

Send it to the client now. It cannot be shown again.
```

Only a SHA-256 fingerprint of the key is stored. Send the key to the client over a channel you trust, and do not keep a copy.

Issue separate keys for a client's test and production systems, so one can be revoked without touching the other.

## See what has been issued

```sh
docker compose exec api node dist/cli/keys list
```

```
twr_9cP0fK3x  active   created 2026-11-16  last used 2026-11-17  Acme Re, production
twr_Lm2vQ8ay  revoked  created 2026-10-02  last used 2026-10-30  Acme Re, test
```

The first column is the start of each key, enough to tell them apart. "Last used" shows which keys are in use and which were never taken up.

## Revoke a key

Pass the prefix from the list:

```sh
docker compose exec api node dist/cli/keys revoke twr_9cP0fK3x
```

The key stops working on the next request. Revoking cannot be undone; issue a new key if it was a mistake.

## Replace a key

To rotate a key without an outage:

1. Issue a new key for the client.
2. Have them deploy it.
3. Watch "last used" on the old key stop advancing.
4. Revoke the old key.

## When a client asks for a key

The [Get an API key](https://towers.vinsa.dev/docs/start/api-key.md) page tells clients to write to **towers@vinsa.dev**. Set that address, and the API address quoted across this site, in `docs/site.config.mjs` or with the `TOWERS_KEY_CONTACT` and `TOWERS_API_URL` environment variables when building the site.
