TokenMix Research Lab · 2026-04-10

How to Get an OpenAI API Key: Complete Setup Tutorial (2026)
Last Updated: 2026-04-29
Author: TokenMix Research Lab
5-minute setup: signup at platform.openai.com → add $5 credit → generate key (sk-proj-...) → set monthly budget → first API call. ChatGPT Plus does NOT include API access — they're separate products.
Getting an OpenAI API key takes about 5 minutes. You need an OpenAI account, a payment method on file, and a basic understanding of key security. This guide walks through every step -- from signup to your first API call -- and covers billing setup, usage limits, key rotation, and the security mistakes that get developers' keys stolen.
Whether you are building your first AI application or setting up keys for a team, this OpenAI API key tutorial covers everything you need.
Table of Contents
- Quick Overview: OpenAI API Key Setup Steps
- Step 1: Create Your OpenAI Account
- Step 2: Set Up Billing and Payment
- Step 3: Generate Your OpenAI API Key
- Step 4: Configure Usage Limits
- Step 5: Make Your First API Call
- API Key Security Best Practices
- Managing Multiple API Keys
- OpenAI API Key Pricing and Billing
- Common Errors and Troubleshooting
- Which OpenAI Plan Should You Choose?
- What's the Bottom Line on Getting Started?
- FAQ
Quick Overview: OpenAI API Key Setup Steps
Five steps, ~5 minutes total: account (2 min), billing ($5 minimum, 1 min), key generation (30s), usage limits (1 min), first API call (1 min). Phone verification required.
| Step | Action | Time |
|---|---|---|
| 1 | Create OpenAI account at platform.openai.com | 2 min |
| 2 | Add payment method and set billing | 1 min |
| 3 | Generate API key in API Keys section | 30 sec |
| 4 | Set usage limits and rate limits | 1 min |
| 5 | Test with a curl command or SDK | 1 min |
| Total | ~5 min |
Step 1: Create Your OpenAI Account
Sign up at platform.openai.com (NOT chatgpt.com — different product). Email/Google/Microsoft/Apple SSO. Phone verification mandatory. Set up an Organization first if you're managing keys for a team.
Go to platform.openai.com and click "Sign up." This is the API platform -- separate from chatgpt.com where you use ChatGPT.
Important distinction: A ChatGPT Plus subscription ($20/month) does NOT give you API access. The API has separate pricing based on usage. You need a platform account even if you already use ChatGPT.
Signup options:
- Email and password
- Google account
- Microsoft account
- Apple account
After signup, verify your email address and complete phone number verification. OpenAI requires phone verification to prevent abuse.
Organization setup: If you are creating keys for a team, set up an Organization first. Go to Settings > Organization. This lets you manage billing and API keys centrally. Individual developers can skip this step.
Step 2: Set Up Billing and Payment
$5 minimum prepaid credit unlocks Tier 1 (500 RPM). Enable auto-recharge to avoid 429 errors when balance hits zero. Six tiers from Free to Tier 5; spend gates each upgrade.
You cannot generate API keys without a payment method on file. OpenAI uses a prepaid credit system.
How to add billing:
- Go to Settings > Billing in the platform dashboard
- Click "Add payment method"
- Enter a credit card or debit card
- Add an initial credit amount (minimum $5)
Billing model: OpenAI uses prepaid credits. You add funds to your account, and API calls deduct from that balance. When your balance hits zero, API calls stop working. No surprise bills -- but also no service if you forget to top up.
Auto-recharge: Enable auto-recharge to avoid service interruptions. Set a threshold (e.g., "recharge $25 when balance drops below $5"). This prevents your application from going down because your credits ran out.
Usage Tiers
OpenAI assigns your account to a usage tier based on total spend. Higher tiers unlock higher rate limits.
| Tier | Total Spend Required | RPM (GPT-5.4) | TPM (GPT-5.4) |
|---|---|---|---|
| Free | $0 (limited) | 3 | 40,000 |
| Tier 1 | $5+ | 500 | 200,000 |
| Tier 2 | $50+ | 5,000 | 2,000,000 |
| Tier 3 | $100+ | 5,000 | 4,000,000 |
| Tier 4 | $250+ | 10,000 | 10,000,000 |
| Tier 5 | $1,000+ | 10,000 | 30,000,000 |
RPM = Requests Per Minute. TPM = Tokens Per Minute.
Most developers start at Tier 1. The $5 minimum credit gets you there immediately.
Step 3: Generate Your OpenAI API Key
Profile → API keys → Create new secret key. Name it (e.g. "prod-app"), pick All or Restricted permissions, copy immediately — OpenAI shows the key exactly once. Keys start with sk-proj-.
This is the core step. Here is exactly how to get your OpenAI API key.
- Log into platform.openai.com
- Click your profile icon (top-right corner)
- Select "API keys" from the dropdown
- Click "+ Create new secret key"
- Name your key (e.g., "my-app-production" or "dev-testing")
- Select permissions:
- All -- full access to all API endpoints
- Restricted -- choose specific endpoint access
- Click "Create secret key"
- Copy the key immediately -- you will NOT be able to see it again
Your API key looks like this: sk-proj-xxxxxxxxxxxxxxxxxxxxxxxxxxxx
The sk-proj- prefix indicates a project-level key. Older keys use sk- prefix.
Critical: Copy and store this key securely right now. OpenAI shows it only once. If you lose it, you must generate a new one.
Step 4: Configure Usage Limits
Settings → Limits → set monthly budget hard cap + notification threshold. Recommended: solo dev $10-25/month, small team $100-500, production = expected usage + 30% buffer.
Protect yourself from unexpected costs by setting usage limits before making your first call.
- Go to Settings > Limits
- Set a Monthly budget (hard cap -- API calls stop when reached)
- Set a Notification threshold (email alert when spending hits this amount)
Recommended starting limits:
- Individual developer: $10-25/month budget, $5 notification threshold
- Small team: $100-500/month budget, $50 notification threshold
- Production application: Set based on expected usage + 30% buffer
TokenMix.ai tracks pricing across 300+ models and can help you estimate monthly costs before you start building. Check the cost calculator at tokenmix.ai to project your expected spend based on model choice and query volume.
Step 5: Make Your First API Call
Three SDK options: curl, Python (OpenAI() reads env var), Node.js. Use gpt-5.4-nano for cheapest tests. 401 = key wrong; 429 = rate-limited or out of credits.
Test your key immediately to verify everything works.
Using curl (Terminal/Command Line)
curl https://api.openai.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-proj-YOUR_KEY_HERE" \
-d '{
"model": "gpt-5.4-nano",
"messages": [{"role": "user", "content": "Hello, world!"}]
}'
Using Python
from openai import OpenAI
client = OpenAI(api_key="sk-proj-YOUR_KEY_HERE")
response = client.chat.completions.create(
model="gpt-5.4-nano",
messages=[{"role": "user", "content": "Hello, world!"}]
)
print(response.choices[0].message.content)
Using Node.js
import OpenAI from 'openai';
const openai = new OpenAI({
apiKey: 'sk-proj-YOUR_KEY_HERE',
});
const response = await openai.chat.completions.create({
model: 'gpt-5.4-nano',
messages: [{ role: 'user', content: 'Hello, world!' }],
});
console.log(response.choices[0].message.content);
Expected result: A JSON response containing the model's reply. If you get a 401 error, your key is incorrect or has not been saved properly. If you get a 429 error, you have hit a rate limit.
API Key Security Best Practices
Stolen keys are exploited within minutes — track shows thousands in charges per hour. Five rules: env vars only, .env in .gitignore, secrets manager in prod, rotate every 90 days, separate dev/prod keys.
API key theft is the number one cause of unexpected OpenAI bills. TokenMix.ai has tracked cases where exposed keys racked up thousands of dollars in charges within hours.
The Rules
Never do this:
- Hard-code your API key in source code
- Commit your key to Git (even in private repos)
- Share your key in Slack, Discord, or email
- Put your key in client-side (frontend) code
- Store your key in plain text files in your project directory
Always do this:
- Store keys in environment variables
- Use
.envfiles locally (and add.envto.gitignore) - Use a secrets manager in production (AWS Secrets Manager, HashiCorp Vault, etc.)
- Rotate keys every 90 days
- Use separate keys for development and production
Environment Variable Setup
Linux/Mac:
export OPENAI_API_KEY="sk-proj-YOUR_KEY_HERE"
Windows (PowerShell):
$env:OPENAI_API_KEY = "sk-proj-YOUR_KEY_HERE"
Python .env file:
# .env file (add to .gitignore!)
OPENAI_API_KEY=sk-proj-YOUR_KEY_HERE
import os
from openai import OpenAI
client = OpenAI() # Automatically reads OPENAI_API_KEY env var
What To Do If Your Key Is Exposed
- Immediately go to platform.openai.com > API Keys
- Click "Revoke" on the compromised key
- Generate a new key
- Update your application with the new key
- Check your billing for unauthorized usage
- If significant unauthorized charges occurred, contact OpenAI support
Response time matters. Stolen keys are typically exploited within minutes. The faster you revoke, the less damage.
Managing Multiple API Keys
Use one key per environment + purpose: dev-local, staging-app, prod-app, analytics. OpenAI Projects feature gives separate billing, rate limits, and access control per project.
For teams and multi-environment setups, use separate keys for each purpose.
Recommended Key Structure
| Key Name | Purpose | Permissions | Usage Limit |
|---|---|---|---|
| dev-local | Local development | All | $10/month |
| staging-app | Staging environment | Restricted | $50/month |
| prod-app | Production application | Restricted (specific endpoints) | $500/month |
| analytics | Data analysis scripts | Restricted (completions only) | $100/month |
Project-Based Keys
OpenAI supports project-based API keys. Create a Project under your Organization, then generate keys scoped to that project. This provides:
- Separate billing tracking per project
- Independent rate limits
- Granular access control
- Easier key rotation without affecting other projects
OpenAI API Key Pricing and Billing
One key, all models. Nano $0.20/$1.25 = ~$50/month for 1K daily chatbot conversations. GPT-5.4 $2.50/$10 for complex tasks. o3 $2/$8 for reasoning. Pay-per-use, no per-key fees.
Your API key gives access to all OpenAI models. You pay per use, not per key.
Current Model Pricing (April 2026)
| Model | Input (per 1M tokens) | Output (per 1M tokens) | Best For |
|---|---|---|---|
| GPT-5.4 | $2.50 | $10.00 | Complex tasks |
| GPT-5.4 Mini | $0.40 | $1.60 | Balanced cost/quality |
| GPT-5.4 Nano | $0.20 | $1.25 | Simple tasks, high volume |
| o3 | $2.00 | $8.00 | Reasoning tasks |
| o3-mini | $0.50 | $2.00 | Light reasoning |
Cost estimation example:
Building a chatbot with 1,000 conversations/day, average 2,000 input tokens and 1,000 output tokens per conversation, using GPT-5.4 Nano:
- Daily input cost: 1,000 x 2,000 / 1,000,000 x $0.20 = $0.40
- Daily output cost: 1,000 x 1,000 / 1,000,000 x $1.25 = $1.25
- Daily total: $1.65 / Monthly: ~$50
For cost comparison across all providers, TokenMix.ai maintains real-time pricing tables for 300+ models.
Common Errors and Troubleshooting
401 = key wrong/revoked. 429 = rate limit or zero credits. 403 = permission missing. 500/503 = OpenAI side, retry with exponential backoff. Top mistakes: ChatGPT-Plus confusion, missing usage limits, deprecated model names.
| Error Code | Message | Cause | Fix |
|---|---|---|---|
| 401 | Invalid API key | Wrong key or revoked key | Check key, generate new one |
| 429 | Rate limit exceeded | Too many requests | Wait and retry, or upgrade tier |
| 429 | Insufficient quota | No credits remaining | Add funds to billing |
| 403 | Access denied | Key lacks permission | Check key permissions |
| 500 | Server error | OpenAI service issue | Retry after 30 seconds |
| 503 | Service unavailable | OpenAI overloaded | Retry with exponential backoff |
Common Mistakes
Mistake 1: Using the wrong base URL. The API endpoint is https://api.openai.com/v1/. Do not use https://chatgpt.com/ or https://chat.openai.com/.
Mistake 2: Confusing ChatGPT Plus with API access. Your $20/month ChatGPT subscription has nothing to do with the API. They are separate products with separate billing.
Mistake 3: Not setting usage limits. Without a monthly budget cap, a bug in your code could drain your credits in hours. Always set limits before deploying.
Mistake 4: Using a deprecated model name. Model names change. Use the latest names from the API documentation. As of April 2026, the current models are gpt-5.4, gpt-5.4-mini, and gpt-5.4-nano.
Which OpenAI Plan Should You Choose?
Learning: Free + $5 credit. Side project: Tier 1, Nano, $10-25/month. MVP: Tier 2, Nano + Mini, $50-200. Production: Tier 3+, model routing, $200-2K. Multi-provider: TokenMix.ai unified API.
| Your Situation | Recommended Setup | Monthly Budget |
|---|---|---|
| Learning / experimenting | Free tier + $5 credit | $5-10 |
| Personal project / side project | Tier 1, GPT-5.4 Nano | $10-25 |
| Startup building MVP | Tier 2, mix of Nano + Mini | $50-200 |
| Production application | Tier 3+, model routing | $200-2,000 |
| Enterprise / high volume | Tier 5, contact OpenAI sales | $2,000+ |
| Multi-provider setup | TokenMix.ai unified API | Varies |
What's the Bottom Line on Getting Started?
5 minutes to a working key. The hard part is what comes after: securing the key (env vars, secrets manager, 90-day rotation), capping spend (monthly budget + alerts), choosing the right model per task.
Getting an OpenAI API key is straightforward: create an account, add billing, generate the key, set limits, make a call. Five minutes, start to finish.
The part most tutorials skip is what comes after -- key security, cost management, and choosing the right model for each task. Hard-code your key in a GitHub repo and you will learn an expensive lesson. Skip usage limits and a runaway script could drain your balance overnight.
For developers who want to compare OpenAI's API with alternatives like Anthropic, Google, and DeepSeek, TokenMix.ai provides a unified API that works with the same OpenAI SDK format. One key, 300+ models, same code. That is the fastest path from "I have an API key" to "I have a production-ready AI application."
FAQ
How do I get an OpenAI API key for free?
OpenAI offers a limited free tier with $5 in initial credits for new accounts (subject to availability). This is enough for testing and small projects. After the free credits are used, you must add a payment method. There is no permanently free API access for production use.
Is an OpenAI API key the same as a ChatGPT account?
No. They are separate products. A ChatGPT Plus subscription ($20/month) gives you access to ChatGPT's web interface. An API key gives you programmatic access to OpenAI's models through code. You need a separate account at platform.openai.com for API access.
How much does it cost to use an OpenAI API key?
Costs depend on the model and usage volume. GPT-5.4 Nano (cheapest) costs $0.20/$1.25 per million input/output tokens. A typical chatbot with 1,000 daily conversations costs roughly $50/month on Nano. GPT-5.4 (most capable) costs $2.50/$10.00 per million tokens. Use TokenMix.ai's cost calculator to estimate your specific use case.
Can I use one OpenAI API key for multiple applications?
Yes, but you should not. Generate a separate key for each application or environment. This way, if one key is compromised, you revoke only that key without affecting other applications. Use OpenAI's Project feature to organize keys by application.
How do I keep my OpenAI API key secure?
Store it in environment variables, never in source code. Add .env to your .gitignore. Use a secrets manager (AWS Secrets Manager, HashiCorp Vault) in production. Rotate keys every 90 days. Set usage limits to cap potential damage from key theft.
What happens if I exceed my OpenAI API usage limit?
If you set a monthly budget cap, API calls return a 429 error with "insufficient_quota" when you hit the limit. Your application stops working until the next billing cycle or until you increase the limit. If auto-recharge is enabled, your payment method is charged to replenish credits.
Author: TokenMix Research Lab | Last Updated: April 2026 | Data Source: OpenAI Platform Documentation, OpenAI API Pricing, TokenMix.ai