The OpenAI Python library gives you programmatic access to the OpenAI REST API from any Python 3.10+ application. It's built for developers integrating GPT models, embeddings, fine-tuning, file uploads, or realtime audio/text conversations into their own Python code, whether that's a backend service, a CLI tool, or a data pipeline.
The library is generated from OpenAI's OpenAPI specification using Stainless, so its method signatures and types track the API surface closely. It ships both a synchronous OpenAI client and an asynchronous AsyncOpenAI client with identical interfaces, backed by httpx (with optional aiohttp or experimental httpx2 transports).
TypedDicts and responses are Pydantic models, giving autocomplete, validation, and .to_json()/.to_dict() helpers.OpenAI and AsyncOpenAI expose the same API surface, so switching between blocking and asyncio code is a matter of swapping the class and adding await.client.responses.create) and the long-supported Chat Completions API (client.chat.completions.create).bytes, PathLike objects, or (filename, contents, media type) tuples for endpoints that accept file input.client.webhooks.unwrap() verifies and parses incoming webhook payloads from OpenAI.This library is not a good fit if you need a non-Python language binding (OpenAI maintains separate SDKs for other languages), if you're looking for a client for a different LLM provider, or if you want a higher-level agent/orchestration framework rather than a direct API client. It's also not meant for offline or local model inference; it only talks to OpenAI's hosted API.
Install from PyPI:
pip install openai
Set your API key as an environment variable (recommended over hardcoding it):
export OPENAI_API_KEY="your-api-key"
Or load it from a .env file using python-dotenv. Then use the client:
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
response = client.responses.create(
model="gpt-5.5",
input="Hello, world",
)
print(response.output_text)
For improved async concurrency, install the optional aiohttp backend (requires Python 3.10+):
pip install openai[aiohttp]
For experimental HTTPX2 transport support:
pip install 'openai[httpx2]'
Requires Python 3.10 or later in all cases.