Providers / OpenAI API
AI APIs
OpenAI API API keys and credentials
What every OpenAI API credential a founder holds does, whether it expires, and what tends to break. Each fact links to OpenAI API's own docs.
At a glance
| Credential | Expiry | Permissions |
|---|---|---|
| Project API key (sk-proj-...) | You choose | Not documented |
| Project service account API key | You choose | Not documented |
| Admin API key | You choose, max 1 year | Full access only |
| OpenAI platform account login | Not documented | – |
How to rotate the OpenAI project API key
- Issue a replacement key before the old one expires, with an expiration that complies with your organization and project key policies. OpenAI API docs
- Update the workload (environment variable or secret store) to use the replacement key. OpenAI API docs
- Verify that the replacement works. OpenAI API docs
- Revoke the previous key. The API reference documents deleting a project key with DELETE /organization/projects/{project_id}/api_keys/{api_key_id}; it requires permission to write project API keys. OpenAI API docs
Can the old and new key work at the same time? OpenAI API's docs don't say. The docs give the order issue, update, verify, then revoke, which implies the old key keeps working until you revoke it, but they never say so explicitly.
Revoking the old one: Revoke the old key. The API reference documents deleting a project key with DELETE /organization/projects/{project_id}/api_keys/{api_key_id}, which requires permission to write project API keys.
Source: developers.openai.com/api/docs/guides/api-keys, checked
Does the OpenAI project API key expire?
It's up to you: you can set an expiry for the OpenAI project API key.
What breaks when the OpenAI project API key expires
Per OpenAI's error codes guide (https://developers.openai.com/api/docs/guides/error-codes): it documents a 401 "Incorrect API key provided" error for a key that is not correct (a revoked key cached locally is one cause) and a 401 "Invalid Authentication" error for a revoked key. The Python library's AuthenticationError covers a key that was "invalid, expired, or revoked". The docs do not name a separate error for an expired key, so expiry and revocation may look the same. You would notice it as every request using that key failing with a 401 at once; no expiry warning is documented.
Other things that often go wrong with OpenAI API:
- Project key set to expire and requests start failing with an auth error; no key-level rotation alerts are documented
- Organization or project maximum key lifetime may force shorter keys than the application was built for
- Existing keys created before a policy change are not affected, so expiry dates do not apply retroactively
- Keys created before Dec 20, 2023 are untracked for usage by default
- Admin key secret is shown only once on creation
How to rotate the OpenAI service account key
- Create a replacement key for the existing service account (POST /organization/projects/{project_id}/service_accounts/{service_account_id}/api_keys). The reference example authenticates with an admin key. Set expires_in_seconds within your policy; the documented range is 1 to 31536000 (one year). The response reports expires_at as null if the key does not expire. OpenAI API docs
- Store the new key value straight away. The API returns the full value only when the key is created. OpenAI API docs
- Update the workload to use the new key and verify that it works. OpenAI API docs
- Revoke the previous key. The service account itself stays the same, so only its keys change. OpenAI API docs
Can the old and new key work at the same time? OpenAI API's docs don't say. The docs say a service account's identity can remain the same while its keys change, and give the order issue, update, verify, revoke. They do not state whether several keys on one service account are valid at once, nor any limit on the number of keys.
Revoking the old one: DELETE /organization/projects/{project_id}/api_keys/{api_key_id} deletes the key and requires permission to write project API keys. Deleting a service-account key does not delete the service account or its other keys.
Source: developers.openai.com/api/docs/guides/api-keys, checked
Does the OpenAI service account key expire?
It's up to you: you can set an expiry for the OpenAI service account key.
What breaks when the OpenAI service account key expires
Per OpenAI's error codes guide (https://developers.openai.com/api/docs/guides/error-codes): it documents a 401 "Incorrect API key provided" error for a key that is not correct (a revoked key cached locally is one cause) and a 401 "Invalid Authentication" error for a revoked key. The Python library's AuthenticationError covers a key that was "invalid, expired, or revoked". The docs do not name a separate error for an expired key, so expiry and revocation may look the same. You would notice it as every request using that key failing with a 401 at once; no expiry warning is documented.
Each credential
Project API key (sk-proj-...)
- You choose
- Expiry readable by API
OpenAI recommends setting an expiration date when creating a project API key. Admins can enforce a maximum key lifetime at organization or project level; project limits cannot exceed the organization limit, and new keys must expire within the configured limit. Existing keys are not affected by new policies. The project API keys list endpoint (confirmed on the API reference) returns expires_at (Unix seconds, null if no expiry), last_used_at and a redacted_value only; the full secret is not returned. Listing requires an admin key. Keys can be restricted by admin policy to service-account keys or user-owned keys, or creation can be disabled.
Project service account API key
- You choose
OpenAI recommends a project service account for an application identity rather than an individual developer's key. When an organization policy sets a maximum lifetime, the initial service account key's expiration must be supplied and must not exceed that limit. Policy values were not published as a fixed number.
Admin API key
- You choose, max 1 year
- Full access only
- Expiry readable by API
Created in the organization admin keys page or via API. The create endpoint takes optional expires_in_seconds, minimum 1 and maximum 31536000 (365 days); omitting it creates a key that does not expire, so the default is no expiry. The secret value is only shown on create. Create and list responses include expires_at (nullable) and last_used_at. Admin keys authenticate the Usage/Costs and admin endpoints as Bearer tokens. No permission scopes are documented for admin keys. Treat as a root credential.
OpenAI platform account login
- Not documented
Dashboard login at platform.openai.com. Owners manage members and keys; readers can make API requests but not manage members.
Renewals and billing
Admin API Organization Costs endpoint (GET /v1/organization/costs) reports daily spend. group_by supports project_id, api_key_id, user_id, line_item, api_source; filters project_ids and api_key_ids. Requires an admin key (Bearer).
Where to find it in OpenAI API
What OpenAI API's docs don't say
We couldn't confirm these from official docs, so don't rely on them either way:
- Whether a restricted admin key can be read-only and cannot write (not confirmed)
- Default and maximum lifetime for project API keys (only organization-configurable policy is documented, no number)
- Whether project keys support permission scopes (documented as project-level only)
- Dashboard session lifetime and billing or prepaid credit terms
- Costs endpoint rate limits and pagination limits beyond the documented limit range
- Admin API key list response does not show scopes; permission check method unknown
Rotating or replacing a OpenAI API key
The steps are the same for most providers: make the new key, deploy it everywhere the old one is used, check it works, then revoke the old one. Our guides walk through it:
Sources
- developers.openai.com/api/docs/guides/production-best-practices
- developers.openai.com/api/reference/resources/admin/subresources/organization/subresources/admin_api_keys/methods/create
- developers.openai.com/api/reference/resources/admin/subresources/organization/subresources/projects/subresources/api_keys/methods/list
- developers.openai.com/api/reference/resources/admin/subresources/organization/subresources/usage/methods/costs
- developers.openai.com/api/reference/resources/admin/subresources/organization/subresources/admin_api_keys/methods/list
- developers.openai.com/api/docs/guides/api-keys
- developers.openai.com/api/docs/guides/error-codes
- developers.openai.com/api/reference/resources/admin/subresources/organization/subresources/projects/subresources/api_keys/methods/delete
- developers.openai.com/api/reference/resources/admin/subresources/organization/subresources/projects/subresources/service_accounts/subresources/api_keys/methods/create
Related providers
Keep track of every OpenAI API key
StackHangar stores your OpenAI API keys in an encrypted vault, grouped by the product they belong to, warns you before they expire, and walks you through rotating them. We can't read your secrets.