Skip to content
OpenAIProject API key

How to rotate an OpenAI API key

Reissue an OpenAI project API key: create the replacement in the same project, deploy it, confirm it works, then revoke the old key, which stops within seconds.

OpenAIProject API key

What a leaked key reaches
One project's API resources, within the permissions assigned to the key and, for a user-owned key, the project role of its owner.
Can be scoped
Yes

Keys can be limited to fewer permissions or resources.

Expires
Optional at creation; admins can enforce a maximum lifetime
Switching keys
Overlap windowRevokes at once

What Crunu does here

Crunu doesn't reissue keys at providers. It shows which values to replace and keeps the new one.

Build the list for a departure with the offboarding checklist
On this page

Create a new API key in the same project with the same permissions, deploy it, check that requests succeed with it, and only then revoke the old key. A project can hold several keys, so both work during the switch. OpenAI describes the same order for planned rotation: before a key expires, create a replacement, update your applications, and revoke the old key once you've verified the replacement works (OpenAI docs). Revocation is quick: the API reference says it takes effect within a few seconds (API reference).

Crunu doesn't create or revoke OpenAI keys and has no integration with the OpenAI platform. Its job is to show which OpenAI values a departing person received, to store the new key as a new version of the environment, and to restart the programs that read it.

Which OpenAI key you hold

OpenAI separates two kinds of credentials. A standard API key authenticates application requests. An Admin API key works with the Administration endpoints, which manage users, invites, projects, API keys and audit logs. An Admin key is the more dangerous of the two, so reissue it on its own, with fewer people involved.

Standard keys live in projects, and a project is the workspace for its keys, files and resources. Inside a project a key can be owned by a user or by a service account, which only organization owners and project owners can manage (permissions guide). Permissions are checked twice: for a request in a project, OpenAI takes the permissions assigned to the key and also checks that its user has a project role granting them. OpenAI's own example: the key must have api.model.read assigned, and its user must hold a project role with api.model.read.

Legacy user API keys may need the OpenAI-Organization and OpenAI-Project headers to choose where usage counts. If you still have one, a reissue is a good moment to replace it with a project key.

Reissue without downtime

  1. On the API keys page of the right project, create a new secret key with the same owner type, the same permissions and an expiration date. Copy it; you won't see it again.
  2. In Crunu, replace OPENAI_API_KEY in the environment that uses it, for example web-app / production, and save. The environment gets a new version, and its history shows who changed the variable.
  3. Restart the services that call OpenAI. Those started with crunu run --restart on-change restart themselves after the new version arrives; batch jobs pick it up the next time they start under crunu run.
  4. Send a real request with the new key, like the one below, and check your application logs for authentication errors.
  5. Revoke the old key in the dashboard. Requests that still carry it start failing within seconds.
Shell
crunu run --env web-app/production -- sh -c \
  'curl -s https://api.openai.com/v1/models -H "Authorization: Bearer $OPENAI_API_KEY"'

If the new key is restricted and has no permission to read models, use a request your application actually makes instead.

Keys that expire, and who may create them

OpenAI strongly recommends setting an expiration date on every project API key and keeping a regular rotation process. Administrators can enforce a maximum lifetime at organization or project level, and new keys must then expire within it.

API key governance adds a second control: administrators can allow only service account keys, allow only user-owned project keys, or stop new key creation altogether. Organization rules take precedence over project rules. These controls apply only to new keys, so existing keys still need a reissue to fall under them.

When to reissue an OpenAI key

  • Someone leaves. OpenAI's documentation doesn't say what happens to a user-owned key when its owner is removed, so don't rely on it. Revoke the keys they owned and reissue every shared key they could read. In Crunu, removing them produces a reissue checklist that names those variables, and Where to reissue links to OpenAI's key page for recognized OpenAI values.
  • A leak. Revoke the key at once. A few seconds later it's useless, and you deploy the replacement afterwards.
  • A schedule. An expiration date turns rotation into a routine you can't skip. OpenAI also advises reviewing keys regularly, removing unused ones and rotating sensitive ones.

Keep production on service account keys: a key that belongs to a person and their project role is tied to that person's membership. What to rotate when a developer leaves covers the full order of work, and the offboarding checklist builds the list for your stack. On the Crunu side, each saved version shows when the new key arrived; the key itself is always created and revoked in the OpenAI dashboard.

Frequently asked questions

Something else? Write to support@crunu.com

How quickly does a revoked OpenAI key stop working?

OpenAI's API reference says revocations of an API key take effect within a few seconds. Most other updates that change how a key authenticates, such as its permissions, propagate within 15 minutes.

Can OpenAI API keys expire on their own?

Yes, if you set an expiration date when you create a project API key, which OpenAI strongly recommends. Administrators can also enforce a maximum key lifetime for the organization or a project, and a project's limit can't exceed the organization's.

Should production use a personal key or a service account key?

A service account key. A user-owned key is tied to a person and that person's project role, while a service account belongs to the project. Administrators can even allow only service account keys for new key creation.

Does Crunu revoke OpenAI keys?

No. Crunu doesn't call the OpenAI API. It lists which OpenAI values a departing person received, stores the new key as a new environment version and lets crunu run restart the services that read it.

Sources

Every source this page relies on, with the date we last checked it.

  1. OpenAI API reference: Overview and authentication · checked October 30, 2026
  2. OpenAI Docs: Production best practices · checked October 30, 2026
  3. OpenAI Docs: Manage permissions in the OpenAI platform · checked October 30, 2026
  • Resend

    API key

    Expiry: None: a key stays valid until you delete it

    re_…Partly scoped

  • SendGrid

    API key

    Expiry: Not documented; treat the key as valid until you delete it

    SG.…Scoped keys

  • SSH

    SSH key pair

    Expiry: None for plain keys; expiry-time= or a certificate validity adds one

    Partly scoped

  • Stripe

    Secret API key

    Expiry: Until you expire or rotate it

    sk_live_…Partly scoped

  • Vercel

    Access token

    Expiry: Chosen at creation; the token stops working after that date

    vcp_…Scoped keys

  • Anthropic

    Claude API key

    Expiry: Chosen at creation: 3 hours to 30 days, custom or Never; fixed afterwards

    sk-ant-api…Partly scoped

Know which values to replace

Free during early access. When someone leaves, Crunu lists the values they received, changes the environment keys, and keeps each new value as a new version.