Skip to content

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



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.


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

Easy so far. ✅


This is where many people get stuck:

  1. Sign in and go to your OpenAI dashboard
  2. Navigate to “API keys” in the left menu
  3. Click “Start phone verification”
  4. Enter your real mobile number
  5. Type the 6-digit SMS code into the site

You cannot create an API key until your phone number is verified.


  1. Click ”+ Create new secret key”
  2. Name it something descriptive like learning-project or chat-app-dev
  3. Select “Default project” for now
  4. 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.


Surprise! Your API key won’t work until you add credit.

  1. Go to Billing → Payment methods
  2. Click “Add payment method” and enter your card
  3. Go to Billing → Credits
  4. 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.


Before coding:

  1. Go to Billing → Limits
  2. Set a monthly limit (e.g., $20–$30 while learning)
  3. Enable notifications at 50% and 80% usage

I’ve seen devs accidentally burn $200+ in a single day. Don’t be that person.


Let’s check your setup. Run in your terminal:

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, check:

  • Phone number verified
  • $5 credit added
  • API key copied exactly

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