Writing ·

How to rotate an expiring OpenAI project API key without downtime

Treat an expiring OpenAI project API key as a planned cutover: inventory consumers, create a scoped replacement before expiry, verify each workload after cutover, and revoke the old key only when the evidence is complete.

By Youssef Hemimy · OpenAI · API security · AgentOps

Treat an expiring OpenAI project API key as a planned cutover: inventory its consumers, create a scoped replacement before expiry, move and verify one consumer at a time, then revoke the old key. An expiry date is useful only when the replacement path is tested before it turns into a surprise outage. Calendars are not runbooks. Rude, but true.

A safe rotation retains an overlap only long enough to move and verify intended consumers; the old credential is revoked after evidence, not after optimism.

Start with the cutover boundary, not the new key

OpenAI recommends setting an expiration date for project API keys and establishing a regular rotation process. Its stated sequence is to create a replacement before the current key expires, update applications, verify the replacement works, and then revoke the old key. That is a controlled overlap, not an invitation to leave two credentials valid indefinitely.

Before creating anything, make a small inventory for the current key: the project, owner, expiry, intended workloads, secret-delivery path, deployment or restart path, and the evidence that proves a workload is using the replacement. Record identifiers and references—not key material. The operational question is not “did we make a new key?” It is “can every consumer switch without a blind spot?”

Choose an overlap window that has an exit condition

OpenAI documents maximum API-key lifetime controls at the organization and project levels, with a project limit unable to exceed the organization limit. Use that policy to force a predictable cadence. Then plan the actual overlap around your deployment and verification path—not around a hope that every process will reload a secret on its own.

ConditionSafe operating decisionEvidence to retain
A single service with a known deployment pathCreate the replacement, deploy it, and verify its intended API request before retiring the old key.Deployment version, replacement key identifier, and a successful non-destructive request.
Several independently deployed consumersCut over one named consumer at a time; do not revoke while an intended consumer has no recorded result.Consumer inventory and a verification result for each one.
A consumer only reads credentials at startupPlan the rollout or restart explicitly, then verify after that lifecycle event.The rollout record and post-restart verification.
An unknown or unowned consumer appearsPause revocation, contain the ambiguity, and establish ownership before extending the overlap.The unresolved consumer, owner, and the decision that paused revocation.

This separation matters when an organization also uses API-key-based cost attribution. A provider record can help narrow unexpected activity, but it is not proof of application cutover. Pair it with the workload evidence described in OpenAI API-key cost attribution.

Move one consumer at a time

  1. Assign the replacement key a documented purpose, owner, and expiry before distributing it.
  2. Update one named consumer through its approved secret-delivery path; never place the key in source control, logs, tickets, or test fixtures.
  3. Deploy or restart only as that consumer requires, then make a bounded request that demonstrates the intended integration works.
  4. Record the result against the consumer inventory and continue to the next one.
  5. Investigate unexpected old-key activity before revocation instead of interpreting it as a model or network mystery.

OWASP's secrets-management guidance treats creation, rotation, revocation, and expiration as distinct lifecycle activities. That is the useful mental model here: replacement creation is not completion, and revocation is a separate decision backed by evidence.

Verify the application, not just the secret store

A secret manager can report that a value changed while a long-lived process is still using what it loaded earlier. Verification should therefore cross the whole path: the intended workload received the replacement through the approved mechanism, the runtime applied it, and a bounded request succeeded under the expected project and permission boundary. Keep the check narrow and non-destructive.

For each consumer, retain enough evidence to answer later: which version deployed, when the request was verified, which key identifier it used, and who accepted the cutover. Do not make the credential itself part of the evidence. If a retry or rollback is possible, keep the action boundary equally explicit—the same discipline behind production agent tool contracts.

Revoke deliberately, then observe

Revoke the old key only after the inventory is complete and every intended consumer has a passing check. OpenAI's production guidance recommends revocation after verification; it also says API-key usage can be monitored once tracking is enabled. Use post-revocation monitoring to catch an overlooked dependency, with a documented recovery decision rather than a reflexive return to permanent dual credentials.

Keep the rotation record: old and replacement identifiers, planned expiry and revocation time, consumers, verification results, exceptions, and the final revocation decision. That record turns the next expiry from archaeology into maintenance. A delightful concept.

Run this pre-expiry drill

  • Confirm the inventory has an owner and a verification method for every intended consumer.
  • Create a short-lived test replacement through the same approved path.
  • Move one non-production or otherwise bounded consumer and verify the expected request.
  • Exercise the process recovery: restore the prior approved secret reference only if the new path fails, then record why.
  • Prove the old test credential can be revoked without leaving an untracked consumer.
  • Use the evidence to set a rotation window that is longer than the test but shorter than the lifetime policy.

Sources

FAQ

Should an OpenAI project API key have an expiration date?

OpenAI recommends setting an expiration date for project API keys and establishing regular rotation. The appropriate lifetime is an operating-policy decision: it must leave enough time to perform and verify a controlled replacement.

When should the old project API key be revoked?

After the replacement has been installed and verified for every intended application. OpenAI's production guidance gives the same sequence: create a replacement before expiry, update applications, verify it works, then revoke the old key.

Do maximum API-key lifetime limits rotate keys automatically?

No. OpenAI documents organization- and project-level maximum lifetime controls that limit how long new keys can remain valid. They are a governance boundary; each application still needs a tested replacement and cutover process.

Can an API-key usage dashboard prove a rotation is complete?

No. Usage tracking can help investigate which key is active, but completion needs application-specific evidence that each intended consumer is using the replacement and the old key can be revoked safely.

Building something that has to hold up?

We do this work for teams — agent reliability hardening, custom MCP servers, and full-stack AI systems built to survive production.