Skip to content

API key rotation: how often, and a procedure that does not cause an outage

Rotate keys on a schedule and immediately after exposure. A two-key procedure, an inventory, and what to automate. Works for tool and agent keys too.

Published by Contextingo.

A key that never changes is a key that is probably known to someone who left. Rotation limits how long a leaked key is useful.

When to rotate

  • At once when a key may have been exposed: pasted in a chat, committed, logged.
  • When someone with access leaves the team.
  • On a schedule that matches the risk, for example every few months for powerful keys.

A procedure without downtime

  1. Create the new key next to the old one.
  2. Deploy the new key to every place that uses it.
  3. Check from logs that the old key is no longer used.
  4. Revoke the old key.
  5. Record the date and the next rotation.

Make it easier

  • Keep an inventory: what the key is for, who owns it, where it is stored.
  • Give each service its own key, so revoking one does not break the rest.
  • Scope keys narrowly and set low limits on development keys.
  • Store keys in a secret manager and read them at run time.

Personal keys for agents

In Contextingo each person connects Claude Code or Codex with their own personal key, which can be revoked on its own. Related: keeping secrets out of the agent’s context.

Questions

Good to know.

How often is often enough?

There is no universal interval. Match it to what the key can do, and always rotate after exposure.

Is deleting the commit enough after a leak?

No. Assume the key was copied, and rotate it.

Nothing learned is lost. Nothing unchecked is done.