pydoc > openai

πŸ“¦ NAME

openai – File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

πŸš€ Quick Reference

Use CaseCommandDescription
πŸ”‘ Create a clientclient = OpenAI()Sync client, picks up OPENAI_API_KEY from env
⚑ Async clientclient = AsyncOpenAI()Async client, same env‑based auth
πŸ’¬ Chat completionclient.chat.completions.create(...)Send a prompt and get a model response
πŸ“Š Embeddingsclient.embeddings.create(...)Get vector representation of text
πŸ–ΌοΈ Image generationclient.images.generate(...)Generate images from a prompt
🎡 Audio transcriptionclient.audio.transcriptions.create(...)Transcribe audio to text
πŸ“ File uploadclient.files.create(...)Upload files for fine‑tuning or assistants
πŸ—οΈ Fine‑tuningclient.fine_tuning.jobs.create(...)Create a fine‑tuning job
πŸ›‘ Moderationclient.moderations.create(...)Check if content is harmful
πŸŒ€ Streamingstream = client.chat.completions.create(..., stream=True)Iterate over response chunks
πŸ“‹ List modelsclient.models.list()List available models
πŸ”„ Copy clientclient.copy(timeout=30)Clone with overridden options
πŸ“¦ Raw responseclient.with_raw_response.chat...Access the raw HTTP response
🌊 Streaming responseclient.with_streaming_response.chat...Get a streaming context manager

πŸ“ PACKAGE CONTENTS

πŸ“‚ SUBMODULES

πŸ›οΈ CLASSES

Exception Hierarchy

builtins.Exception
 └─ OpenAIError
     β”œβ”€ APIError
     β”‚   β”œβ”€ APIConnectionError
     β”‚   β”‚   └─ APITimeoutError
     β”‚   β”œβ”€ APIResponseValidationError
     β”‚   └─ APIStatusError
     β”‚       β”œβ”€ AuthenticationError
     β”‚       β”‚   └─ OAuthError
     β”‚       β”œβ”€ BadRequestError
     β”‚       β”œβ”€ ConflictError
     β”‚       β”œβ”€ InternalServerError
     β”‚       β”œβ”€ NotFoundError
     β”‚       β”œβ”€ PermissionDeniedError
     β”‚       β”œβ”€ RateLimitError
     β”‚       └─ UnprocessableEntityError
     β”œβ”€ ContentFilterFinishReasonError
     β”œβ”€ LengthFinishReasonError
     β”œβ”€ WebSocketConnectionClosedError
     └─ WebSocketQueueFullError
builtins.ValueError
 └─ InvalidWebhookSignatureError

Client Classes

openai._base_client.AsyncAPIClient
 └─ AsyncOpenAI
     └─ AsyncBedrockOpenAI

openai._base_client.SyncAPIClient
 └─ OpenAI
     └─ BedrockOpenAI

Streaming & Helpers

typing.Generic
 β”œβ”€ AsyncStream
 └─ Stream
pydantic.main.BaseModel
 └─ BaseModel (openai)
builtins.dict
 β”œβ”€ ReconnectingOverrides
 └─ RequestOptions
builtins.object
 β”œβ”€ NotGiven
 β”œβ”€ Omit
 β”œβ”€ Timeout
 └─ ReconnectingEvent

OpenAI

openai.OpenAI – Synchronous OpenAI client.

Constructor: OpenAI(*, api_key, organization, project, base_url, timeout, max_retries, ...)
Automatically infers credentials from environment variables (OPENAI_API_KEY, OPENAI_ORG_ID, etc.).

Key properties: chat, completions, embeddings, files, images, audio, models, moderations, fine_tuning, batches, beta, realtime, responses, conversations, vector_stores, uploads, containers, skills, videos, webhooks, evals.

Methods: copy() – create a new client with overridden options; close() – close the underlying HTTP client; get(), post(), put(), patch(), delete() – low‑level HTTP methods; with_raw_response, with_streaming_response – access raw HTTP responses.

AsyncOpenAI

openai.AsyncOpenAI – Asynchronous OpenAI client.

Same interface as OpenAI but all methods are async. Constructor accepts an optional api_key: Callable[[], Awaitable[str]] for dynamic credentials.

Key properties: same as sync client.

Async methods: aenter(), aexit(), aclose(), adelete(), aget(), apost(), etc.

BaseModel

openai.BaseModel – Base pydantic model for all API objects.

Extends pydantic.BaseModel with extra = 'allow' and custom serialisation helpers.

Key methods: to_dict() – convert to dict (with use_api_names, exclude_unset); to_json() – JSON string; construct() – build without validation.

Stream / AsyncStream

Stream[_T] – Iterable over a synchronous server‑sent event stream.

AsyncStream[_T] – Async version.

Both provide __iter__/__aiter__, close(), and context manager support.

Exception Classes

NotGiven / Omit

openai.NotGiven – sentinel to distinguish between β€œnot passed” and β€œpassed as None”.

openai.Omit – sentinel to explicitly omit a header or parameter (e.g., Content-Type).

Other Classes

πŸ”§ FUNCTIONS

πŸ“Š DATA

🏷️ VERSION

2.44.0

πŸ“„ FILE

/home/chedong/.local/lib/python3.10/site-packages/openai/__init__.py

openai
πŸ“¦ NAME πŸš€ Quick Reference πŸ“ PACKAGE CONTENTS πŸ“‚ SUBMODULES πŸ›οΈ CLASSES
Exception Hierarchy Client Classes Streaming & Helpers OpenAI AsyncOpenAI BaseModel Stream / AsyncStream Exception Classes NotGiven / Omit Other Classes
πŸ”§ FUNCTIONS πŸ“Š DATA 🏷️ VERSION πŸ“„ FILE

Generated by phpman v4.9.27 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-18 13:08 @216.73.216.114
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format

^_top_^