Navigate:
OpenAI Python
~$OPEN0.6%

openai-python: Official Python library for OpenAI API

Type-safe Python client for OpenAI's REST API.

LIVE RANKINGS • 11:36 AM • STEADY
OVERALL
#110
173
AI & ML
#48
43
30 DAY RANKING TREND
ovr#110
·AI#48
STARS
30.1K
FORKS
4.6K
7D STARS
+164
7D FORKS
+17
Tags:
See Repo:
Share:

Learn more about OpenAI Python

The openai-python library is the official Python client for interacting with OpenAI's REST API, providing type-safe bindings for all API endpoints including chat completions, embeddings, image generation, and audio processing. It implements a synchronous and asynchronous HTTP client architecture that handles request serialization, authentication via API keys, automatic retries with exponential backoff, and response deserialization into strongly-typed Python objects. The library supports multimodal interactions by encoding various input types such as text prompts, base64-encoded images, and file uploads into properly formatted API request payloads that conform to OpenAI's JSON schema specifications. It provides Pydantic-based model validation for request parameters and response objects, enabling IDE autocompletion and compile-time type checking while maintaining backwards compatibility with OpenAI's evolving API surface.

OpenAI Python

1

Generated from OpenAPI spec

The library is automatically generated from OpenAI's OpenAPI specification using Stainless, ensuring consistency with the API and reducing manual maintenance of endpoint definitions.

2

Dual sync and async clients

Provides both synchronous and asynchronous client implementations powered by httpx, with optional aiohttp backend for applications requiring higher concurrency throughput.

3

Complete type coverage

Includes comprehensive type definitions for all request parameters and response fields, enabling IDE autocompletion and static type checking across the entire API surface.


import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ.get("OPENAI_API_KEY"),
)

response = client.responses.create(
    model="gpt-5.2",
    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)


[ EXPLORE MORE ]

Related Repositories

Discover similar tools and frameworks used by developers