- Install Python (3.10+).
- Create and activate a Python virtual environment.
- Install required Python packages (
openaiandjupyter). - Create an OpenAI API key and export it as an environment variable.
- Test the API from the command line (curl).
- Test the API from a Python Jupyter notebook.

1) Install Python
Download and install Python 3.10 or later from the official site: https://www.python.org/downloads/. Choose the installer that matches your OS (Windows, macOS, Linux). Example usage (can be run in the Python REPL or a script):
2) pip and creating a virtual environment
Modern Python installers include pip, which you’ll use to install libraries. Always use a virtual environment to isolate dependencies per project. Create and activate a virtual environment (Unix/macOS):3) Install the OpenAI Python package and Jupyter
With the virtual environment activated, install the required packages:requirements.txt for reproducible installs:
4) Create an OpenAI API key
- Sign in to the OpenAI platform: https://platform.openai.com/account/api-keys
- Create a new API key and give it a descriptive name (e.g.,
KodeKloud-dev). - Copy the secret value immediately — you will not be able to view the full secret after you close the dialog.


Keep your API key secret. Copy it now because you will not be able to see it again after closing the creation dialog.
- Add the export line to your shell startup file (e.g.,
~/.bashrc,~/.zshrc) on macOS/Linux. - Or add the PowerShell line to your PowerShell profile for Windows.

Do not commit your API key to version control or paste it into public forums. Use environment variables or a secrets manager for production applications.
5) Test the API from the command line (curl)
Use curl to verify the environment and theOPENAI_API_KEY variable. This example calls the Chat Completions endpoint (gpt-3.5-turbo) and asks a simple timezone question.
usage block (prompt_tokens, completion_tokens, total_tokens) helps you optimize prompts and control costs.
6) Test from a Jupyter notebook (Python)
Start Jupyter:
- Command-line access with curl is functional.
- Python access via the OpenAI client works inside Jupyter.
- The
OPENAI_API_KEYenvironment variable is being used correctly.