OpenAI API Key: Get One, Store It, Fix 401 and 429

In brief

You get an OpenAI API key on the API keys page of platform.openai.com, and it works once you add prepaid credit: the minimum purchase is $5, as of November 2026. ChatGPT plans are billed separately and carry no key. Copy the key when it appears, because you cannot count on seeing it again.

How do I get an OpenAI API key?

Paste this into Claude, ChatGPT, Gemini or Whizi, fill the brackets, and it writes the setup for your own system. Never paste a real key into it.

An old brass key resting on a closed black leather notebook on a black plinth, with a fine thread running to a brushed silver OpenAI knot on its own plinth, in a charcoal studio under white rim light.

I want an OpenAI API key for [what I am building, such as a Python script or a Zapier flow]. I use [Windows, Mac or Linux] and [language or tool]. Walk me through creating the key on platform.openai.com, adding billing, storing it as an environment variable and testing it with one call. I will not paste my key here, so tell me where to check it myself.

Here are the steps as OpenAI's own pages describe them, read on 22 November 2026.

  1. Sign in or sign up at platform.openai.com. This is the API platform, not chatgpt.com.
  2. Open the API keys page at platform.openai.com/api-keys and choose Create new secret key.
  3. Name the key and select a project.
  4. Copy it at once and store it in a password manager or an environment variable.
  5. Add payment details and buy credit (the next section has the numbers).
  6. Send one small test call.
  7. Set a monthly spend limit and an expiry date.

A first time account may be asked to create an organization before the key page opens, according to XRAY's November 2026 guide. The Medium guide that ranks second, from August 2025, stops after step 4 and never mentions billing. That gap is where a new user hits a billing error on the first call.

Do I need to pay before an OpenAI API key works?

Yes, for real use. OpenAI says new API accounts use prepaid billing, so you buy credit first and each call draws the balance down. Its billing page sets a $5 minimum purchase and a $10 default, and it turns on auto reload by default during setup. Turn that off if you don't want automatic credit purchases.

Three more facts from that page matter. Purchased credits expire after one year. They can't be refunded unless the law, a contract or an approved exception applies. And a zero balance isn't an instant stop: "Do not rely on the prepaid balance as an instantaneous spending cutoff." Usage in that delay can show as a negative balance, which comes out of your next purchase.

If your account has free credits, they are used before purchased ones. OpenAI's page doesn't say how a new account gets any, so don't plan around them. Beware sites that sell or give away keys, since OpenAI says sharing keys is against its Terms of Use.

Why does my OpenAI API key return a 401 or 429 error?

A 401 means OpenAI rejected the key or the organization behind it. A 429 means a limit stopped the request, and the limit may be money or speed. OpenAI's error page lists four 401 messages and six 429 messages, read on 22 November 2026.

Three of OpenAI's six 429 errors are about money, not speed
Moneycredit balance, organizationspend, project spend3 of 6Speedtoo many requests, slow down2 of 6Usage capset by OpenAI foryour organization1 of 6one square is one documented 429 message
ErrorOpenAI's stated causeFix
401 Incorrect API key providedThe key is not correctCheck the key, or generate a new one
401 Invalid AuthenticationWrong key or wrong requesting organizationUse the right key and organization
401 You must be a member of an organization to use the APIYour account isn't part of an organization, for example after being removedAsk to be invited to an organization, or have a project owner add you
401 IP not authorizedYour IP isn't on the project or organization allowlistSend from an allowed IP or update the list
429 credit_balance_exhaustedNo prepaid credit leftAdd credit
429 Rate limit reached for requestsYou are sending requests too fastPace requests and follow the Retry-After header
429 organization_spend_limit_exceeded or project_spend_limit_exceededAn enforced spend limit was reachedRaise or remove that limit

The first day trap is a 429 that has nothing to do with speed. OpenAI says retrying a billing, spend or quota error won't restore access, so pacing your calls does nothing. Add credit or raise the limit, then give the balance a few minutes to update.

Tokens drive both cost and limits, and what tokens are explains them.

Is an OpenAI key the same as a ChatGPT login?

No. ChatGPT and the API platform have separate billing systems, and API credits belong to an API organization, not to your ChatGPT subscription, according to OpenAI's billing page. When a guide says OpenAI key, it means the secret key from the API keys page. ChatGPT API vs subscription compares what each costs for the same work.

RouteKey neededHow it is billedFree creditBest at
OpenAI API platformYes, a project keyPrepaid credit, $5 minimum, credits expire after one yearUsed first if your account has anyBuilding your own app or script
ChatGPT Free, Plus or ProNoA separate ChatGPT billing systemNot applicableChatting in the app
ChatGPT Pro or Business creditsYes, in the linked API organizationPro tiers get $100, $200 or $500 a month, Business $20 per Standard seat and $100 per Premium seatYes, after 7 days of paid subscription; Plus and free trials don't qualifyPro and Business users who also build
Existing monthly billing accountYesCredits bought in advance offset the monthly invoiceNot statedTeams already invoiced
WhiziNoFree plan or a paid plan, no API billing account10 messages a day on the free plan, no cardUsing several models in one app

Whizi loses in one case: if you need to call a model from your own code, a Zapier flow or another app, you need the key, and Whizi isn't a substitute. The Pro and Business credits are capped at $500 a month for a Business workspace. For a plain chat, a key and a billing account are more setup than the job needs.

What is a project key, and which kind should I create?

A project key is a secret key that belongs to a project inside your OpenAI organization. For your own scripts and experiments, create a user owned project key. OpenAI's key guide says such a key acts with its owner's access.

A deployed app, a scheduled job or a CI workflow should use a service account and its key instead. The same guide says not to use one developer's identity as the permanent identity of a production app. An Admin key is a third kind, meant only for managing projects and keys. Scopes can restrict what a key does, but they can't grant more than its owner has.

How do I store an OpenAI API key safely?

Keep it in an environment variable and nowhere else. OpenAI recommends the name OPENAI_API_KEY, and its quickstart says each OpenAI SDK reads the key from the system environment by itself. On Windows, run setx OPENAI_API_KEY "your_api_key_here" and open a new prompt. On a Mac or Linux, add export OPENAI_API_KEY="your_api_key_here" to your shell file.

Four rules from OpenAI's key safety page cover most leaks. Never put the key in code that runs in a browser or mobile app: "Never deploy your key in client-side environments like browsers or mobile apps." Never commit it to a repository, even a private one. Give each team member their own key, since OpenAI does not support the sharing of API keys. Set monthly spend limits with hard enforcement, which can block real requests but caps the cost of a leak.

The page lists eight practices in all. The rest are expiry dates with rotation, a key management service for production, IP allowlisting and watching the Usage page.

What should I do if my OpenAI API key leaks?

Replace it first and investigate second. OpenAI says to rotate the key immediately from the API keys page if you think it has leaked, and that a compromised key can cost you data, charges and your monthly quota.

  1. Create a new key in the same project.
  2. Put the new key in your app and check that it works.
  3. Revoke the old key.
  4. Open the Usage page and look for calls you didn't make.
  5. Set a hard spend limit if you hadn't.
  6. Contact OpenAI through help.openai.com if the usage looks wrong.

One more rule is our advice, not OpenAI's: treat a key as exposed the moment it appears in a public repo, a screenshot or a chat transcript, even if you delete the file. Deleting the line doesn't unpublish copies that someone has already pulled.

What do real key problems look like?

These three cases are written for this page. Each shows the prompt and what a good answer must contain. They are examples, not tested output from a named model.

Case 1, a 401 on the first call. Prompt: "My Python script returns 401 Incorrect API key provided. I set OPENAI_API_KEY in one terminal and run the script in another. List the three likeliest causes with one check each. I will not paste my key." A good answer says setx only reaches new prompt windows, a key from another organization fails, and a new key is the clean fix.

Case 2, a 429 minutes after buying credit. Prompt: "I bought credit and still get a 429. Here is the error code: [paste code, no key]. Tell me whether this is rate, spend or balance and what to do." A good answer separates credit_balance_exhausted from a rate limit, says retrying won't help a billing error, and tells you to wait a few minutes for the balance.

Case 3, a key pushed to a public repo. Prompt: "I pushed a file with my OpenAI key to a public repository an hour ago. Give me the order of steps, with the first one being the one that stops the damage." A good answer starts with creating a new key and revoking the old one, then the Usage page and a spend limit, and only then cleaning the repo.

What prompts help when I work with an OpenAI key?

Use these twelve with any chatbot. Replace the brackets with details, and never include the key itself.

Setup

  1. Pick a project name: "Suggest a project and key naming scheme for [number] apps I run, so I can tell which key to revoke if one leaks."
  2. Write the test call: "Write the smallest [Python or JavaScript] script that reads OPENAI_API_KEY from the environment and sends one short request, with the error handling for 401 and 429."
  3. Explain the billing page: "Explain prepaid billing, auto reload and a monthly recharge limit in plain words, then tell me which settings to choose for a hobby project."

Safety

  1. Build a checklist: "Make a key safety checklist for [my setup], with one line per risk and one check I can run for each."
  2. Write the ignore rule: "Write a .gitignore and a .env.example for a [language] project that uses one OpenAI key."
  3. Review my code: "Here is a file with the key replaced by [REDACTED]: [paste]. Point to any line that would expose a key in a browser, a log or a repository."
  4. Plan rotation: "Give me a 4 step routine to replace a key without downtime for [my app]."

Errors

  1. Read the error: "Here is the error text with no key in it: [paste]. Say what caused it, using OpenAI's documented meaning, and the first fix to try."
  2. Add retries: "Add retry with backoff to [my function] for 429 rate errors, and make it stop at once for billing errors."
  3. Tell the cases apart: "Write a function that reads an OpenAI error code and returns rate, balance, spend or key, with a one line fix for each."

Cost

  1. Estimate a run: "I will send [number] requests of about [words] words in and [words] out on [model]. Show the arithmetic for the cost, and say which price page to read."
  2. Cap the spend: "Suggest a monthly spend limit for [use case] and the alert I should set below it."

What mistakes ruin an OpenAI key setup?

Five mistakes cause most of the pain, and each has a fix.

  1. Pasting the key into a chat or a ticket. The fix: paste the error text and swap the key for [REDACTED].
  2. Assuming ChatGPT Plus includes API access. The fix: set up API billing separately, as OpenAI's billing page says.
  3. Sharing one key across a team. The fix: invite each person to the organization so they get their own.
  4. Putting the key in front end code. The fix: send calls through your own server.
  5. Skipping the spend limit. The fix: set it before the first real call, and remember a zero balance isn't an instant cutoff.

A sixth is subtler. Dashboard paths move: OpenAI's own pages link both platform.openai.com/api-keys and platform.openai.com/settings/organization/api-keys. If a guide's menu names don't match your screen, follow the link on OpenAI's docs.

Where does Whizi fit if I only want to use the models?

Whizi is one app instead of a pile of single purpose tools. You don't create a key, add a billing account or watch a rate limit tier, because the models are already inside the app. Pro carries Claude, GPT and Gemini in one app, and its first week is $1.99. The free plan gives 10 messages a day on Whizi AI, Auto and Claude Haiku, with no card.

Web search is on by default in each chat, and you can upload a PDF, Word file or Excel file to ask about it. Excel and Word files made in chat have no plan gate, so prompt 4 can come back as a Word checklist or an Excel rotation schedule. Side by side Compare puts two models on one prompt on Pro and Powerhouse, which suits a second opinion on an error. See Whizi pricing for what each plan holds.

Whizi loses if you want to call a model from your own code. Best BYOK AI chat apps covers chat apps that take your key.

Where does AI get API key advice wrong?

It can invent a menu name, a model name or an error code, because dashboards and docs change faster than training data. OpenAI's billing and error pages were updated within the last two weeks before this page was written, and a chatbot may repeat an older version.

It also can't protect a key you paste. A chat transcript is one more place a key can sit, so keep the key out of every prompt. For anything that spends money, check the answer against OpenAI's own docs, listed under the sources below.

Workflow checklist
  • Create the key in a named project and copy it once
  • Store it as OPENAI_API_KEY, never in browser, mobile or repository code
  • Add prepaid credit and turn auto reload off if you want a hard budget
  • Set a monthly spend limit and an expiry date
  • Keep the key out of every chat prompt
Common questions

Frequently asked questions

Can I get an OpenAI API key for free?

You can create a key without paying, but real use needs credit: OpenAI's billing page sets a $5 minimum purchase, as of November 2026. Free credits, if your account has any, are used first. Eligible ChatGPT Pro and Business subscribers can also claim API credits after 7 days of paid subscription.

Is an OpenAI API key the same as my ChatGPT account?

No. ChatGPT and the API platform have separate billing systems, and API credits belong to an API organization, per OpenAI's billing page. Your ChatGPT login opens chatgpt.com, and the key comes from platform.openai.com.

How much will my first API calls cost?

It depends on the model and on how many tokens you send and receive, so read OpenAI's pricing page for the model you pick. The token counter shows the token count of a prompt and an estimated API price before you send it.

Can my whole team share one OpenAI API key?

No. OpenAI does not support the sharing of API keys and says sharing is against its Terms of Use. Invite each person from the Members page so they get their own key, and use a service account for a deployed app.