Skip to content

🔑 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.



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.


  1. Go to platform.openai.com
  2. Click Sign up and create your account
  3. Verify your email (check your inbox for the link)

Nothing tricky here - standard account creation.


This is where some people get stuck:

  1. In your dashboard, look for “Add phone number”
  2. Enter your real mobile number (not VOIP)
  3. 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.


Now for the good stuff:

  1. Click “API keys” in the left sidebar
  2. Click ”+ Create new secret key”
  3. Give it a name like learning-project or chat-app-dev
  4. Choose “Default project” for now
  5. Click “Create secret key”

CRITICAL: Copy the key immediately! You’ll never see it again.

Store it safely:

# In your .env file
OPENAI_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.


Here’s the part that surprises everyone - you must add money before your key works:

  1. Go to “Billing”“Payment methods”
  2. Click “Add payment method” and add your card
  3. Go to “Billing”“Credits”
  4. Click “Add credits” → Enter $5Purchase

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.


Before you start coding, protect yourself:

Set spending limits:

  1. Go to “Billing”“Limits”
  2. Set a monthly limit of $20-30
  3. 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.


Let’s verify everything works. Open your terminal and run:

Terminal window
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

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!