Skip to content
Agents tracked: 506 Releases (7d): 634 Agent status: 3 with issuesSince last limit reset: Claude 15d · Codex 0d For AI agents: Markdown Updated Nov 26, 2026

OpenAI Python Library

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

Model SDKsPYPI

GitHubWebsiteAPI page

1. License

License from PyPI license expression.

github.com/openai/openai-python

From the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error

What OpenAI Python Library does

This is OpenAI's own Python client, generated from its OpenAPI spec, with matching sync and async clients and built-in workload identity auth, so cloud jobs can call the API with short-lived tokens instead of a long-lived API key.

OpenAI Python Library popularity

86 / 100
Gid Score, #32 overall
94.8M
downloads a week, pypi
32.2K
GitHub stars
248
agent projects use it
OpenAI Python Library: downloads per weekPyPI, openai 93,708,497
OpenAI Python Library: GitHub starsopenai/openai-python 32,227

Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated

How OpenAI Python Library is used

  • OpenAI Python Library is a dependency in 248 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (15.3% of the 1,623 Python ones), #3 of 92 in model sdks.
  • Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 3,165; those are left out of every share on this page.
  • The most used alternative in our scan is Anthropic Python SDK (115 projects).
  • Projects that use it most often also use python-dotenv (70.2%), Pydantic (56.5%), Uvicorn (51.6%).
  • It is more common in projects set up for OpenClaw (10.8%) than for OpenCode (2.9%).

By coding agent

113 projects, 3.7%
109 projects, 3.3%
88 projects, 3.6%
36 projects, 10.8%
20 projects, 4.2%
15 projects, 3.2%
13 projects, 4.7%
10 projects, 2.9%

Often used with

In 70.2% of its projects
In 56.5% of its projects
In 51.6% of its projects
In 48.4% of its projects
In 44.8% of its projects
In 39.5% of its projects
In 33.9% of its projects
In 31.5% of its projects

OpenAI Python Library in practice

Strengths

Keyless auth for cloud workloads

Instead of an API key, the client can get short-lived tokens from Kubernetes service account tokens, Azure managed identity, GCP compute engine metadata, a custom JWT provider, or X.509 mutual TLS. You pass a <code>workload_identity</code> setting when you build the client.

Tunable token refresh

For workload identity, the README gives a default token refresh buffer of 1200 seconds (20 minutes) before expiration. You can change it with <code>refresh_buffer_seconds</code>.

Typed from the OpenAPI spec

Because the library is generated from OpenAI's OpenAPI specification, nested request parameters are <code>TypedDict</code>s. Responses are Pydantic models with <code>to_json()</code> and <code>to_dict()</code> helpers.

Same interface for async streaming and uploads

The streaming and file upload sections both say the async client uses the same interface as the sync one. For async uploads, a <code>PathLike</code> file is read asynchronously automatically.

Watch out for

Realtime errors come as events, not exceptions

In the Realtime API, an error arrives as an <code>error</code> 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.

Generate text with the Responses API

import os
from openai import OpenAI

client = OpenAI(
    # This is the default and can be omitted
    api_key=os.environ.get("OPENAI_API_KEY"),
)

response = client.responses.create(
    model="gpt-5.5",
    instructions="You are a coding assistant that talks like a pirate.",
    input="How do I check if a Python object is an instance of a class?",
)

print(response.output_text)

More about OpenAI Python Library

Agent Skills for it
  • : Skills Catalog for Codex
  • openai-docs: Use when the user asks how to build with OpenAI products or APIs and needs up-to-date official documentation with citations (for example: Co
  • openai-tts: OpenAI Text-to-Speech API for high-quality speech synthesis. Use for generating natural-sounding audio from text with customizable voices an
  • openai: Check OpenAI API access and list the models your key can use. Read-only. Trigger phrases: openai, openai models, what models do I have acces
  • openai-frontend-design: This skill should be used when the user asks for "visual concepts", "image-led website design", or "concept fidelity". Create visual concept

See all

Head to head
Packages around it
  • python-dotenv: Loads .env files
  • pydantic: Data models and validation
  • uvicorn: ASGI server
  • fastapi: Web API framework
  • requests: HTTP client
  • numpy: Numeric arrays
More in Model SDKs

Alternatives

OpenAI Python Library This page

Apache-2.0Gid 8694.8M/wk

Anthropic Python SDK

Official Python library for calling Claude via the Anthropic API.

Apache-2.0Gid 7451.5M/wk

Google GenAI Python SDK

Official Python SDK for Google's generative AI models including Gemini.

Apache-2.0Gid 7340.7M/wk

DashScope SDK

Official Python client SDK for Alibaba DashScope API to call language models.

Apache-2.0Gid 43339K/wk

Mistral AI SDK

Official Python SDK for the Mistral AI API to call Mistral language models.

Apache-2.0Gid 503.3M/wk

Cohere

Official SDK for accessing Cohere's language models and APIs.

MITGid 502.9M/wk

Compare OpenAI Python Library with another tool

Get started

Install it.

pip install openai

Rules for your agent

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.

AgentGid articles about OpenAI Python Library

All guides