An API Key is a unique token that allows you to authenticate and access OpenAI's services programmatically. This key is essential for using OpenAI's models (like GPT-4, GPT-3.5) in your applications.
Before starting, ensure you have:
- A working internet connection
- A valid email address
- A credit card (for existing accounts) or access to free credits (for new accounts)
- Approximately 5-10 minutes to complete the setup
An API Key is:
- A secure authentication token
- Required to make API calls to OpenAI services
- Unique to your account
- Should be kept confidential (never share publicly)
- Can be regenerated at any time if compromised
The API key allows you to:
- Access OpenAI models from your code
- Build applications using ChatGPT, GPT-4, etc.
- Make API requests directly without using the web interface
- Integrate AI capabilities into your projects
| Screenshot File |
|---|
| Screenshots/Platform_Openai_Webpage.png |
| Screenshots/OPENAI_API_KEY.png |
| Screenshots/Open_notebook.png |
| Screenshots/Create_New_Secret_Key_Prompt.png |
| Screenshots/Create_API_Key.png |
| Screenshots/Authorize_Colaboratory.png |
| Screenshots/AfterAuthentication_webpage.png |
| Screenshots/After_Authroization_ColabwithGithub.png |
- Open your web browser
- Navigate to: https://platform.openai.com/docs/overview
- You should see the OpenAI platform homepage
View: platformopenai_webpage.png
Why create a new account?
- Receive free trial credits (~$5-18)
- Test features without payment concerns
- Separate billing for the workshop
Steps to Create Account:
- Click the "Sign up" button
- Enter your email address
- Create a strong password
- Verify your email by clicking the link sent to your inbox
- Complete your profile information:
- Full Name
- Organization (optional)
- Phone Number
- Use Case
- Accept the terms and conditions
- You're all set! Your account is created with free credits
- Click the "Log in" button
- Enter your email address
- Enter your password
- Complete any two-factor authentication if enabled
- You'll be logged into your account
View: AfterAuthentication_webpage.png
New OpenAI accounts receive:
- Free trial credits: Usually $5-$18 USD
- Valid for: 3 months from account creation
- Automatic expiration: After 3 months, credits expire
Check your credits:
- Click the profile icon (top-right corner)
- Select "Billing" from the dropdown
- View your "Credit balance"
Check available funds:
- Click the profile icon (top-right corner)
- Select "Billing" from the dropdown
- Check your "Credit balance" or "Payment method"
Note: If you're using a paid account, ensure you have:
- Valid payment method on file
- Sufficient credits/funds
- Billing alerts configured (optional but recommended)
- In the top-right corner, locate the profile icon (usually your initials or avatar)
- Click it to open the dropdown menu
- You should see several options:
- Your Profile
- Settings
- Billing
- API keys
- Select "Settings" to access more options
- From the profile dropdown, select "Settings"
- In the left sidebar, click "API keys"
- Or directly go to: https://platform.openai.com/account/api-keys
You should see:
- A list of existing API keys (if any)
- A "Create new secret key" button
- Click the "Create new secret key" button
- A dialog box will appear with options to configure your key
View: create_new_secret_key_prompt.png
Name Field:
OPENAI_API_KEY
Project Field:
- Leave as default (Personal) for now
- Or select your project if you have multiple
Other Settings:
- Keep all other options at their default values
Click "Create secret key" button
- After creating the key, you'll see a dialog with:
- Your secret key (long string of characters)
- A "Copy" button
-
Click the "Copy" button to copy to clipboard
-
Immediately paste and save it to:
- A secure password manager (recommended)
- A
.envfile in your project (for local development) - A secure text file (temporary, not recommended for production)
Example of an API Key:
sk-proj-abc123xyz789... (typically 48+ characters)
If you forgot to copy the key, don't worry:
- Go to: https://platform.openai.com/account/api-keys
- Find your API key in the list
- Click the "Edit" button (pencil icon)
- Click "Show" to reveal the key value
- Copy it now
DO:
- ✅ Store in a
.envfile (use.gitignoreto prevent uploading to GitHub) - ✅ Use environment variables in your application
- ✅ Rotate keys periodically
- ✅ Use a password manager to store securely
- ✅ Create separate keys for different projects
DON'T:
- ❌ Share your key publicly
- ❌ Commit your key to version control (Git)
- ❌ Hardcode the key in your source code
For Local Development:
-
In your project root folder, create a file named:
.env -
Add your key:
OPENAI_API_KEY=sk-proj-your-actual-key-here
- Create a
.gitignorefile (if not already exists) and add:
.env
.env.local
*.key
This prevents accidentally uploading your key to GitHub!
Option 1: Command Line (macOS/Linux)
export OPENAI_API_KEY='sk-proj-your-key-here'Option 2: Windows PowerShell
$env:OPENAI_API_KEY='sk-proj-your-key-here'Option 3: In Python Code
import os
from dotenv import load_dotenv
# Load from .env file
load_dotenv()
api_key = os.getenv('OPENAI_API_KEY')After completing Step 1, you have:
- ✅ OpenAI account created or accessed
- ✅ Free credits verified (or payment method added)
- ✅ API key generated
- ✅ API key securely stored
- ✅ Ready to use OpenAI's models in code
Google Colab is a cloud-based Jupyter notebook environment that allows you to run Python code without local setup. It provides free access to GPUs and is ideal for machine learning and AI development.
- Completed Step 1 (OpenAI API Key setup)
- Google account
- Internet connection
- Navigate to: https://colab.research.google.com/
- Click "Open notebook" button
- In the dialog, select "GitHub" tab
- Provide the GitHub URL:
https://github.com/AnSwati/LLM101 - Grant necessary authorization for Google Colab to access your GitHub
View: Authorize_Colaboratory.png
- Once authorization is complete, locate the
Basic_LLM_tutorial_prompt_engineering.ipynbfile - Click on it to open directly in Google Colab
- ✅ Google Colab environment set up
- ✅ GitHub repository linked to Colab
- ✅ Notebook ready for development
You're now ready to start working with LLMs in the Colab notebook environment.
Run the LLM101 code locally on your machine using Visual Studio Code (VSCode). This option gives you more control and doesn't require Google Colab.
- Completed Step 1 (OpenAI API Key setup)
- Python installed
- pip (Python package manager) installed
- Visual Studio Code installed
- Open VSCode terminal
- Run the following command:
git clone https://github.com/AnSwati/LLM101.git
cd LLM101- Visit: https://github.com/AnSwati/LLM101
- Click "Code" → "Download ZIP"
- Extract the ZIP file
- Open the folder in VSCode: File → Open Folder
Ensure Python and pip are installed:
python --version
pip --versionBoth should show version numbers. If not, install Python from: https://www.python.org/
Navigate to the project directory and install required packages:
pip install -r requirements.txtOr manually install the required packages:
pip install openai python-dotenv- Create a
.envfile in the project root folder - Add your OpenAI API key from Step 1:
OPENAI_API_KEY=sk-proj-your-actual-key-here
- Create a
.gitignorefile and add:
.env
.env.local
This prevents accidentally uploading your API key to GitHub.
- Open the Python script or notebook in VSCode
- Run the code:
python script_name.pyOr use VSCode's Run button (
- ✅ LLM101 repository cloned/downloaded
- ✅ Dependencies installed
- ✅ Environment configured
- ✅ Ready to run LLMs locally
Q: I get a RateLimit error when running the code A: This means you've exceeded your OpenAI API quota or run out of credits. Solutions:
- Create a new OpenAI account with fresh credits
- Use a different account with available credits
- Check your credit balance at: https://platform.openai.com/account/billing/overview
Q: Can I use Google Colab instead of VSCode? A: Yes! Google Colab works well for this course. You can:
- Provide the GitHub URL (as shown in Step 2)
- Upload the full ZIP file
- Upload to Google Drive and connect Colab
Q: What if I don't have Python installed? A: Install Python from https://www.python.org/ ensuring you check "Add Python to PATH" during installation.
Q: How do I know if my environment is set up correctly? A: Run the following commands in terminal:
python --version
pip --version
python -c "import openai; print(openai.__version__)"Q: How much do API calls cost? A: Pricing varies by model. Check https://openai.com/pricing for current rates. New accounts get free trial credits.
Q: Can I use one API key for multiple projects? A: Yes, but it's recommended to create separate keys for different projects for better tracking and security.
Q: What if I lose my API key? A: Create a new one! Old keys can be revoked from the API keys dashboard.
Q: Is my API key tied to my account? A: Yes, the key authenticates requests as your account. Charges will be billed to your account.
Q: Can I have multiple API keys? A: Yes! You can create as many as needed and manage them from the API keys page.
Solution:
- Upgrade to a paid account
- Add a payment method in Billing settings
- See current pricing at: https://openai.com/pricing
Solution:
- Verify the key is copied completely (check for missing characters)
- Ensure there are no extra spaces before/after the key
- Check if the key has been revoked (view in API keys page)
- Try creating a new key
Solution:
- Log out and log back in
- Try accessing directly: https://platform.openai.com/account/api-keys
- Ensure you have account access (not just team member)
- Clear browser cache and try again
Solution:
- Check if you're using a new or existing account
- View billing details to see payment methods
- Contact OpenAI support if unsure
Solution:
- You've made too many API calls too quickly
- Wait a few moments before making new requests
- Consider upgrading to a paid plan for higher limits
- OpenAI Platform: https://platform.openai.com
- OpenAI Documentation: https://platform.openai.com/docs/overview
- Pricing Information: https://openai.com/pricing
- API Reference: https://platform.openai.com/docs/api-reference
- Support: https://support.openai.com
- Python Installation: https://www.python.org/
- Visual Studio Code: https://code.visualstudio.com/
- Git: https://git-scm.com/