# OpenAI Python Library — card for AI agents

Official Python SDK to call OpenAI APIs including GPT models and embeddings.

Category: Model SDKs · PyPI package `openai` · latest version 3.42.0 (checked 2026-11-01)
Install: `pip install openai`
License: Apache-2.0 (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Rules for AI agents (paste into AGENTS.md or CLAUDE.md)

## OpenAI Python Library
- Prefer loading `OPENAI_API_KEY` from the environment over passing `api_key`. The README recommends python-dotenv and a `.env` file so the key is not stored in source control.
- Use `client.responses.create` for new code. The README calls the Responses API the primary API and Chat Completions the previous standard.
- In async code, use `AsyncOpenAI` and `await` every call. Use `async for` when streaming or paginating.
- Iterate list calls directly instead of writing manual page loops. Use `.has_next_page()` and `.get_next_page()` only when you need page-level control.
- In Realtime connections, check `event.type == 'error'` inside the event loop. The SDK does not raise on error events.
- When uploading `io.BytesIO`, pass a `(filename, contents, media type)` tuple so the API can detect the format.
- With X.509 workload identity, build a new client to change identity. X.509 currently covers HTTP APIs, not Realtime or WebSockets.

## Agent Skills for it
- Official: openai/skills (43 skills): `npx skills add openai/skills`
- openai-docs from davila7/claude-code-templates: `npx skills add davila7/claude-code-templates --skill openai-docs`
- openai-tts from benchflow-ai/skillsbench: `npx skills add benchflow-ai/skillsbench --skill openai-tts`
- openai from Anil-matcha/awesome-muse-connectors: `npx skills add Anil-matcha/awesome-muse-connectors --skill openai`
- openai-frontend-design from fcakyon/claude-codex-settings: `npx skills add fcakyon/claude-codex-settings --skill openai-frontend-design`

## What it is
- `openai` on PyPI is the official Python library for the OpenAI API. The repository was created in 2020 and is Apache-2.0 licensed. It runs on Python 3.10 and newer. The current release is 3.28.0.
- The README says the library is generated from OpenAI's OpenAPI specification. It ships type definitions for every request parameter and response field. You create an `OpenAI` client and call methods such as `client.responses.create`. For async code you use `AsyncOpenAI`, `await` each call, and use `async for` when streaming or paginating. The README names the Responses API as the primary way to talk to models. The older Chat Completions API is still available.
- The README also covers vision input, streaming over Server-Sent Events, a WebSocket-based Realtime API, auto-paginated list calls and file uploads. It is written for Python applications that call OpenAI models. That includes services on cloud-managed Kubernetes, Azure or Google Cloud that want short-lived credentials.

## Caveats
- Realtime errors come as events, not exceptions: In the Realtime API, an error arrives as an `error` event and the connection stays open. The README says the SDK raises no exception for it, so your event loop has to handle it.
- X.509 auth covers HTTP APIs only: The README says mutual-TLS workload identity currently supports HTTP APIs. Realtime and WebSockets are not included.
- X.509 identity is fixed per client: Identity settings are read when the client is built, so changing identity means a new client. Azure clients do not support X.509 workload identity.
- Certificate handling stays with you: In X.509 mode the SDK exchanges and caches tokens. Certificate files, private keys, server trust, proxies and rotation are left to your application and transport.
- Custom HTTP setups need migration: HTTPX2 is now the default HTTP client. If you customized the HTTP layer, the README points you to a separate migration guide.

## Numbers (AgentGid data)
- Gid Score: 86.0 (#32 of all tools, 1 of 92 in its category)
- Used in 248 public projects set up for AI coding agents (4.0%)
- Downloads last week: 94,791,561 (as of 2026-11-24), +14.6% over 4 weeks
- GitHub stars: 32,227 (as of 2026-11-24)
- Last push: 2026-11-24

## Often used with
python-dotenv 70.2%, Pydantic 56.5%, Uvicorn 51.6%, FastAPI 48.4%, Requests 44.8%, NumPy 39.5%

## Checked alternatives (same job)
- Anthropic Python SDK: https://agentgid.com/tools/anthropic/agent.md
- Google GenAI Python SDK: https://agentgid.com/tools/google-genai-pypi/agent.md
- DashScope SDK: https://agentgid.com/tools/dashscope/agent.md
- Mistral AI SDK: https://agentgid.com/tools/mistralai/agent.md
- Cohere: https://agentgid.com/tools/cohere/agent.md

## Links
- AgentGid page: https://agentgid.com/tools/openai-pypi/
- Homepage: https://github.com/openai/openai-python
- Repository: https://github.com/openai/openai-python
- Source: https://github.com/openai/openai-python#readme
- Source: https://github.com/openai/openai-python
- Source: https://github.com/openai/openai-python/releases
- Source: https://pypi.org/project/openai/

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
