To get a ChatGPT API key, sign in at platform.openai.com, open the API keys page and click Create new secret key. Copy the key right away, because OpenAI only shows the full key once. API usage is billed separately from ChatGPT Plus and other ChatGPT subscriptions, so you also need to buy prepaid API credits (minimum $5) before your key will work.
Keys are now managed inside OpenAI Projects, and the same key works with current models such as gpt-6.2-astra. This updated 2026 guide walks you through the 5-step process, from account creation to billing, plus a working code example to test your key, what the API really costs, and fixes for the most common errors.
Quick Answer: How to Get an OpenAI API Key in 2026
- Log in to your account at platform.openai.com
- Open the API keys page of your project (platform.openai.com/api-keys)
- Click Create new secret key, give it a name and copy it
- Buy credits under Settings → Billing (the minimum purchase is $5)
- Set a monthly spend limit for your organization or project
Your key is now ready to integrate into your app.
What Is ChatGPT API Key and Why You Should Use It?
A ChatGPT API key is a unique identifier that allows you to access and utilize the ChatGPT API. This API serves as an interface between ChatGPT and external applications.
By integrating the ChatGPT API, you can seamlessly incorporate ChatGPT's capabilities into your own applications. This will help you to unlock a wide range of advanced language processing features.
That means the API acts as a digital key that authenticates you as a user and allows you to make requests to the ChatGPT API to receive AI generated responses in return.
The ChatGPT API key is particularly valuable for developers working on projects that involve:
- Natural Language Processing (NLP): ChatGPT's ability to understand and process human language makes it an ideal tool for NLP-focused applications, such as chatbots, virtual assistants, and text summarization tools.
- Machine Learning (ML): Developers can utilize ChatGPT's language processing capabilities to enhance ML models, particularly in areas such as sentiment analysis, topic modeling, and text classification.
- Content Creation: ChatGPT's ability to generate creative text formats, like poems, code, scripts, musical pieces, emails, letters, etc., can be leveraged by content creators to develop engaging and original content.
- Chatbots and Conversational AI: ChatGPT's ability to engage in natural and meaningful conversations makes it an essential tool for developing advanced chatbots and conversational AI applications.
- Education and Research: Educators and researchers can utilize ChatGPT to explore the potential of language models in education, such as personalized learning, language learning tools, and automated grading systems.
Now, let's focus on how you can generate a ChatGPT API key!
How to Generate ChatGPT API Key – 5 Steps Tutorial for Beginners

Generating the ChatGPT API key isn't as difficult as it sounds. You can create it all by yourself only following 5 steps. Here are those steps:
- Create an Account
- Navigate to the API Section
- Generate ChatGPT API Key
- Add Billing to Activate Your API Key
- Set a Usage Limit (Optional but Smart)
Now, let us show you the tutorial in detail with the necessary images so that you can easily understand what you need to do. Keep reading!
Step 01: Create an OpenAI Account
If you haven't already signed up for the OpenAI platform, you need to sign up there to generate a ChatGPT API key. To do that, go to the OpenAI official website and find the Sign-up option.

Now insert all the necessary information to create your account within minutes. Also, you may be required to verify your phone number or email ID. If it's necessary, do it without having a second thought!
Already pay for ChatGPT Plus or Pro? You still need to set up the API separately. OpenAI's help center states that "API usage is billed separately from your ChatGPT subscription" and that ChatGPT and the API platform have separate billing systems.
Step 02: Navigate to the API Section
Once you have successfully created an OpenAI account, the next step is to locate the API section within the platform. This is where you will generate your ChatGPT API key, which will grant you access to the language model's capabilities.
API keys belong to a project. Every account starts with a default project, and you can create more projects later to keep keys for different apps apart.
- The quickest route is to go straight to platform.openai.com/api-keys while you are logged in.
- You can also open Settings, select your project and click API keys in the left sidebar.

- The API Keys page gives you an overview of your existing API keys and the option to generate a new one.

Step 03: Generate ChatGPT API key
To generate an API key, click on the ‘+Create new secret key‘.
Note: If the “Create new secret key” button isn't working that means you haven't verified your phone number. You'll get an option to verify your phone number at the top of this page, simply verify your phone number and continue the next steps.
- A pop-up window will appear on your screen. This window will contain a field where you can enter a descriptive name for your API key.
- Provide a meaningful name for your API key, such as “My ChatGPT API Key” or “Project X ChatGPT API Key”. This name will serve as a reminder of the purpose or project associated with this key.
- Choose the permission level. OpenAI offers All (full access, the default), Restricted (you pick which endpoints the key can read or write) and Read Only. For a simple test, All is fine. For production apps, give each key only the access it needs.

- After entering a suitable name, click on the “Create secret key” button within the pop-up window. This action will finalize the generation of your API key.
- Copy the API key and store it securely in a password manager or other secure location. OpenAI only shows the full secret key once, when you create it. If you lose it, you have to create a new key and update your app. Never share this key with anyone else, as it grants access to your OpenAI account and credits.

Congratulations! You have successfully created your ChatGPT API key. Now you can integrate it with any of your applications to leverage the power of ChatGPT.
Step 04: Add Billing to Activate Your API Key
Creating the API key isn’t enough. To actually use it, you must add a valid billing method.
Without billing, your API requests won’t go through. You’ll get an error every time. It’s like having a car but no fuel.
OpenAI API billing works on prepaid credits. You add a payment method, buy credits, and your API usage is deducted from that balance. You pay only for what you use, not a flat monthly fee. The minimum purchase is $5, and the default amount is $10.
Now, let’s add your billing info and unlock the full power of the API.
- Click on your profile icon and then click on the ‘Your profile‘ option.

- Open Settings → Billing (you can also go straight to platform.openai.com/settings/organization/billing/overview) and add your payment details.

- Fill in your credit or debit card number, expiry date, CVC, and billing address.

- Click Buy credits or Add to credit balance (whichever appears) and choose an amount. $5 is enough for testing.
- Decide on auto recharge. It is turned on by default during setup and tops up your balance when it falls below a threshold you set. Turn it off, or set a monthly limit on automatic purchases, if you want a firm cap.
- Give it a few minutes. Your balance can take a short while to update, and then your API key is ready to use.
Keep in mind that purchased credits expire after one year, so there is no benefit in buying far more than you need.
Step 5: Set a Usage Limit (Optional but Smart)
You’re not required to set a usage limit but you absolutely should.
Without a cap, your API usage can go unchecked. That means if a script goes wild or someone misuses your key, you could end up with a huge bill. Not fun.
A usage limit helps you stay in control. It’s like putting a monthly spending cap on your API budget.
Here’s how to set it:
- Open Settings → Organization → Limits (platform.openai.com/settings/organization/limits) and set a monthly spend limit you’re comfortable with. Even $5 or $10 works for testing.
- You can also set a spend limit for a single project in that project's settings.
- Turn on hard enforcement if it is offered. OpenAI notes that spend alerts on their own don't stop traffic, while an enforced limit does.

That’s it. Now you’ve got your safety net in place.
With billing and limits set, it’s time for the reward: a quick test. Below you’ll find a terminal command for a fast check and a Python script for developers.
Bonus Step: Test Your Key (The “Hello World” Moment)
Now that your billing is active and your key is generated, it’s time to make sure everything is working correctly. You don't need to build a full app yet; you can run a simple test in seconds.
First: Save your key as an environment variable
Instead of pasting the key into your code, store it in an environment variable named OPENAI_API_KEY. OpenAI recommends this name, and the official SDKs read it automatically.
- macOS / Linux:
export OPENAI_API_KEY="your_api_key_here" - Windows (PowerShell):
setx OPENAI_API_KEY "your_api_key_here"(then open a new terminal window)
Option A: Quick Test via Terminal (cURL)
This is the fastest way to verify your key without writing any code. Open your Terminal (Mac/Linux) and paste the following. It calls the Responses API, which is what OpenAI's current quickstart uses:
curl https://api.openai.com/v1/responses \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -d '{ "model": "gpt-6.2-astra", "input": "Say \"Your API is working!\" in 3 languages." }'Option B: Integration via Python (OpenAI SDK)
If you are a developer, use the official openai Python library.
- Install the library:
pip install openai(for JavaScript, usenpm install openai) - Run this script:
from openai import OpenAI
# The SDK reads OPENAI_API_KEY from your environment automaticallyclient = OpenAI()
try: response = client.responses.create( model="gpt-6.2-astra", input="Tell me one fun fact about AI." ) print("Success! Response from the API:") print(response.output_text)
except Exception as e: print(f"Error: {e}")You can swap gpt-6.2-astra for any model listed on the OpenAI API pricing page. Prices differ by model, so check the rates before you pick one for a real project.
Pro-Tip: What if it fails?
If you get a 401 error, double-check that your API key is copied correctly and is set in the same terminal you run the code from. If you get a 429 error right after buying credits, wait a few minutes; OpenAI says the credit balance can take a few minutes to update. The full list of fixes is in the next section.
Is the ChatGPT API Free? Cost and Usage Limits
No, the ChatGPT API is not free, and a ChatGPT subscription does not cover it. OpenAI's help center is clear that ChatGPT and the API platform have separate billing systems, and that API usage is billed separately from your ChatGPT subscription. Paying for ChatGPT Plus or Pro does not give you API access by itself.
If you only want to experiment without paying, Google's Gemini API has a free tier. See how to get a free Gemini API key.
Here is how API costs work in 2026:
- Prepaid credits: You buy credits up front (minimum $5, default $10) and usage is deducted from your balance. When the balance runs out, API requests start returning a billing error.
- Credits expire: Purchased credits expire after one year.
- Pay per token: Prices are listed per 1 million tokens and vary by model. Input tokens (what you send) and output tokens (what the model writes back) are priced separately. See the official OpenAI API pricing page for current rates.
- Free items: The only item marked free on the pricing page is the moderation model (
omni-moderation-latest). - Promotional credits: Some eligible ChatGPT subscriptions may come with promotional API credits for a linked API organization. These are not guaranteed, and they still sit in the separate API billing system.
Usage tiers and rate limits
OpenAI also limits how much you can use the API. Rate limits are measured in requests per minute (RPM), requests per day (RPD), tokens per minute (TPM), tokens per day (TPD) and, for image models, images per minute (IPM). You hit the limit on whichever metric runs out first.
Your monthly usage limit depends on your usage tier, which goes up as you buy more credits:
| Usage tier | How you qualify | Monthly usage limit |
|---|---|---|
| Free | You are in an allowed geography | $100 / month |
| Build | $5 in total credit purchases | $500 / month |
| Launch | $100 in total credit purchases | $5,000 / month |
| Grow | $500 in total credit purchases | $200,000 / month |
You can see your exact per-model rate limits and upgrade your tier under Settings → Organization → Limits. Source: OpenAI rate limits guide.
Common ChatGPT API Key Errors and Fixes
Even if you follow every step, you might encounter an error message. Don't worry, most are quick fixes. Here is a breakdown of the most common issues in 2026, based on OpenAI's official error codes guide:
| HTTP Code | Error Message | What it Actually Means | The Quick Fix |
|---|---|---|---|
| 401 | Invalid Authentication / Incorrect API key provided | Your API key is incorrect, revoked, or has a typo, or the wrong organization is used. | Re-copy the key from your dashboard. Ensure there are no extra spaces in your code. If the key is lost, create a new one. |
| 401 | IP not authorized | Your organization uses an IP allowlist and your server's IP isn't on it. | Send the request from an allowed IP, or update the allowlist. |
| 429 | Credit balance exhausted (type insufficient_quota) | You have no credits left in your account. | Check Billing: OpenAI uses a prepaid system. Add credits to your balance. Retrying will not help. |
| 429 | Organization spend limit reached / Project spend limit reached | You hit the spend limit you set. | Raise or remove the limit in your organization or project settings. |
| 429 | Rate limit reached for requests | You are sending too many requests too fast. | Slow down your requests, follow the Retry-After header, or implement “Exponential Backoff” (retrying with a delay). |
| 403 | Country, region, or territory not supported | You are calling the API from a location OpenAI doesn't support. | Check OpenAI's supported countries list. The API only works from supported locations. |
| 403 | Permission Denied | Your key doesn't have access to this specific Project or Model. | Go to Project Settings and ensure your API key has “All” permissions enabled, or the right Restricted scopes. |
| 404 | Model not found | The model name is misspelled, retired, or not available to your project. | Copy the exact model ID from the pricing or models page and check your project's model access. |
| 500 | The server had an error while processing your request | Something went wrong on OpenAI's side. | Retry after a brief wait, and contact support if it keeps happening. |
| 503 | Model temporarily overloaded | The model is temporarily at capacity. | This is on their end! Follow Retry-After, wait and try again, or check status.openai.com. |
Quota vs. rate limit: both come back as a 429, so read the error message. If it mentions credits or a spend limit, waiting won't fix it. You need to add credits or raise the limit. If it says "rate limit reached", slow down and retry.
Bonus 01: How to Revoke Your ChatGPT API Key If It's Needed
If you suspect that your API key has been compromised or misused, revoking it is the most effective way to prevent unauthorized access to your ChatGPT account. This could happen if you accidentally shared your key with someone else, if your device was hacked, or if there was a security breach on the OpenAI platform.
Let's check how you can revoke your ChatGPT API key!
- Log in to your OpenAI account and navigate to the API Keys page.
- Find the API key you want to revoke. The API Keys page will typically display a list of all your generated API keys, along with their names and creation dates.
- Click on the delete button.

- After clicking on the Delete/Trash button, a confirmation prompt may appear asking you to verify that you want to revoke the selected API key. Click on the “Confirm” or “Revoke” button to proceed.
Once you have followed these steps, the selected API key will be revoked and can no longer be used to access ChatGPT's features. If you need to revoke multiple API keys, repeat the process for each key you want to disable.
Rotating a key without downtime: create the replacement key first, update your apps to use it, confirm it works, and only then revoke the old key. If you think a key has leaked, rotate it immediately from the API Keys page.
Bonus 02: Mistakes to Avoid While Generating ChatGPT API Key
You should be aware of some mistakes that many users commit while generating and using the ChatGPT API key. Here we have listed a few mistakes that you should always avoid:
- Creating multiple API keys without a clear purpose: Each API key should be associated with a specific project or application. Having too many keys can make it difficult to track usage and identify potential security issues.
- Sharing your API key with unauthorized individuals: Your API key is like a password; never share it with anyone else. This could allow unauthorized access to your ChatGPT account and compromise your projects.
- Storing your API key insecurely: Store your API key in a secure location, such as a password manager or an encrypted file. Avoid storing it in plaintext or sharing it through insecure channels.
- Not revoking compromised API keys: If you suspect that your API key has been compromised, revoke it immediately to prevent unauthorized access. You can revoke keys from the API Keys page on the OpenAI platform.
- Not monitoring API usage: Keep an eye on your API usage to identify any anomalies or unusual activity. This can help you detect potential security breaches or misuse of your API key.
- Hardcoding the key in your code: Load it from an environment variable named
OPENAI_API_KEY, or from a secrets manager in production. Never commit your key to a repository, public or private. - Putting the key in client-side code: Never ship your key in a browser app, a website's JavaScript or a mobile app. Anyone can extract it from there. Send requests through your own backend instead.
- Sharing one key across a team: OpenAI recommends a unique API key for each team member, and project-scoped keys with only the permissions each app needs.
- Using keys that never expire: Project keys can be created with an expiration date. OpenAI strongly recommends setting one and rotating keys on a regular schedule.
- Relying on alerts instead of limits: Spend alerts only notify you. Set a monthly spend limit with hard enforcement for your organization or project so a leaked key can't run up an unlimited bill.
Source: OpenAI's best practices for API key safety.
Related: ChatGPT for eCommerce: Elevate Your Online Sales with Essential Strategies
FAQs About the OpenAI API Key (2026)
Is the OpenAI API free in 2026?
No. The OpenAI API is not completely free. You must add a payment method and buy prepaid credits (minimum $5) before using it. You are charged based on how many tokens your application uses, with prices per 1 million tokens listed on the OpenAI pricing page. There is no fixed monthly fee.
Does ChatGPT Plus include API access?
No. OpenAI states that API usage is billed separately from your ChatGPT subscription, and that ChatGPT and the API platform have separate billing systems. Even if you pay for ChatGPT Plus or Pro, you need to buy API credits on platform.openai.com to use your API key.
Do I get free credits when creating an OpenAI API key?
Free trial credits are not guaranteed. In most cases, you must add billing before your API key becomes active. Some eligible ChatGPT subscriptions may include promotional API credits for a linked API organization, so check your billing overview to see if any are available.
Can I see my OpenAI API key again after creating it?
No. For security, OpenAI only shows the full secret key once, when you create it. If you lose it, create a new key on the API keys page, update your app to use it, and delete the old one.
Do OpenAI API credits expire?
Yes. Purchased API credits expire after one year, and OpenAI can't extend that date. Buy only what you expect to use, or use auto recharge with a monthly limit.
Why is my OpenAI API key not working?
Your API key may not work for these reasons:
- Billing is not added
- The key was copied incorrectly
- The key was revoked
- You exceeded your usage limit
- Your request format is incorrect
Start by checking billing and usage limits in your dashboard.
Why does OpenAI say I must add a payment method?
OpenAI uses prepaid billing for the API. You need a payment method and a credit balance before your requests are processed. When your prepaid balance runs out, API calls start returning a billing error.
How much does the OpenAI API cost per month?
There is no fixed monthly fee. You pay based on usage. The cost depends on the model you use and how many tokens your application processes. You can set monthly spending limits to control costs.
How do I set a usage limit for my OpenAI API key?
Go to Settings → Organization → Limits on platform.openai.com and set a monthly spend limit, or set one for a single project in its project settings. Enable hard enforcement so requests actually stop at the cap. This prevents unexpected charges if your app makes too many requests.
How do I revoke or delete an OpenAI API key?
Open the API Keys section in your dashboard. Find the key you want to remove and click Delete. Once deleted, the key will stop working immediately.
What happens if my OpenAI API usage exceeds the limit?
If you hit your spend limit, your API requests fail with a 429 error such as "Organization spend limit reached" or "Project spend limit reached". To continue using the API, raise or remove the limit, or wait until the next month. If your credit balance runs out instead, you will see "Credit balance exhausted" and need to add credits.
Do You Have Any Further Queries?
That's all from our side.
We have described:
- What is a ChatGPT API key
- How you can generate ChatGPT API key
- How to revoke a ChatGPT API key if it's needed
- ChatGPT Pricing plans, and
- A few common mistakes that you should avoid while generating ChatGPT API key for you.
That means now you know everything about the ChatGPT API key and we can certainly say that you will be able to create ChatGPT API keys all by yourself for your applications.
That being said, if you have any further confusion regarding this topic, feel free to share that with us using the comment box below. We are all ears!







