Getting an OpenAI API Key

Image for the blog post, "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:


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!

Twitter v2 Update for Our Python Books and Videos

Intro to Python for Computer Science and Data Science: Learning to Program with AI, Big Data and the Cloud
Python for Programmers
Python Fundamentals
Updated September 7, 2023—We’re leaving this post up for anyone who might still have access to the Twitter APIs. The Twitter API’s free tier is now so limited that most of what we demonstrate in our Twitter chapter/lesson is longer available. Higher levels of paid access are too expensive for average users and students. The first paid tier ($100/month) provides basic capabilities and no streaming access (the free tier used to allow access to 1% of the daily live stream). The second paid tier gives more access and some streaming capability, but costs $5000/month and caps the total number of tweets at 1,000,000. Significant access to the live stream of tweets costs tens of thousands of dollars per month. There has been some discussion of an academic/research tier, but as of now, we have not seen any indication of when or if this will be available.
Attention users of the following Python products:
  • Intro to Python for Computer Science and Data Science: Learning to Program with AI, Big Data and the Cloud
  • Python for Programmers
  • Python Fundamentals LiveLessons

On August 18, 2022, we discovered that new Twitter developer accounts cannot access the Twitter v1.1 APIs on which we based Intro to Python‘s Chapter 13, Data Mining Twitter, and two case studies in Chapter 17, Big Data: Hadoop, Spark, NoSQL and IoT. Chapters 13 and 17 correspond to Chapters/Lessons 12 and 16 in our Python for Programmers book and Python Fundamentals LiveLessons videos.

Twitter users who already had Twitter developer accounts can still access the Twitter v1.1 APIs, but most of our Python content users will not fall into this category.

We’ve updated all our Twitter examples to the Twitter v2 APIs now. In addition, for the Intro to Python textbook, we need to update the instructor’s manual solutions and test-item file.

Updated chapters from our books are now available:

Updated instructor slides for Chapter 13 of the textbook should be available now in the Pearson Instructor Resource Center (IRC). Other updated instructor supplements will be updated there as we complete them.

Updated source-code files are available in the books’ IntroToPython and PythonForProgrammers GitHub repositories at https://github.com/pdeitel.

I’ll be re-recording the Python Fundamentals LiveLessons videos’ Lesson 12 soon.

If you have any questions, please email paul@deitel.com.

C How to Program, 9/e Errata

C How to Program, 9/e Cover

 This post contains the C How to Program, 9/e errata list. We’ll keep this up-to-date as we become aware of additional errata items. Please Contact Us with any you find.

Note: After publication, we discovered a bug in our authoring software that deleted some items in single quotes, like ‘A’, from our code tables. The source-code files were not affected, but occasionally a single-quoted item is missing from a code table in the text.

Last updated January 15, 2023

Chapter 2 — Intro to C Programming

  • Page 76, in Section 2.5: “+, / and %” should be “*, / and %.

Chapter 4 — Program Control

  • Page 149, “Notes on Integral Types”:

    –32767 should be –32768
    –2147483647 should be –2147483648
    –127 should be –128

Chapter 5 — Pointers

  • Page 214, Fig. 5.9: The example should produce factorial values through 20, not 21. The value displayed for factorial(21) in the program output is incorrect because unsigned long long is not capable of representing that value.

Chapter 7 — Pointers

  • Page 320, line 19 of Fig. 7.6 should be:
    while (*sPtr != '\0') {
  • Page 321, line 22 of Fig. 7.7, should be
    for (; *sPtr != '\0'; ++sPtr) {

Chapter 10 — Structures, Unions, Bit Manipulation and Enumerations

  • Page 496, Fig. 10.4, line 24 should be:
    putchar(value & displayMask ? '1' : '0');
  • Page 496, Fig. 10.4, line 28 should be:
    putchar(' ');
  • Page 496, Fig. 10.4, line 32 should be:
    putchar('\n');
  • Page 497, seventh text line on the page should be:
    putchar(value & displayMask ? '1' : '0');
  • Page 499, Fig. 10.5, line 53 should be:
    putchar(value & displayMask ? '1' : '0');
  • Page 499, Fig. 10.5, line 57 should be:
    putchar(' ');
  • Page 499, Fig. 10.5, line 61 should be:
    putchar('\n');
  • Page 502, Fig. 10.6, line 32 should be:
    putchar(value & displayMask ? '1' : '0')
  • Page 502, Fig. 10.6, line 36 should be:
    putchar(' ');
  • Page 502, Fig. 10.6 line 40 should be:
    putchar('\n');

Questions? Contact us!

C++20 for Programmers Now Available to O’Reilly Online Learning Subscribers

C++20 for Programmers Final Cover Image

C++20 for Programmers is now available to O’Reilly Online Learning Subscribers at:

https://learning.oreilly.com/library/view/c-20-for-programmers/9780136905776/

The print version should be in-stock mid-April. Preorder it at Amazon.com or other online book retailers.

Written for programmers with a background in another high-level language, in C++20 for Programmers, you’ll learn Modern C++ development hands-on using C++20 and its “Big Four” features:

  • Ranges
  • Concepts
  • Modules
  • Coroutines

In the context of 200+, hands-on, real-world code examples, you’ll quickly master Modern C++ coding idioms using popular compilers—Visual C++®, GNU® g++, Apple® Xcode® and LLVM®/Clang.

After the C++ fundamentals quick start, you’ll move on to C++ standard library containers array and vector; functional-style programming with C++20 Ranges and Views; strings, files and regular expressions; object-oriented programming with classes, inheritance, runtime polymorphism and static polymorphism; operator overloading, copy/move semantics, RAII and smart pointers; exceptions and a look forward to C++23 Contracts; standard library containers, iterators and algorithms; templates, C++20 Concepts and metaprogramming; C++20 Modules and large-scale development; and concurrency, parallelism, the C++17 and C++20 parallel standard library algorithms and C++20 Coroutines.

Features include:

  • Rich coverage of C++20’s “Big Four”: Ranges, Concepts, Modules and Coroutines
  • Objects-Natural Approach: Use standard libraries and open-source libraries to build significant applications with minimal code
  • Hundreds of real-world, live-code examples
  • Modern C++: C++20, 17, 14, 11 and a look to C++23
  • Compilers: Visual C++®, GNU® g++, Apple Xcode® Clang, LLVM®/Clang
  • Docker: GNU® GCC, LLVM®/Clang
  • Fundamentals: Control statements, functions, strings, references, pointers, files, exceptions
  • Object-oriented programming: Classes, objects, inheritance, runtime and static polymorphism, operator overloading, copy/move semantics, RAII, smart pointers
  • Functional-style programming: C++20 Ranges and Views, lambda expressions
  • Generic programming: Templates, C++20 Concepts and metaprogramming
  • C++20 Modules: Large-Scale Development
  • Concurrent programming: Concurrency, multithreading, parallel algorithms, C++20 Coroutines, coroutines support libraries, C++23 executors
  • Future: A look forward to Contracts, range-based parallel algorithms, standard library coroutine support and more

For more details, see the Preface, the Table of Contents diagram and reviewer testimonials.

Questions? Contact us!

Welcome to the New Deitel.com

Welcome to the new Deitel.com!

This new site will provide information about our

We’ll use our blog to discuss additional topics related to our books and training, announce new products, publish our live training schedule, and more.

Have comments, suggestions or questions? Contact us!

We hope you like the new design!

Pin It on Pinterest