How to Get an OpenAI API Key (Step by Step)

To get a ChatGPT API key (officially an OpenAI API key), create an OpenAI Platform account at platform.openai.com, verify your phone number, then go to API keys and select Create new secret key. Copy the key immediately and store it somewhere safe. Add a payment method and a spend limit before your first API call.
How to get your ChatGPT API key
If you want to build apps with GPT models, the first thing you need is a ChatGPT API key. Officially it is called an OpenAI API key. It is a long secret string that lets your code talk to OpenAI's models, and you can create one in about five minutes from the OpenAI Platform dashboard.
This guide walks through every step: creating the account, verifying the phone, generating the key and setting up billing. It also covers the parts that trip most people up, including usage limits and how to store the key so it never leaks.

What is a ChatGPT API key?
A ChatGPT API key is a secret credential that proves to OpenAI's servers that a request comes from your account. When your app calls the API, it sends the key in a header, OpenAI checks it, and the request goes through. Every call is then billed to your account based on the number of tokens it uses.
The key looks like a long random string. You generate it once, copy it into your app's settings, and OpenAI's official SDKs read it automatically from an environment variable. One distinction matters: a ChatGPT subscription and an API key are separate things. The subscription pays for the chatbot, while the key pays for API usage.
How to get an OpenAI API key in six steps
The whole process takes about five minutes. Follow the six steps below and you will have a working key before the end of this section.
Create an OpenAI Platform account. Go to platform.openai.com and sign up with your email address, or continue with a Google, Microsoft or Apple account. Use an address you control, because the verification link goes there.
Verify your email and phone number. OpenAI sends a verification link to your email, then asks for a mobile number and sends a code by text. The phone check is mandatory for API access and it limits how many accounts one person can open.
Add a payment method. The API uses prepaid billing, so you buy credits up front and every call draws them down. Add a card under Settings, then Billing, and buy your first credits. Credits expire one year after purchase.
Open the API keys page. Sign in to platform.openai.com and go to Settings, then API keys. The page lists every key your account owns.
Create a new secret key. Select Create new secret key, give it a name that matches its purpose, such as my-app-production, and confirm. The full key is displayed once, so copy it immediately. After you close the dialogue you can only see the first few characters.
Test the key. Save it as an environment variable, install an OpenAI SDK for your language, and run a one-line test request. If a short prompt comes back with a response, your key works.
If your test call returns an error instead of a response, the troubleshooting section below covers every common cause.

Understanding usage limits and billing
Two different limits apply to every OpenAI account. Usage limits are what OpenAI approves for your account each month, and they grow automatically as you buy credits. Spend limits are caps you set yourself, so a runaway app cannot empty your card.
New accounts start on the Free usage tier with a 100 dollar monthly usage limit. Buying 5 dollars of credits in total moves you up to the Build tier, 100 dollars to Launch, and 500 dollars to Grow, each with higher limits. You can check your current tier under Settings, then Limits.
Set a spend alert to get an email when usage crosses a threshold, and set a hard spend limit to stop API traffic when it hits your cap. Requests that arrive after a hard limit return an error instead of running up a bill.
Want to know what each model costs before you buy credits? Our ChatGPT API pricing guide breaks down input and output prices for every current model.
How to keep your API key secure
An API key is a password with a budget attached. Anyone who holds it can spend your credits, so treat it like a bank card number rather than a normal config setting.
Never put an API key in front-end code, a mobile app, or anywhere a visitor can read it. Anything in the browser is public, so keep the key on your server.
Store the key as an environment variable, not in your source files. Environment variables stay on your machine, so the key never reaches a code repository.
Use a separate key for each project. If one leaks, you revoke one key and the rest of your work keeps running.
Rotate keys every few months. Creating a new key, moving your apps across, then deleting the old one takes minutes.
Set a hard spend limit even on a hobby project. A cap of a few dollars means a leaked key costs you pocket change, not a month's budget.
What to do if your key stops working or is compromised
Most key problems fall into three buckets, and each has a clear fix.
401 invalid key errors usually mean a typo, a missing character, or a deleted key. Generate a fresh key, update your environment variable, and restart your app.
429 rate limit errors mean you are sending requests faster than your usage tier allows, or you have hit a hard spend limit. Check your limits under Settings, space out your requests, or upgrade your tier.
Insufficient quota means your prepaid credits ran out. Buy more credits under Settings, then Billing, and the key starts working again with no other changes.
If you believe the key has leaked, act immediately. Go to Settings, then API keys, delete the key and create a new one. Then check the usage dashboard for calls you did not make. The faster you revoke, the smaller the damage, and OpenAI support can help with charges from abuse.

Frequently asked questions
Is a ChatGPT API key free to get?
Creating the key is free, but using the API is not. OpenAI uses prepaid billing, so you buy credits and every call draws them down. There is no separate charge for the key itself, and you can create several keys at no cost.
Can I use my ChatGPT Plus subscription with the API?
No. A ChatGPT Plus subscription only pays for the chatbot at chat.openai.com. API usage is billed separately through prepaid credits, so subscribers still need a payment method and credits on the platform. Our guide to ChatGPT plans explains what each subscription includes.
Does an OpenAI API key expire?
A key keeps working until you delete it. What does expire is prepaid credit, one year after purchase, so an unused account can start returning quota errors even though the key itself is still valid.
Can one API key serve several apps?
Yes, one key works everywhere, but it is a bad habit. Separate keys per app keep usage and debugging clear. When one app is compromised, you revoke only its key and everything else keeps running.
Do I need a separate key for each model?
No. One key covers every model your account can access, from the smallest and cheapest to the largest. You choose the model in each API call, and the same key is billed at that model's rate.
What if I lose my API key?
You cannot recover it, because OpenAI only shows the full key once. Delete the old entry, create a new key, update your environment variable, and restart your apps. Nothing is lost beyond a few minutes.
The bottom line
Getting a ChatGPT API key is a five minute job: create an OpenAI Platform account, verify your phone, add a payment method, generate a secret key and store it in an environment variable. The habits around the key matter more than the key itself. Keep it on your server, use one key per project, and set a hard spend limit before your first call.
As AI development shifts from writing prompts to building apps, the API key is the one credential that connects those two worlds. Explore more ChatGPT guides and developer resources on whatischatgpt.co.uk.

















