Pythonopenaiv1.54.0
PythonBeginner-friendly

openai

Official Python SDK for the OpenAI API — call GPT-4, DALL-E, Whisper, and Embeddings with a clean async-first interface.

aillmgptapi-clientasync
The Problem

You want to add AI capabilities — text generation, image creation, speech recognition, or embeddings — to your Python application without managing HTTP requests and response parsing yourself.

Mental Model

The SDK wraps REST endpoints in typed Python objects. Create an OpenAI client, then call client.chat.completions.create() with a list of message dicts. The response is a structured object with .choices[0].message.content. Everything has an async equivalent.

60-second start

Send a chat message and get a response

from openai import OpenAI

client = OpenAI()  # reads OPENAI_API_KEY from env

response = client.chat.completions.create(
    model='gpt-4o',
    messages=[
        {'role': 'system', 'content': 'You are a helpful assistant.'},
        {'role': 'user', 'content': 'Explain async/await in Python in one paragraph.'}
    ]
)
print(response.choices[0].message.content)

Use it when

Integrating GPT-4/3.5 into apps, generating embeddings for semantic search, transcribing audio with Whisper, generating images with DALL-E, or building agentic workflows with tool calling.

Skip it when

When you need to run models locally (use ollama or transformers), when cost is a hard constraint for high-volume tasks, or when you need a specific open-source model.

Alternatives
anthropicClaude models — often better for long documents and coding
litellmUnified interface to 100+ LLM providers
langchainOrchestration framework for complex LLM pipelines

Ready to explore the full API?

See every class, function, and relationship in an interactive graph.