Image for the blog post, "Getting an OpenAI API Key"
  • facebook
  • Twitter
  • LinkedIn
  • reddit
  • Hacker News
  • Print

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:


Step 2: Get an OpenAI Developer API Key

  1. Sign into your account at https://platform.openai.com/docs/overview.
  2. In the upper-right corner, press the settings icon.
  3. In the left column under the Project heading, select API keys.
  4. Press + Create new secret key.
  5. Optionally, specify an API key Name, then press Create secret key button.
  6. 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

  1. Open Terminal.
  2. Open the configuration file ~/.zshrc using a text editor (e.g., nano ~/.zshrc).
    • nano ~/.zshrc
  3. Scroll to the end of the file and add the following line, replacing YourAPIKey with the lengthy alphanumeric key you copied previously:
    • export OPENAI_API_KEY="YourAPIKey"
  4. Save and close the file.
  5. Run the following command in the Terminal to apply the changes:
    • source ~/.zshrc

Storing the API Key on Windows

  1. In the taskbar’s Search field, enter SystemPropertiesAdvanced, and press Enter.
  2. In the System Properties dialog, press the Environment Variables… button.
  3. Under User variables, press New….
  4. Enter the Variable name as OPENAI_API_KEY.
  5. For the Variable value, paste in the lengthy alphanumeric API key you copied previously.
  6. Press OK to save the environment variable, then press OK in the System Properties dialog to close it.
  7. 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!

Pin It on Pinterest

Share This Page