How to Create & Use OpenAI API Key in 2026: Step-by-Step Guide
Nov 05, 2026 5 Min Read 11801 Views
(Last Updated)
An OpenAI ChatGPT API key is what lets your own code talk to OpenAI’s models. Without one, a script can’t identify who is sending a request, and OpenAI has no account to bill.
Creating a key takes about five minutes. What changes more often is everything around it, such as billing options and which models are still available. The steps below reflect how things work in 2026.
Quick Answer:
To create an OpenAI API key, sign in at platform.openai.com, open Settings → API keys, click Create new secret key, and copy it right away because it is shown only once. Then add a payment method under Billing and store the key in an environment variable to use it in your code.
Table of contents
- TL;DR Summary
- What is an OpenAI ChatGPT API Key?
- Why Should You Use It?
- ChatGPT Account vs OpenAI API Account
- How to Create an OpenAI API Key in 2026 (Step by Step)
- Step 1: Sign up on the API platform
- Step 2: Set up your organization and project
- Step 3: Open the API keys page
- Step 4: Generate your key
- Step 5: Add billing
- How to Use Your API Key in Python?
- OpenAI API Pricing 2026: How Much Does It Cost?
- Latest OpenAI API Pricing
- Which Model Should Beginners Choose?
- How to Secure Your OpenAI API Key?
- Common Mistakes Beginners Make
- Common Errors and How to fix them
- Conclusion
- FAQs
- Is the OpenAI ChatGPT API key free?
- Does ChatGPT Plus include API access?
- Can I use one key across multiple projects?
- What happens if my key gets exposed?
- Can I limit what a key is allowed to do?
TL;DR Summary
- An OpenAI API key is a secret string that lets your code send requests to OpenAI models and bill usage to your account.
- You create it on the API keys page at platform.openai.com, and it is shown only once, so copy it straight into a password manager.
- The API is billed separately from ChatGPT, although eligible ChatGPT Pro and Business subscribers can claim free monthly API credits.
- Store the key in an environment variable on a backend, never in browser code or a public repository.
- Older models such as gpt-5 and gpt-4o are being retired, so new projects should start with a current model from OpenAI’s models page.
What is an OpenAI ChatGPT API Key?

An API key is a unique string that identifies your account every time your code contacts OpenAI’s servers. Think of it as a digital ID card. Without it, OpenAI can’t tell who is asking or who to bill.
Every request your app sends carries this key in the background. OpenAI checks it, confirms your account has active billing, and returns a response.
Why Should You Use It?
An API key lets you build with OpenAI’s models on your own terms. Here is what you gain by using one:
- Build your own tools: Power chatbots, scripts, and apps with the same models behind ChatGPT.
- Automate repetitive work: Let code handle summarizing, drafting, and answering questions for you.
- Pay for what you use: Billing follows the tokens you consume, with no fixed monthly fee.
- Stay in control: Create a separate key per project, restrict its permissions, and revoke it anytime.
An API key lets you connect to powerful models, but building real AI products takes solid skills. HCL GUVI’s Intel & IITM Pravartak Certified AI/ML Course takes you from Python to deep learning and Agentic AI, with a two-day in-person immersion and placement guidance backed by 1000+ hiring partners!
ChatGPT Account vs OpenAI API Account
This trips up almost everyone at first. Here’s the distinction:
- ChatGPT (chat.openai.com) is the consumer website where you type and get replies.
- The OpenAI API (platform.openai.com) is for developers. It powers your own apps and scripts.
- A ChatGPT Plus subscription does not include API credit. You’re billed separately for each.
- You can use the same email for both, but they run as two independent accounts.
This confuses almost everyone when they first start. The short answer is no; they are two completely separate things.
Automated bots scan public GitHub repositories around the clock specifically looking for exposed API keys, and a leaked key can rack up charges within minutes of being found.
How to Create an OpenAI API Key in 2026 (Step by Step)

Step 1: Sign up on the API platform
Go to platform.openai.com and click Sign up. You can register with an email, or sign in with Google, Microsoft, or Apple. Confirm the verification email, and verify your phone number if asked.
Step 2: Set up your organization and project
On first login, OpenAI asks you to name an organization (a label for your account) and create a project (a folder that groups your keys and usage). Name the project something clear, like my-first-app.
Step 3: Open the API keys page
From the left sidebar, click Settings, then API keys. You can also go directly to platform.openai.com/api-keys. This page lists every key tied to your account.
Step 4: Generate your key
Click Create new secret key. You’ll be asked to:
- Name the key, for example test-key or portfolio-project
- Choose permissions (start with full access; you can restrict this later)
- Pick which project it belongs to
Click Create secret key. The key appears once, starting with something like sk-proj-.... Copy it immediately into a password manager or secure notes app. OpenAI will never show it to you again.
Step 5: Add billing
Go to Settings → Billing and add a payment method. New accounts get a small trial credit, but real usage needs an active card on file. While you’re there:
- Set a monthly spending limit so a bug in your code never surprises you with a large bill
- Turn on auto-recharge if you want your balance to top up automatically
Your First API Call Is Just the Beginning. Learn to build real AI applications with HCL GUVI’s Intel & IITM Pravartak Certified AI/ML Course, which includes a two-day in-person immersion and placement support. Enroll today and take your next step in AI!
How to Use Your API Key in Python?
Once your key exists, store it as an environment variable rather than pasting it into your script. Create a .env file in your project folder:
OPENAI_API_KEY=paste-your-key-here
Add .env to your .gitignore so it never gets pushed to GitHub. Then install the SDK:
pip install openai python-dotenv
The script below uses the Responses API, which OpenAI recommends for new projects.
from dotenv import load_dotenv
from openai import OpenAI
load_dotenv()
client = OpenAI()
response = client.responses.create(
model="gpt-6-luna",
input="Explain what an API key is in simple terms.",
)
print(response.output_text)
The OpenAI() client reads OPENAI_API_KEY from the environment on its own, so the key never appears in your code. Run the file with python your_filename.py and the reply prints within a few seconds.
Many older tutorials and libraries still call the Chat Completions API. It’s still supported, and the request looks like this.
response = client.chat.completions.create(
model="gpt-6-luna",
messages=[{"role": "user", "content": "Explain what an API key is in simple terms."}],
)
print(response.choices[0].message.content)
Run either file with python your_filename.py. You’ll see a reply within a couple of seconds.
OpenAI API Pricing 2026: How Much Does It Cost?
OpenAI follows a pay-as-you-go pricing model. There is no fixed monthly subscription fee for API access. You pay based on the number of tokens your application processes.
Latest OpenAI API Pricing
| Model | Best For | Input / 1M Tokens | Output / 1M Tokens |
|---|---|---|---|
| GPT-6 Astra | Complex reasoning and coding | $10.00 | $50.00 |
| GPT-6.1 Sol | Research and professional tasks | $2.00 | $10.00 |
| GPT-6.1 Terra | Everyday tasks and automation | $1.00 | $5.00 |
| GPT-6 Luna | Budget-friendly applications | $0.10 | $0.50 |
Which Model Should Beginners Choose?
For beginners, GPT-6 Luna is a budget-friendly starting point. GPT-6.1 Terra is a good choice for applications requiring more capabilities.
Important: ChatGPT subscriptions and API billing are separate. A ChatGPT Plus subscription does not include free API usage.
How to Secure Your OpenAI API Key?
Your key is effectively a password to your billing account. A few rules keep it safe.
Never expose it in frontend code. If you write your key directly into JavaScript that runs in a browser, anyone can open dev tools and steal it. All API calls must go through a backend server you control, never client-side code.
Use environment variables, not hardcoded strings. Keep the key in .env locally and in a secrets manager (AWS Secrets Manager, Google Cloud Secret Manager, Doppler) in production.
Restrict permissions per key. A key used only for chat completions doesn’t need billing or model-training access.
Rotate and revoke fast. If you suspect a key leaked, for example after accidentally pushing it to GitHub, delete it from platform.openai.com/api-keys immediately and generate a fresh one. Bots scan public repositories for exposed keys around the clock.
Common Mistakes Beginners Make
- Skipping the spending limit: A stuck loop in your code can burn through credit fast. Set a cap before your first real test.
- Hardcoding the key in the script: This is the single most common way keys leak publicly. Use environment variables from day one.
- Confusing ChatGPT login with API access: A ChatGPT Plus subscription won’t unlock API calls. You need a separate platform account with billing set up.
- Forgetting the environment variable on deployment: Code that works locally often fails on a live server because you never added the key to the hosting platform’s settings.
Common Errors and How to fix them
A new key that fails on the first call usually points to a billing, project, or model problem rather than a broken key.
| Error | Likely cause | Fix |
|---|---|---|
| 401, incorrect API key provided | The key is wrong, revoked, or expired | Create a new key on the API keys page and update the environment variable |
| 429, credit_balance_exhausted | No free or purchased credits remain | Add credits in billing settings or turn on auto recharge |
| 429, rate limit reached | Too many requests for your organization’s limits | Slow the requests down or review the limits in your organization settings |
| Model not found or not available | The model was retired, misspelled, or is not open to your account | Check the models and deprecations pages and switch to a current model |
Ready to Go Beyond the API? HCL GUVI’s Intel & IITM Pravartak Certified AI/ML Course takes you from Python to deep learning and Agentic AI, with placement guidance backed by 1000+ hiring partners. Enroll today and build what comes next!
Conclusion
Getting an OpenAI API key is genuinely a five-minute task once you know where to click. The harder part, and the more valuable one, is what you do after: storing it safely, picking the right model for your budget, and writing your first working call.
Set up your account, generate your key, run the Python example above, and you’ll have ChatGPT responding to your own code for the first time. From there, what you build with it is up to you.
FAQs
1. Is the OpenAI ChatGPT API key free?
Creating a key costs nothing. Usage is billed per token, unless you are spending free credits, such as those available to eligible ChatGPT Pro and Business subscribers.
2. Does ChatGPT Plus include API access?
No. Plus covers the ChatGPT app only. Pro and Business plans can claim monthly API credits, as explained earlier.
3. Can I use one key across multiple projects?
You can, but a separate key per project makes usage tracking and revoking access much easier.
4. What happens if my key gets exposed?
Revoke it instantly at platform.openai.com/api-keys, generate a new one, and check your usage history for unfamiliar activity.
5. Can I limit what a key is allowed to do?
Yes. Restricted and Read Only permissions control which endpoints a key can reach, and a spend limit caps how much the project can be charged.



Did you enjoy this article?