openai β File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
| Use Case | Command | Description |
|---|---|---|
| π Create a client | client = OpenAI() | Sync client, picks up OPENAI_API_KEY from env |
| β‘ Async client | client = AsyncOpenAI() | Async client, same envβbased auth |
| π¬ Chat completion | client.chat.completions.create(...) | Send a prompt and get a model response |
| π Embeddings | client.embeddings.create(...) | Get vector representation of text |
| πΌοΈ Image generation | client.images.generate(...) | Generate images from a prompt |
| π΅ Audio transcription | client.audio.transcriptions.create(...) | Transcribe audio to text |
| π File upload | client.files.create(...) | Upload files for fineβtuning or assistants |
| ποΈ Fineβtuning | client.fine_tuning.jobs.create(...) | Create a fineβtuning job |
| π Moderation | client.moderations.create(...) | Check if content is harmful |
| π Streaming | stream = client.chat.completions.create(..., stream=True) | Iterate over response chunks |
| π List models | client.models.list() | List available models |
| π Copy client | client.copy(timeout=30) | Clone with overridden options |
| π¦ Raw response | client.with_raw_response.chat... | Access the raw HTTP response |
| π Streaming response | client.with_streaming_response.chat... | Get a streaming context manager |
builtins.Exception
ββ OpenAIError
ββ APIError
β ββ APIConnectionError
β β ββ APITimeoutError
β ββ APIResponseValidationError
β ββ APIStatusError
β ββ AuthenticationError
β β ββ OAuthError
β ββ BadRequestError
β ββ ConflictError
β ββ InternalServerError
β ββ NotFoundError
β ββ PermissionDeniedError
β ββ RateLimitError
β ββ UnprocessableEntityError
ββ ContentFilterFinishReasonError
ββ LengthFinishReasonError
ββ WebSocketConnectionClosedError
ββ WebSocketQueueFullError
builtins.ValueError
ββ InvalidWebhookSignatureError
openai._base_client.AsyncAPIClient
ββ AsyncOpenAI
ββ AsyncBedrockOpenAI
openai._base_client.SyncAPIClient
ββ OpenAI
ββ BedrockOpenAI
typing.Generic ββ AsyncStream ββ Stream pydantic.main.BaseModel ββ BaseModel (openai) builtins.dict ββ ReconnectingOverrides ββ RequestOptions builtins.object ββ NotGiven ββ Omit ββ Timeout ββ ReconnectingEvent
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.
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.
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[_T] β Iterable over a synchronous serverβsent event stream.
AsyncStream[_T] β Async version.
Both provide __iter__/__aiter__, close(), and context manager support.
OpenAIError β base exceptionAPIError β base for API errors (has request, body, code, param)APIStatusError β raised for 4xx/5xx responses; subclasses: AuthenticationError (401), BadRequestError (400), PermissionDeniedError (403), NotFoundError (404), ConflictError (409), UnprocessableEntityError (422), RateLimitError (429), InternalServerError (500)APIConnectionError β connection issues, APITimeoutError β timeoutAPIResponseValidationError β response validation failedOAuthError β auth error with OAuth detailsContentFilterFinishReasonError β content filter triggeredLengthFinishReasonError β max tokens reachedWebSocketConnectionClosedError β WebSocket closed with unsent messagesWebSocketQueueFullError β outgoing WebSocket queue fullInvalidWebhookSignatureError β webhook signature mismatchopenai.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).
Timeout β configures connect, read, write, pool timeouts.RequestOptions β TypedDict for perβrequest overrides (headers, extra_json, etc.).ReconnectingOverrides β TypedDict for reconnection customisation.ReconnectingEvent β dataclass with reconnection attempt info.BaseTransport β abstract transport; Transport alias.file_from_path(path: str) -> FileTypesDEFAULT_CONNECTION_LIMITS β Limits(max_connections=1000, ...)DEFAULT_MAX_RETRIES β 2DEFAULT_TIMEOUT β Timeout(connect=5.0, read=600, write=600, pool=600)NOT_GIVEN β sentinelnot_given β alias for NOT_GIVENomit β sentinel object__all__ β list of public symbols__title__ β 'openai'2.44.0
/home/chedong/.local/lib/python3.10/site-packages/openai/__init__.py
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)
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format