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.
Part of the guide
OpenAIProject API key
- Where to issue a new one
- platform.openai.com/settings/organization/api-keys
- 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 checklistOn 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
- 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.
- In Crunu, replace
OPENAI_API_KEYin the environment that uses it, for exampleweb-app / production, and save. The environment gets a new version, and its history shows who changed the variable. - Restart the services that call OpenAI. Those started with
crunu run --restart on-changerestart themselves after the new version arrives; batch jobs pick it up the next time they start undercrunu run. - Send a real request with the new key, like the one below, and check your application logs for authentication errors.
- Revoke the old key in the dashboard. Requests that still carry it start failing within seconds.
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.
- OpenAI API reference: Overview and authentication · checked October 30, 2026
- OpenAI Docs: Production best practices · checked October 30, 2026
- OpenAI Docs: Manage permissions in the OpenAI platform · checked October 30, 2026