Official Python client library for calling Ollama's local and cloud models through chat, generate, embed and model-management APIs.
openai/openai-python
The official Python library for the OpenAI REST API, with sync and async clients and typed request and response models.
- Stars
- 31,893
- Forks
- 8,476
- Open issues
- 147
- Last commit
- 6 hours ago
What is it?
openai-python is the official Python client for the OpenAI REST API, supporting Python 3.10 and later. It exposes both synchronous and asynchronous clients built on HTTPX2, with type definitions for all request parameters and response fields. The library is generated from OpenAI's OpenAPI specification.
The primary interface is the Responses API, with the Chat Completions API still supported. The library also covers streaming over Server-Sent Events, a Realtime API client over WebSockets for text and audio, auto-paginating list methods, file uploads, webhook signature verification, and automatic retries with configurable timeouts. Responses are Pydantic models with helpers such as to_json() and to_dict().
The SDK also works with Azure OpenAI through a dedicated AzureOpenAI class, and with Amazon Bedrock's OpenAI-compatible API through a provider configuration that handles AWS authentication. Workload identity authentication for Kubernetes, Azure, GCP and X.509 mutual TLS is documented as well.
Key features
- 01Sync and async clients with identical interfaces
- 02Typed request params (TypedDict) and Pydantic response models
- 03Streaming responses via Server-Sent Events
- 04Realtime API over WebSockets for text and audio
- 05Auto-paginating list methods and file upload helpers
- 06Webhook signature verification and payload parsing
- 07Automatic retries and configurable timeouts
Use cases
- Building a Python backend that calls OpenAI models through the Responses or Chat Completions API
- Adding streaming text generation to an async web service
- Building low-latency voice or text conversational apps with the Realtime API
- Calling OpenAI models from Azure OpenAI or Amazon Bedrock with the same client code
Quick start
- 1
Install the library from PyPI
pip install openai - 2
Set your API key in the OPENAI_API_KEY environment variable
- 3
Create a client and call the Responses API as shown in the README
Things to know
- Requires an OpenAI API key and usage on OpenAI's paid API to make requests.
- Requires Python 3.10 or newer.
Topics
FAQ
- What is openai-python?
- The official Python library for the OpenAI REST API, with sync and async clients and typed request and response models. openai-python is the official Python client for the OpenAI REST API, supporting Python 3.10 and later. It exposes both synchronous and asynchronous clients built on HTTPX2, with type definitions for all request parameters and response fields. The library is generated from OpenAI's OpenAPI specification.
- Is openai-python free to use? What license does it have?
- openai-python is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
- Is openai-python still maintained?
- Actively maintained. The last commit to openai-python was on Oct 20, 2026.
- What can I use openai-python for?
- Building a Python backend that calls OpenAI models through the Responses or Chat Completions API Adding streaming text generation to an async web service Building low-latency voice or text conversational apps with the Realtime API Calling OpenAI models from Azure OpenAI or Amazon Bedrock with the same client code
- How do I install openai-python?
- Install the library from PyPI: pip install openai Set your API key in the OPENAI_API_KEY environment variable Create a client and call the Responses API as shown in the README
- Where can I get openai-python?
- The source code and installation instructions are on GitHub: https://github.com/openai/openai-python
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A Python framework for building LLM-powered applications and agents, with standard interfaces for models, embeddings, vector stores and third-party integrations.
A lightweight Python framework for building multi-agent workflows with tools, handoffs, guardrails, sessions and tracing, provider-agnostic across OpenAI and 100+ LLMs.
Official Python SDK for building Model Context Protocol servers and clients that connect LLM applications to tools, data and prompts.
A fast BPE tokeniser for OpenAI's models, used to convert text into tokens and back losslessly.
A command-line tool and Python library for running prompts and chats against remote and locally installed large language models.