🔑 Getting Your OpenAI API Key
Time to get your OpenAI API key! 🗝️
The process is simple, but there are a few “gotchas” that trip up beginners. Let’s go through it step-by-step so you don’t get stuck.
🎥 Video Walkthrough
Section titled “🎥 Video Walkthrough”🎯 What You Need First
Section titled “🎯 What You Need First”Before you start:
- A valid email address for your OpenAI account
- A real mobile number (no Google Voice or VOIP — they won’t work)
- A credit or debit card (to add your $5 credit)
💡 Tip: OpenAI only allows one account per phone number, so use your actual number.
🚀 Step 1: Create Your OpenAI Account
Section titled “🚀 Step 1: Create Your OpenAI Account”- Go to platform.openai.com
- Click Sign up and create your account
- Verify your email — check your inbox for the confirmation link
Easy so far. ✅
📱 Step 2: Verify Your Phone
Section titled “📱 Step 2: Verify Your Phone”This is where many people get stuck:
- Sign in and go to your OpenAI dashboard
- Navigate to “API keys” in the left menu
- Click “Start phone verification”
- Enter your real mobile number
- Type the 6-digit SMS code into the site
You cannot create an API key until your phone number is verified.
🔑 Step 3: Generate Your API Key
Section titled “🔑 Step 3: Generate Your API Key”- Click ”+ Create new secret key”
- Name it something descriptive like
learning-projectorchat-app-dev - Select “Default project” for now
- Click “Create secret key”
⚠️ Important: Copy your key right away — you will never see it again.
Store it in your .env file:
OPENAI_API_KEY=sk-proj-abc123...🔒 Security warning: Never commit this key to GitHub or share it publicly — people actively scan for keys and will use your credits.
💳 Step 4: Add $5 Credit (Required)
Section titled “💳 Step 4: Add $5 Credit (Required)”Surprise! Your API key won’t work until you add credit.
- Go to Billing → Payment methods
- Click “Add payment method” and enter your card
- Go to Billing → Credits
- Click “Add credits”, enter $5, and purchase
Without this step, you’ll get an error like:
invalid_request_error: 429 insufficient_quota💡 Good news: $5 will last a long time while learning — probably under $1 for this whole course.
🛡️ Step 5: Protect Your Budget
Section titled “🛡️ Step 5: Protect Your Budget”Before coding:
- Go to Billing → Limits
- Set a monthly limit (e.g., $20–$30 while learning)
- Enable notifications at 50% and 80% usage
I’ve seen devs accidentally burn $200+ in a single day. Don’t be that person.
✅ Quick Test
Section titled “✅ Quick Test”Let’s check your setup. Run in your terminal:
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, check:
- Phone number verified
- $5 credit added
- API key copied exactly
🔒 API Key Best Practices
Section titled “🔒 API Key Best Practices”DO:
- Store keys in environment variables
- Use different keys for dev/prod
- Rotate keys every few months
- Monitor usage regularly
DON’T:
- Hard-code keys in your source
- Commit keys to version control
- Share keys in screenshots/demos
- Reuse the same key for multiple projects
Perfect! Your API key is ready. 🎉
Next: We’ll set up a Node.js backend and make your first OpenAI API call.
👉 Setting Up Your Backend