Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Openai Openai python Module Level Client

From Leeroopedia
Revision as of 13:39, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Openai_Openai_python_Module_Level_Client.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains SDK_Infrastructure
Last Updated 2026-02-15 00:00 GMT

Overview

Concrete tool for module-level lazy API access provided by the openai-python SDK.

Description

The _module_client module defines 21 proxy classes that enable module-level attribute access for all API resource namespaces (e.g., openai.chat, openai.files, openai.completions). Each proxy class extends LazyProxy[T] and overrides the __load__() method to call _load_client() and return the corresponding resource attribute from the default OpenAI client singleton. The proxy classes include ChatProxy, BetaProxy, FilesProxy, AudioProxy, EvalsProxy, ImagesProxy, ModelsProxy, SkillsProxy, VideosProxy, BatchesProxy, UploadsProxy, WebhooksProxy, RealtimeProxy, ResponsesProxy, EmbeddingsProxy, ContainersProxy, CompletionsProxy, ModerationsProxy, FineTuningProxy, VectorStoresProxy, and ConversationsProxy. Module-level instances are created using __as_proxied__() to provide correctly typed attributes.

Usage

Use this module implicitly when accessing API resources at the module level, such as openai.chat.completions.create(...), without first constructing an explicit client instance.

Code Reference

Source Location

Signature

class ChatProxy(LazyProxy["Chat"]):
    def __load__(self) -> Chat: ...

class BetaProxy(LazyProxy["Beta"]):
    def __load__(self) -> Beta: ...

class FilesProxy(LazyProxy["Files"]):
    def __load__(self) -> Files: ...

# ... 18 more proxy classes following the same pattern ...

# Module-level instances
chat: Chat
beta: Beta
files: Files
audio: Audio
evals: Evals
images: Images
models: Models
skills: Skills
videos: Videos
batches: Batches
uploads: Uploads
webhooks: Webhooks
realtime: Realtime
responses: Responses
embeddings: Embeddings
containers: Containers
completions: Completions
moderations: Moderations
fine_tuning: FineTuning
vector_stores: VectorStores
conversations: Conversations

Import

import openai

# Access resources directly at module level
openai.chat
openai.files
openai.completions

I/O Contract

Inputs

Name Type Required Description
(none) N/A N/A Proxy classes take no explicit input; they lazily load the default client

Outputs

Name Type Description
__load__() result Resource class (e.g., Chat, Files) The fully initialized resource object from the default OpenAI client

Usage Examples

Basic Usage

import openai

# Module-level access triggers lazy client initialization
response = openai.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello"}],
)

# Equivalent to:
# client = openai.OpenAI()
# response = client.chat.completions.create(...)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment