This is an early release preview. You may encounter bugs.
OpenAI Python logo
Unclaimed

Tool coding

OpenAI Python

Python client for the OpenAI REST API with synchronous and asynchronous clients, typed requests and responses, and streaming

Built by OpenAI

A+ 90/100 GitHub score ? This grade is derived from GitHub signals, not user votes. Open for the full breakdown.
Discussion

01 / Summary

About OpenAI Python.

OpenAI Python is the official Python client for the OpenAI REST API. It is generated from the OpenAI OpenAPI specification, ships type definitions for every request parameter and response field, and offers both synchronous and asynchronous clients built on HTTPX2. Requests are typed dictionaries and responses are Pydantic models with helpers for serializing to JSON or a dictionary.

The primary interface for generating text is the Responses API, with the older Chat Completions API still available. Beyond text, the client covers image inputs for vision, file uploads, server-sent event streaming, and the Realtime API, which carries low-latency text and audio conversations with function calling over a WebSocket connection.

Authentication uses an API key or workload identity: short-lived tokens from Kubernetes service accounts, Azure managed identity, Google Cloud metadata, X.509 mutual TLS, or a custom token provider. The same library targets Azure OpenAI through a dedicated client class and Amazon Bedrock's OpenAI-compatible API through a Bedrock provider that uses the standard AWS credential chain.

  • Typed client: type definitions for all request params and response fields, with editor autocomplete
  • Sync and async clients: synchronous and asynchronous clients on HTTPX2, with an optional aiohttp backend
  • Responses API: the primary interface for text generation, alongside Chat Completions
  • Streaming: streamed responses over server-sent events
  • Realtime API: text and audio input and output with function calling over WebSockets
  • Vision and file uploads: image inputs by URL or base64, and file uploads from paths, bytes, or file objects
  • Workload identity: short-lived tokens from Kubernetes, Azure, Google Cloud, X.509 mutual TLS, or a custom provider in place of long-lived API keys
  • Auto-pagination: iterators that fetch successive pages of list responses automatically
  • Webhook verification: parses and verifies signed webhook payloads
  • Errors, retries, and timeouts: typed exceptions, automatic retries with exponential backoff, request IDs, and configurable timeouts
  • Raw and custom requests: access to raw response headers, streaming response bodies, and undocumented endpoints or params
  • Azure OpenAI and Amazon Bedrock: a dedicated Azure client and a Bedrock provider for Amazon Bedrock's OpenAI-compatible API

02 / Discussion CREDIBILITY-GATED

Discussion

Reading is open to everyone. Posting and voting need a verified identity or a GitHub grade of B or higher.

  • No discussions yet.

04 / Build

Build with OpenAI Python.

Browse the catalog for frameworks, tools, and harnesses, each scored on real GitHub credibility.

Get OpenAI Python →

Browse the catalog