Getting Your OPENAI_API_KEY
This guide explains how to obtain your OpenAI API key.
🔑 Step 1: Get Your OpenAI API Key
- Go to https://platform.openai.com
- Log in with your OpenAI account (or create one if you don’t have it yet).
- In the left sidebar, click “View API keys” or navigate directly to
https://platform.openai.com/account/api-keys - Click “Create new secret key” and give it a name (for example:
astro-app). - Copy the key immediately — it will only be shown once.
Your key will look something like this:
sk-proj-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
⚙️ Step 2: Add Your API Key to Your Environment
In your project root, create a .env file (if you don’t have one yet):
touch .env
Add your key:
OPENAI_API_KEY="sk-proj-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
That’s all you need to connect your project to the OpenAI API securely.
- You can check model access at: https://platform.openai.com/account/limits
✅ Summary
-
Get your API key from:
https://platform.openai.com/account/api-keys -
Store it in your
.envfile:OPENAI_API_KEY="your-secret-key"