# Keys and rotation

> How a key acts as its maker, how long it lives, what ends it early, and how to rotate keys without stopping your work.

Markdown twin of https://panlytics.net/developers/security/keys (last updated 2026-10-27). Every page of the Panlytics developer docs is listed at https://panlytics.net/developers/llms.txt, and all of them are in one file at https://panlytics.net/developers/llms-full.txt. The site guide is https://panlytics.net/llms.txt.

## What a key is

A key is a long secret that starts with `pan_`. A program sends it in the `Authorization` header of every call:

```http
GET /api/v1/me HTTP/1.1
Host: panlytics.net
Authorization: Bearer pan_...
```

The key acts as the person who made it, in the company it was made in. Every call runs through the same checks the person's own pages use, with the person's role read fresh on each call, and then the fence on top. Whatever the key does is recorded under the person's name and marked as done with a key. In the audit log it reads "name (AI key)".

Panlytics never stores the key itself. It keeps a keyed fingerprint (an HMAC: a hash that also needs a secret only the server holds), so a copy of the database is not a copy of anybody's keys. That is also why the key is shown only once.

## Who may make one

Two things must be true:

1. **Developer mode is on** for the company. The CEO presses **Turn on** on the **Connect an AI** card.
2. **The person's role holds "Make keys for programs and AI agents".** The CEO holds it. Only the CEO can put it on another role.

Making a key also needs a **recent sign-in**: if you signed in a while ago, Panlytics asks you to confirm with your passkey, or with a code, first. A key can never make another key, so a program can never renew its own access.

Each person may hold **five live keys** at once. Pressing **Connect again** revokes your earlier key if no AI has used it yet.

## How long a key lives

A key ends **1 to 5 hours** after it is made. The CEO chooses the period for the whole company, and one hour is the default. Shortening the period shortens every live key at once; lengthening it only affects keys made afterwards. No key ever works longer than five hours, whatever the setting says.

The end is a fixed moment, in `key.endsAt` from `GET /v1/me`. Using a key does not extend it.

When a key reaches its end, its maker is told once, in the bell.

## What ends a key early

| What happens | Which keys end |
| --- | --- |
| The maker presses **Disconnect** on the **Connect an AI** card | That key |
| The maker presses **Connect again** before any AI used the key | That unused key |
| The CEO presses **Revoke** under **Live keys** in the Developer settings | That key |
| The CEO presses **Turn off** in the Developer settings | Every key in the company |
| The CEO shortens the period | Every key older than the new period |
| The maker is removed from the company | The maker's keys in that company |
| The maker is switched off or banned | Every key the maker holds |
| The maker changes their password and signs out other devices, or signs out everywhere | Every key the maker holds |
| The maker's role loses "Make keys for programs and AI agents", or the maker moves to a role without it | Every key the maker holds in that company, revoked at once |

An ended or revoked key answers `401` with the code `api.key_refused` on every call. The card then says **Access ended**, and **Live keys** lists only keys that still work.

## Rotating keys

Because a key ends within hours, rotation is part of normal work rather than an emergency.

1. When the card says **Access ended**, press **Connect again**, then **Copy prompt**.
2. Give your program or agent the new key.
3. To end a key early, press **Disconnect**.

For a program that runs on a schedule, connect at the start of each run and let the key end afterwards. For an agent, see [When the key ends](https://panlytics.net/developers/connect-an-ai-agent#when-the-key-ends).

> [!WARNING]
> If a key leaks, press **Disconnect** at once. A CEO who cannot reach the maker can press **Revoke** under **Live keys** in the Developer settings, or press **Turn off** to end every key.

## Keeping a key safe

- Put the key in an environment variable or your platform's secret store, never in a file that is committed.
- Never log it, print it or send it in a URL. Panlytics reads it only from the `Authorization` header.
- Give each program and each agent its own key, so you can end one without stopping the others.
- A key starts with `pan_`, which secret scanners look for. If one is found in a repository, revoke it.
