How to Install openai in Python

v2.31.0 General Purpose Python >=3.9 Apache-2.0

The official Python library for the openai API

Install pip install openai

What is openai?

The official Python library for the openai API

The OpenAI Python library provides convenient access to the OpenAI REST API from any Python 3.9+ application. The library includes type definitions for all request params and response fields, and offers both synchronous and asynchronous clients powered by httpx.

It is generated from our OpenAPI specification with Stainless.

The REST API documentation can be found on platform.openai.com. The full API of this library can be found in api.md.

Quick Start

Minimal example to get started with openai:

from openai import OpenAI

client = OpenAI()  # uses OPENAI_API_KEY env var

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)

Installation

pip (standard)

pip install openai

Virtual environment (recommended)

python -m venv venv
source venv/bin/activate   # Windows: venv\Scripts\activate
pip install openai

pip3

pip3 install openai

conda

conda install -c conda-forge openai

Poetry

poetry add openai

Dependencies

Installing openai will also install these packages:

Verify the Installation

After installing, confirm the package is available:

python -c "import openai; print(openai.__version__)"

If this prints a version number, installation succeeded. If you see a ModuleNotFoundError, see the errors section below.

Installation Errors

Common errors when installing openai with pip.

ModuleNotFoundError: No module named 'openai'

Cause: The package is not installed in the current Python environment.

Fix: Run pip install openai. If using a virtual environment, ensure it is activated first.

ModuleNotFoundError: No module named 'openai' (installed but still failing)

Cause: pip installed the package into a different Python than the one running your script.

Fix: Use python -m pip install openai to install into the interpreter you are running.

ImportError: cannot import name 'X' from 'openai'

Cause: The function or class does not exist in the installed version.

Fix: Check the version with pip show openai and upgrade with pip install --upgrade openai.

pip: command not found

Cause: pip is not in PATH or Python was not added to PATH during installation.

Fix: Try python -m pip install openai. On macOS/Linux try pip3.

PermissionError: [Errno 13] Permission denied

Cause: No write access to the system Python package directory.

Fix: Use a virtual environment, or add --user: pip install --user openai

SSL: CERTIFICATE_VERIFY_FAILED

Cause: pip cannot verify PyPI's SSL certificate — common behind corporate proxies.

Fix: Try: pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org openai

Runtime Errors

Common errors when using openai after installation.

openai.AuthenticationError: Incorrect API key

Cause: The API key is missing, wrong, or revoked.

Fix: Set OPENAI_API_KEY environment variable or pass api_key='sk-...' to the client.

openai.RateLimitError

Cause: Too many requests or usage quota exceeded.

Fix: Add retry logic with backoff. Use the tenacity library or time.sleep() between requests.

Recent Releases

VersionReleased
2.31.0 latest 2026-04-08
2.30.0 2026-03-25
2.29.0 2026-03-17
2.27.0 2026-03-13
2.28.0 2026-03-13

Full release history on PyPI →

Manage openai

Upgrade to latest version

pip install --upgrade openai

Install a specific version

pip install openai==2.31.0

Uninstall

pip uninstall openai

Check what is installed

pip show openai

Last updated: 2026-04-11 • Data from PyPI