OpenAI Python SDK

2.x · active · verified Sat Feb 28

Official Python SDK for the OpenAI API. As of v2.x, the Agents SDK requires openai v2. The Assistants API is deprecated and will be removed August 26, 2026. Use the Responses API for new agent builds.

Warnings

Install

Imports

Quickstart

Minimal call using the Responses API (current recommended approach).

from openai import OpenAI

client = OpenAI()  # reads OPENAI_API_KEY from env
response = client.responses.create(
    model='gpt-4o',
    input='What is the capital of France?'
)
print(response.output_text)

view raw JSON →