Environment:Openai Openai python Python 3 9 Plus
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, API_Client |
| Last Updated | 2026-02-15 10:00 GMT |
Overview
Python 3.9+ environment with httpx, pydantic, anyio, and other core dependencies required to run the OpenAI Python SDK v2.21.0.
Description
This environment defines the baseline runtime requirements for the openai Python SDK. It is a pure Python environment (no GPU or native hardware requirements) that provides the HTTP client layer, data validation, async support, and JSON parsing needed to interact with the OpenAI API. The SDK supports Pydantic v1 (1.9+) and v2/v3 (< 3) through a runtime compatibility layer, and runs on Linux, macOS, and Windows.
Usage
This is the mandatory baseline environment for all OpenAI SDK functionality. Every Implementation page in this wiki requires this environment. It must be set up before using any chat completions, embeddings, image generation, fine-tuning, audio, or Responses API features.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Linux, macOS, or Windows | All major platforms supported (OS Independent) |
| Python | >= 3.9 | Tested on 3.9, 3.10, 3.11, 3.12, 3.13, 3.14 |
| Disk | Minimal | SDK is a lightweight HTTP client; no large model downloads |
Dependencies
System Packages
No system-level packages required for the core SDK.
Python Packages
- `httpx` >= 0.23.0, < 1 — HTTP client library
- `pydantic` >= 1.9.0, < 3 — Data validation (supports both v1 and v2)
- `typing-extensions` >= 4.11, < 5 — Backported type hints
- `anyio` >= 3.5.0, < 5 — Async compatibility layer
- `distro` >= 1.7.0, < 2 — Linux distribution detection
- `sniffio` — Async library detection
- `tqdm` > 4 — Progress bars (used for file uploads)
- `jiter` >= 0.10.0, < 1 — Fast JSON parser
Credentials
The following environment variables must be set:
- `OPENAI_API_KEY`: Required. OpenAI API key for authentication. Can also be passed directly to the client constructor.
Optional environment variables:
- `OPENAI_ORG_ID`: Organization ID for API requests.
- `OPENAI_PROJECT_ID`: Project ID for scoping API requests.
- `OPENAI_BASE_URL`: Custom API base URL (defaults to `https://api.openai.com/v1`).
- `OPENAI_WEBHOOK_SECRET`: Secret for webhook signature verification.
- `OPENAI_LOG`: Set to `debug` to enable debug logging.
- `DEFER_PYDANTIC_BUILD`: Controls Pydantic v2 model building behavior (default: `true`).
Quick Install
# Install core SDK
pip install openai
# Or install specific version
pip install openai==2.21.0
Code Evidence
API key resolution from `_client.py:136-141`:
if api_key is None:
api_key = os.environ.get("OPENAI_API_KEY")
if api_key is None:
raise OpenAIError(
"The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable"
)
Pydantic version detection from `_compat.py:20`:
PYDANTIC_V1 = pydantic.VERSION.startswith("1.")
Python version from `pyproject.toml:22`:
requires-python = ">= 3.9"
Core dependencies from `pyproject.toml:11-19`:
dependencies = [
"httpx>=0.23.0, <1",
"pydantic>=1.9.0, <3",
"typing-extensions>=4.11, <5",
"anyio>=3.5.0, <5",
"distro>=1.7.0, <2",
"sniffio",
"tqdm > 4",
"jiter>=0.10.0, <1",
]
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable` | No API key provided | Set `OPENAI_API_KEY` environment variable or pass `api_key` to the client constructor |
| `MissingDependencyError: missing numpy` | Optional dependency not installed | Install the appropriate extra: `pip install openai[voice_helpers]` |
| `You need to install openai[realtime] to use this method` | WebSocket dependency missing | `pip install openai[realtime]` |
Compatibility Notes
- Pydantic v1 vs v2: The SDK supports both Pydantic v1 (>= 1.9.0) and v2 (< 3) through a runtime compatibility layer in `_compat.py`. Methods like `parse_obj()` vs `model_validate()` are automatically handled.
- Python 3.10+: Union type syntax (`X | Y`) support is detected at runtime for type introspection.
- Python 3.12+: `TypeAliasType` support and secure tarfile extraction are conditionally enabled.
- Windows: Fully supported. No platform-specific limitations for the core SDK.
- macOS: Fully supported.
- Linux: Fully supported. `distro` package is used for distribution detection in user-agent strings.
Related Pages
- Implementation:Openai_Openai_python_OpenAI_Client_Init
- Implementation:Openai_Openai_python_Completions_Create
- Implementation:Openai_Openai_python_Chat_Completion_Response
- Implementation:Openai_Openai_python_API_Error_Hierarchy
- Implementation:Openai_Openai_python_Pydantic_Function_Tool
- Implementation:Openai_Openai_python_Responses_Create
- Implementation:Openai_Openai_python_Response_Model
- Implementation:Openai_Openai_python_Input_Tokens_Count
- Implementation:Openai_Openai_python_Realtime_Connect
- Implementation:Openai_Openai_python_Realtime_Session_Update
- Implementation:Openai_Openai_python_Realtime_Conversation_Item_Create
- Implementation:Openai_Openai_python_Realtime_Server_Events
- Implementation:Openai_Openai_python_Realtime_Error_Event
- Implementation:Openai_Openai_python_Speech_Create
- Implementation:Openai_Openai_python_Transcriptions_Create
- Implementation:Openai_Openai_python_Translations_Create
- Implementation:Openai_Openai_python_Local_Audio_Player
- Implementation:Openai_Openai_python_Images_Generate
- Implementation:Openai_Openai_python_Images_Edit
- Implementation:Openai_Openai_python_Images_Response_Model
- Implementation:Openai_Openai_python_Validators_Framework
- Implementation:Openai_Openai_python_Files_Create
- Implementation:Openai_Openai_python_Fine_Tuning_Jobs_Create
- Implementation:Openai_Openai_python_Fine_Tuning_Jobs_Retrieve
- Implementation:Openai_Openai_python_Fine_Tuned_Model_Inference
- Implementation:Openai_Openai_python_Embeddings_Create
- Implementation:Openai_Openai_python_Embedding_Response_Model