🔑 Getting Your OpenAI API Key
Time to get your hands on the magic key! 🗝️
This process is straightforward, but there are a few gotchas that catch everyone. I’ll walk you through each step so you don’t get stuck.
🎥 Video Walkthrough
Section titled “🎥 Video Walkthrough”🎯 What You Need First
Section titled “🎯 What You Need First”Before we start, make sure you have:
- Valid email address (for account creation)
- Real mobile phone number (VOIP numbers get rejected)
- Credit/debit card (for the $5 minimum credit)
Important: Use your actual phone number, not a Google Voice or similar service. OpenAI is strict about this.
🚀 Step 1: Create Your Account
Section titled “🚀 Step 1: Create Your Account”- Go to platform.openai.com
- Click Sign up and create your account
- Verify your email (check your inbox for the link)
Nothing tricky here - standard account creation.
📱 Step 2: Verify Your Phone
Section titled “📱 Step 2: Verify Your Phone”This is where some people get stuck:
- In your dashboard, look for “Add phone number”
- Enter your real mobile number (not VOIP)
- Enter the 6-digit SMS code you receive
Why this matters: No phone verification = no API access. OpenAI uses this to prevent abuse.
One phone per account - so if you mess up, you might need a different number.
🔑 Step 3: Generate Your API Key
Section titled “🔑 Step 3: Generate Your API Key”Now for the good stuff:
- Click “API keys” in the left sidebar
- Click ”+ Create new secret key”
- Give it a name like
learning-project
orchat-app-dev
- Choose “Default project” for now
- Click “Create secret key”
CRITICAL: Copy the key immediately! You’ll never see it again.
Store it safely:
# In your .env fileOPENAI_API_KEY=sk-proj-abc123...
Security warning: Never commit this key to GitHub or share it publicly. Seriously - people scan for these keys and will use your credits.
💳 Step 4: Add $5 Credit (Required)
Section titled “💳 Step 4: Add $5 Credit (Required)”Here’s the part that surprises everyone - you must add money before your key works:
- Go to “Billing” → “Payment methods”
- Click “Add payment method” and add your card
- Go to “Billing” → “Credits”
- Click “Add credits” → Enter $5 → Purchase
Without this $5, your API calls will fail with an error like:
invalid_request_error: Must add funds first
Good news: $5 lasts a long time while learning. You’ll probably spend $0.50-$2.00 going through this entire course.
🛡️ Step 5: Set Up Protection
Section titled “🛡️ Step 5: Set Up Protection”Before you start coding, protect yourself:
Set spending limits:
- Go to “Billing” → “Limits”
- Set a monthly limit of $20-30
- Set usage notifications at 50% and 80%
Why this matters: I’ve seen developers accidentally spend $200+ in a day. Don’t be that person.
✅ Quick Test
Section titled “✅ Quick Test”Let’s verify everything works. Open your terminal and run:
curl https://api.openai.com/v1/models \ -H "Authorization: Bearer YOUR_API_KEY_HERE"
Success looks like:
{ "data": [ {"id": "gpt-4o-mini", "object": "model", ...}, {"id": "gpt-4o", "object": "model", ...} ]}
If you get an error, double-check:
- ✅ Phone number verified
- ✅ $5 credit added
- ✅ API key copied correctly
🔒 Key Security Best Practices
Section titled “🔒 Key Security Best Practices”DO:
- Store keys in environment variables
- Use different keys for development/production
- Rotate keys every few months
- Monitor usage regularly
DON’T:
- Hard-code keys in your source code
- Commit keys to version control
- Share keys in screenshots or demos
- Use the same key across multiple projects
Perfect! Your API key is ready. 🎉
What’s next? We’ll build a Node.js backend and make your first AI API call. Time to see this thing in action!
👉 Next: Setting Up Your Backend - Let’s write some code!