How to Keep an OpenAI API Key Safe and Limit Surprise Bills
· 6 min read
To keep an OpenAI API key safe, treat it like a password that can spend money: keep it out of published code, browsers and chats, store it in an environment variable or a secrets manager, give each project its own key and set a hard spend limit. If a key leaks, revoke or replace it first, then read your usage.
This guide covers keys for OpenAI's API, not the ChatGPT app. For the app, read what ChatGPT is. Sources, read on 2 December 2026: OpenAI's Help Center (relative update times only), its developer docs, the Terms of Use ("Effective: January 1, 2026"), the Services Agreement ("Updated: December 1, 2025" and "Effective: January 1, 2026"), GitHub's documentation, the OWASP Secrets Management Cheat Sheet and the NCSC page Secure your development environment, published 20 February 2019. Nobody on our side has created, used or tested an OpenAI key, so we describe the dashboard only as the pages do.
Where should an OpenAI API key live, and where must it never go?
OpenAI's key safety article says a compromised key lets someone use your account quota without consent, which can mean unexpected charges and interrupted access. Keep the key out of these places:
- Published code. The article calls committing a key to source code a common route to compromise: a public repository can share it with the internet, and a private one can still leak it.
- Browsers, apps and logs. The article says a key in client-side code lets malicious users take it and make requests on your behalf; the API keys guide adds logs and customer-facing responses.
- Chats, tickets and screenshots. This one is our advice: treat a pasted key as exposed, as the AI assistant privacy checklist does.
The API reference says to load keys from an environment variable or a key management service on the server. The key safety article's setup steps for Windows, Linux and macOS set an operating-system variable named OPENAI_API_KEY, for example OPENAI_API_KEY=YOUR_KEY_HERE, a placeholder for your real key. Using a project file instead is our addition: keep it out of version control and check that your tooling reads it.
The OWASP cheat sheet, a general source rather than OpenAI's, advises avoiding environment variables for secrets where feasible and names process listing and diagnostic logs as exposure routes; OpenAI's pages describe the environment-variable setup, so weigh the two.
How do I rotate keys and split them by project?
OpenAI's Help Center article Can I share my API key with my teammate/coworker? does not recommend sharing even a personal key with trusted coworkers and recommends distinct keys per project, with isolated rate limits and spend controls.
The key safety article strongly recommends giving project keys an expiration date plus regular rotation. The API keys guide's rotation steps: issue a replacement, update the workload, verify it, revoke the previous key. The key safety article also describes IP allowlisting, which rejects requests from other addresses even with a valid key; the API keys guide says key scopes can restrict a key.
The pages word sharing differently. The key safety article says sharing API keys is against the Terms of Use. The Terms of Use say you may not share your account credentials and that their Business Terms govern APIs; that link opens the page titled OpenAI Services Agreement. That agreement bars sharing account access credentials between multiple users (section 3.1) and buying, selling or transferring API keys with a third party (section 3.3(g)). We cannot tell how these fit; read the agreement you accepted.
The safe workflow for AI coding assistants covers scoped, revocable test keys.
Which OpenAI spend limits stop a runaway bill?
A hard limit does; an alert does not. The spend limits guide says: "Spend alerts do not enforce a cap." A hard spend limit makes affected requests return a 429 error once tracked spend reaches it. That guide and the key safety article both say enforcement is not instantaneous, so spend can slightly exceed the limit, and a hard limit can interrupt production traffic.
OpenAI's prepaid billing article says auto-reload is turned on by default during setup and that the prepaid balance is not an instantaneous spending cutoff. The spend limits guide says OpenAI separately assigns each organization an approved monthly usage limit by usage tier; the prepaid article describes an optional monthly reload limit that it says is not an API usage limit. The pages we read do not say whether a new account starts with a spend limit, so check yours.
What should I do first if my OpenAI API key leaks?
Revoke or replace first, then investigate. OpenAI's article Keeping your OpenAI account secure lists that order under "Revoke an exposed API key": delete the key, review usage and keep the details, contact OpenAI Support. GitHub, OWASP, the key safety article and the NCSC page also say to revoke or rotate compromised credentials.
- Revoke or replace the key. The key safety article says to rotate it immediately from the API Keys page and update production applications. The API reference says revocations take effect within a few seconds; other updates to a key can take longer.
- Read your usage. OpenAI's usage article says to confirm the organization, project and period, narrow by API key and model and compare with your application logs.
- Ask support, without the key. The usage article says to send OpenAI Support the UTC period, organization and project IDs, the key identifier and screenshots or logs, never the secret key.
- Clean the repository second. GitHub's documentation says revoking or rotating a secret comes first and may be enough, and commits can stay reachable through forks and cached views.
GitHub says its secret scanning notifies a provider whose credentials it finds in a public repository so the provider can take action such as revoking them, and its supported patterns include an OpenAI key. OpenAI's account-security article says: "When OpenAI detects an API key on the public internet, or leaked inside an app in an app store, the API key is disabled immediately." The pages we read do not say how OpenAI finds keys, whether it tells you, or what happens to a key exposed anywhere else, so revoke yours without waiting.
Who pays if someone else uses my key?
We cannot say. The Services Agreement says the customer is responsible for all activities that occur under its Account (section 3.2), that fees are non-refundable except as required by law or as otherwise specifically permitted (section 6.1), and that the customer will promptly notify OpenAI of unauthorized access to the Account or the Services (section 3.1). The prepaid billing article says used credits may qualify only for confirmed unauthorized use or a verified billing correction.
A separate article on fraudulent credit purchase charges says OpenAI can review refund eligibility, that unauthorized charges must be validated and that you should contact your bank or card issuer. It concerns purchase charges, and none of the three pages says whether a leaked-key charge counts as unauthorized use. So ask OpenAI Support and do not assume a refund. This is not legal advice, and rules differ by place.
Where NAMELESS stands
This guide has nothing to say about NAMELESS, which is not available and has no launch date. It is our own AI model, built on its own architecture and still in training; extremely fast replies and stronger logic and reasoning are goals, not results. Join the waitlist.
Product and company names in this article belong to their owners and are used only to describe them. NAMELESS is not affiliated with or endorsed by them.