The official openai Python package (v2.31.0+ as of April 2026) provides a typed, ergonomic interface to all OpenAI APIs. It handles authentication, retries, streaming, and error handling automatically.
Environment Setup
The SDK automatically reads OPENAI_API_KEY from the environment. You never need to pass it explicitly unless you want to override it. The package supports Python 3.8+ and uses httpx as its HTTP client under the hood.
Why pin and bump on a schedule
The openai SDK ships fast. Major versions occasionally break parameter shapes (max_tokens → max_completion_tokens is a recent example). An unpinned dependency means a Friday afternoon deploy can silently start failing on Monday because pip resolved a newer minor version.
The pattern that works: pin a known-good lower bound (e.g. openai>=1.78,<2) in requirements.txt. Lock the resolved version in a lockfile (uv.lock, poetry.lock, or pip-compile output). Bump the lower bound deliberately on a schedule, not by accident.