Getting an OpenAI API Key

Updated October 28, 2025
This guide provides instructions for setting up your OpenAI Developer Account and securely storing your API Key. This is essential for using our book and video products that interact with the OpenAI APIs.
🔑 Step 1: Get an OpenAI Developer Account
Signup: You’ll need to sign up for an account. Use the following link: https://platform.openai.com/signup.
Additional relevant info:
- Pricing: Information on pricing for the API can be found here: https://openai.com/api/pricing/.
- Rate Limits: You may also want to review the rate limits documentation: https://platform.openai.com/docs/guides/rate-limits/rate-limits.
Step 2: Get an OpenAI Developer API Key
- Sign into your account at https://platform.openai.com/docs/overview.
- In the upper-right corner, press the settings icon.
- In the left column under the Project heading, select API keys.
- Press + Create new secret key.
- Optionally, specify an API key Name, then press Create secret key button.
- Press the Copy button to copy the alphanumeric key to the clipboard.Â
Step 3: Storing the API Key as an Environment Variable
For security, it’s best practice to store your API key as an environment variable rather than directly in your code. We’ll use the variable name OPENAI_API_KEY.
Storing the API Key in macOS
- Open Terminal.
- Open the configuration file
~/.zshrcusing a text editor (e.g.,nano ~/.zshrc).nano ~/.zshrc
- Scroll to the end of the file and add the following line, replacing
YourAPIKeywith the lengthy alphanumeric key you copied previously:export OPENAI_API_KEY="YourAPIKey"
- Save and close the file.
- Run the following command in the Terminal to apply the changes:
source ~/.zshrc
Storing the API Key on Windows
- In the taskbar’s Search field, enter
SystemPropertiesAdvanced, and press Enter. - In the System Properties dialog, press the Environment Variables… button.
- Under User variables, press New….
- Enter the Variable name as
OPENAI_API_KEY. - For the Variable value, paste in the lengthy alphanumeric API key you copied previously.
- Press OK to save the environment variable, then press OK in the System Properties dialog to close it.
- Restart your command line before launching iPython or Jupyter Lab to ensure the new variable is loaded.
You are now ready to use the OpenAI APIs with your Deitel products!