Where to find, rotate and revoke your OpenAI API key
A practical guide to managing OpenAI API keys: where to find them, which kind to use, how to swap one without breaking production, and how to shut one off fast.
Checked against these docs on 2026-11-19
Where to find your OpenAI API keys
Keys are managed in the OpenAI Platform dashboard, on the API keys page under your organization settings. OpenAI also has a separate API key management dashboard, where you can turn on usage tracking for keys created before 20 December 2023.
The Usage page shows activity per key once tracking is on. Untracked earlier usage shows as "Untracked".
Key types
Administrators can use API Key Governance in Platform settings to allow only service-account keys, only user-owned project keys, or to turn off new key creation. Organization rules override project rules, and they apply only to keys created after the rule is set. Admins can also set a maximum key lifetime; a project limit can’t exceed the organization limit.
- Project API keys that belong to a user. OpenAI recommends setting an expiration date when you create one.
- Service account keys. OpenAI recommends a project service account as an application’s identity, so access doesn’t depend on one developer’s key.
- Legacy user API keys. If you belong to several organizations or use one of these, you can send the
OpenAI-OrganizationandOpenAI-Projectheaders to say which organization and project a request counts against. - Short-lived access tokens from workload identity federation are also accepted as bearer credentials, instead of a long-lived key.
How to rotate an OpenAI key without downtime
OpenAI’s own sequence keeps the old key working until the new one is proven:
- Create a replacement key before the old one expires.
- Update your applications to use the new key.
- Check that the replacement works in production.
- Revoke the old key.
Because both keys are valid during steps 1 to 3, there is no gap. If the same key sits in several apps, update every one of them before step 4.
How to revoke an OpenAI key
Revoke a key from the API keys page. OpenAI’s API reference says revocations of an API key take effect within a few seconds, so anything still using it will start failing almost immediately. Revoke only after the replacement is live, unless the key is compromised.
What happens if an OpenAI key leaks
OpenAI API keys are covered by GitHub secret scanning. GitHub’s list of supported patterns shows the OpenAI API key as a partner pattern with push protection and a validity check, and partner alerts go to the provider. That means a key committed to a public repository can be detected, but it is not a substitute for your own response.
OpenAI’s documentation we checked doesn’t describe automatic revocation of leaked keys, so don’t rely on it. Treat a leaked key as compromised: create a replacement, deploy it, then revoke the leaked key, and check the Usage page for activity you don’t recognise.
Recommended rotation practice
- Set an expiration date on every project key you create, and put the date in a place your team will see.
- Use a project service account for production apps, not a person’s key.
- Keep keys on the server and load them from an environment variable or a key management service. Never ship them in browser or mobile code.
- Keep keys out of source code and public repositories.
- OpenAI doesn’t publish a fixed rotation interval in the docs we checked, so pick your own (for example, rotate on expiry and whenever someone with access leaves) and write it down.
Sources
Everything above comes from these pages. Providers change their dashboards, so check them for the latest. KeyAtlas is not affiliated with OpenAI.