How to get a ChatGPT (OpenAI) API key
Create an OpenAI API key, store it as an environment variable on Mac or Windows, test it with one command, and know what it costs.
Short answer
Make it on the API Platform, not in ChatGPT.
A ChatGPT API key is an OpenAI API key. You create it on the OpenAI API Platform under API Keys with Create new secret key, and you see the full key only once. OpenAI bills the API separately from ChatGPT, so Plus does not cover it; new accounts prepay credits, from $5.
$5prepaid
Plus not includedCreate your OpenAI API key and test it
Start with Create to make the key. Then pick your computer to store it as an environment variable and run one test request. The steps follow OpenAI’s own help pages as of November 6, 2026.
- 01Go to platform.openai.com and sign in, or create an OpenAI account if you have none. You can use the same email as your ChatGPT account, but billing is separate.
- 02Open the project selector at the top and pick a project. Every organization has a Default project; select Create project for a new one.
- 03Open Settings, select the project, then API Keys. The address platform.openai.com/api-keys opens the same page.
- 04Select + Create new secret key. Name it and pick permissions: All (the default), Restricted or Read Only. Set an expiration date if you can.
- 05Copy the key at once. OpenAI shows the full secret key only when you create it; if you lose it, create a new one.
- 06In Settings, open Billing, select Add payment details and buy credits: $5 minimum, $10 by default. Use auto-reload is on by default; turn it off if you want no automatic top-ups.
Now pick Mac or Linux, or Windows, above to store the key and check that it works.
- 01Open Terminal. Copy the command below, replace your-key-here with your key, keep the quotes, and press Enter.
- 02Run the test request in the same window. A list of models means the key works; an error with 401 means the key is wrong.
- 03The export line lasts for this window only. To keep it, add the same line to the file .zshrc in your home folder (.bash_profile if you use bash), then run source ~/.zshrc.
- 01Open Command Prompt. Copy the command below, replace your-key-here with your key, keep the quotes, and press Enter.
- 02Close the window and open a new one: setx saves the key for future windows, not the current one. Type echo %OPENAI_API_KEY% to check.
- 03Run the test request in the new window. A list of models means the key works; an error with 401 means the key is wrong.
You can also add it by hand: System properties, Advanced system settings, Environment Variables, then New under User variables, with the name OPENAI_API_KEY.
How to get a ChatGPT API key on the OpenAI platform
There is no separate ChatGPT API key. The key people search for under that name is an OpenAI API key, and it lets your own code, scripts and apps call the same models through the OpenAI API. It is a secret credential: every request carries it, and OpenAI uses it to know which organization and project to bill.
The key lives inside a project. OpenAI’s help page on projects says each project has its own API keys, under Settings, the project, then API Keys, with the button + Create new secret key. A personal key created in a project works only for that project and its resources. Three permission levels are offered when you create a user key:
- All: full permissions, the default.
- Restricted: you choose scopes per resource or endpoint, such as None, Read or Write.
- Read Only: read access to all endpoints.
For an app that runs on a server, OpenAI’s guide on API keys and service accounts suggests a service account, a project identity that is not a person, with its own key. Its key is also shown only once, when it is created.
Does ChatGPT Plus include API access?
No. OpenAI’s help article on billing says ChatGPT and the API platform have separate billing systems, and API usage is billed separately from your ChatGPT subscription. Paying for Plus gives you nothing to spend on the API.
The exception is newer: eligible Pro and Business subscribers can claim API credits as a subscription benefit. OpenAI’s article on the benefit says Plus and free trial subscriptions do not qualify, and the subscription must have been paid and active for at least 7 days before you claim.
| ChatGPT plan | API credits per month |
|---|---|
| Free, Go, Plus | None |
| Pro ($100 tier) | $100 |
| Pro ($200 tier) | $200 |
| Pro ($500 tier) | $500 |
| Business, per paid seat | $20 Standard, $100 Premium, $500 cap per workspace |
You claim them once, in ChatGPT under Settings, Billing, or on the API Platform under Billing, and they go to one API organization that you own. Monthly grants expire at the end of the billing cycle and do not roll over. The first grant is prorated. The article adds that the benefit may change or be removed.
ChatGPT API key pricing: add billing and prepaid credits
The key itself is free to create. What costs money is each request, priced per token by model. OpenAI’s prepaid billing article, read November 6, 2026, sets the rules for new accounts:
- New API accounts use prepaid billing: you buy credits first and each request draws them down.
- The minimum purchase is $5 and the default is $10. Auto-reload is on by default during setup, with a $5 minimum recharge.
- Purchased credits expire after 1 year and are non-refundable except for billing errors, unauthorized use or similar cases.
- Access may not stop the second credits run out, so the balance can go negative; that amount comes off your next purchase.
So a new key does nothing until you add a payment method on the Billing page and buy credits: with no credit left, API calls fail with the 429 insufficient_quota error in the table below. To prevent unexpected charges, turn off auto-reload and set a spend limit for the organization or project; a request over that limit gets its own 429 error.
Buying credits also raises your usage tier. OpenAI’s rate limit guide lists Build at $5 of total purchases, Launch at $100 and Grow at $500, each with higher limits. For what a model costs per million tokens, see our AI API pricing comparison, which we check against OpenAI’s own pricing page.
$0.05Is the OpenAI API free? Free credits and the Free tier
Creating a key costs nothing, but using it does. We found no free trial credit for new API accounts on OpenAI’s help or docs pages on November 6, 2026. The rate limit guide does list a tier called Free, open to users in supported countries, but that is a level of rate limits. Since new accounts are prepaid, a request with no credits left fails with the code credit_balance_exhausted.
The only free API credits OpenAI describes are the Pro and Business benefit above. A key handed out by another site belongs to someone else: OpenAI’s key safety page says sharing API keys is against its Terms of Use.
OpenAI API key security: how to keep your key safe
Anyone with your key can spend your credits. OpenAI’s page Best practices for API key safety lists these steps:
- 01Keep it in the environment variable OPENAI_API_KEY, as in the tool above, not pasted into your code. OpenAI’s SDKs read it from there.
- 02Never put it in client code: not in a web page, browser extension or mobile app. Send requests through your own server.
- 03Never commit it to a repository, public or private.
- 04Give each person their own key: invite teammates as members instead of sharing one.
- 05Create keys with an expiration date and rotate them: make a replacement, update your app, then revoke the old key.
- 06Set a monthly spend limit for the organization or project and turn on Enforce a hard limit. Alerts alone do not stop traffic.
If you think a key leaked, rotate it right away on the API Keys page and check the Usage page. To delete a key, select the trash can icon next to it; apps that still use it stop working.
Fix “Incorrect API key provided” (401) and 429 quota errors
OpenAI’s error codes guide and its help article on 429 errors explain each message. Read the error code before you retry: retrying a billing, spend or quota error does not restore access.
| Error | What it means and the fix |
|---|---|
| 401 Incorrect API key provided | Typo, extra space, deleted key or a key from another project. Fix: copy it again or create a new key, then update the variable. |
| 401 Invalid Authentication | Revoked key, wrong organization, or a key without permission for that endpoint. Fix: check the key, organization and key permissions. |
| 429 insufficient_ | No prepaid credits left. Fix: buy credits in Billing; wait a few minutes. |
| 429 spend limit reached | Your own organization or project spend limit. Fix: raise or remove it, or wait for the monthly reset. |
| 429 Rate limit reached | Too many requests or tokens too fast. Fix: slow down, follow Retry-After, back off and retry. |
| 403 Country, region, or territory not supported | You call the API from an unsupported location. Fix: use it only from a supported country. |
Two more causes of a 401 that OpenAI names: an old, revoked key cached on your machine, and an IP allowlist on the project that blocks your address. After you change the variable, open a new terminal window so the new key is used. If you belong to several organizations, check that the request uses the one with credits.
ChatGPT API key for Codex: sign in or use a key
Codex does not need an API key. OpenAI’s Codex docs offer two ways in: Sign in with ChatGPT, which uses your ChatGPT plan, or Use API Key, which bills your OpenAI Platform account at standard API rates. With a key, some features that rely on ChatGPT workspace access or cloud services are limited. OpenAI suggests the key for scripted runs, such as CI jobs. The API credits that come with Pro and Business do not cover Codex used through an API key.
FAQ
How do I get my API key on ChatGPT?
Not in ChatGPT itself. Sign in at platform.openai.com, open Settings, your project, then API Keys, and select + Create new secret key. Copy it at once; the full key is shown only then.
What is an API key used for?
It identifies your requests to the OpenAI API, so your own code or an app you connect can use OpenAI models, and the usage is billed to your organization and project.
Does ChatGPT Plus include API access?
No. OpenAI bills ChatGPT and the API separately, and Plus does not qualify for API credits. Eligible Pro and Business subscribers can claim monthly API credits.
Can I get an OpenAI API key for free?
The key is free to create, but requests need credits. On November 6, 2026 we found no free trial credit for new accounts on OpenAI’s pages; the smallest credit purchase is $5.
How much does the ChatGPT API cost?
You pay per token, and the price depends on the model; our AI API pricing page lists them. OpenAI’s ChatGPT plans are billed separately; its help center lists Pro tiers at $100, $200 and $500 a month.
Where do I find my API key after I created it?
You cannot view the full key again. OpenAI’s help page says to create a new key and update your app, then delete the old one with the trash can icon.
Do I need an API key for Codex?
No. You can select Sign in with ChatGPT and use your plan. Use API Key bills standard API rates to your OpenAI Platform account instead.
Sources
- OpenAI Help Center, Where do I find my OpenAI API Key?, read November 6, 2026
- OpenAI Help Center, Managing projects in the API platform, read November 6, 2026
- OpenAI Help Center, Best practices for API key safety, read November 6, 2026
- OpenAI Help Center, Managing billing for ChatGPT and the API platform, read November 6, 2026
- OpenAI Help Center, Setting up and managing prepaid API billing, read November 6, 2026
- OpenAI Help Center, API credits benefit for eligible ChatGPT subscriptions, read November 6, 2026
- OpenAI Help Center, Troubleshooting API rate limits and 429 errors, read November 6, 2026
- OpenAI API docs, Error codes, read November 6, 2026
- OpenAI API docs, Rate limits (usage tiers), read November 6, 2026
- OpenAI API docs, API keys and service accounts, Developer quickstart and List models reference, read November 6, 2026
- OpenAI Codex docs, Authentication, read November 6, 2026
Spotted a mistake? Write to support@gptx.io and we will check it.
Next up9 minWhat is an MCP server?6A plug-in for AI apps in plain words, with ready setups for six popular servers.