Implementation:Openai Openai python Old API Shims
| Knowledge Sources | |
|---|---|
| Domains | SDK_Infrastructure |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Concrete tool for deprecated v0.x API symbol proxies provided by the openai-python SDK.
Description
The _old_api module provides deprecation shims for API symbols that were removed in openai>=1.0.0. The APIRemovedInV1 exception class raises an informative error message directing users to the migration guide and the openai migrate tool. The APIRemovedInV1Proxy class extends LazyProxy[Any] and returns itself from __load__() so that attribute access does not immediately fail (allowing code that only inspects module attributes to continue working), but raises APIRemovedInV1 when the proxy is actually called. The SYMBOLS list contains 15 old class names: Edit, File, Audio, Image, Model, Engine, Customer, FineTune, Embedding, Completion, Deployment, Moderation, ErrorObject, FineTuningJob, and ChatCompletion. Each symbol is dynamically injected into the module's locals as an APIRemovedInV1Proxy instance. The __all__ export list is hidden from type checkers to avoid polluting autocomplete.
Usage
This module activates automatically when users access old v0.x symbols (e.g., openai.ChatCompletion) after upgrading to v1.0+. It guides them to migrate their code.
Code Reference
Source Location
- Repository: openai-python
- File: src/openai/lib/_old_api.py
- Lines: 1-72
Signature
class APIRemovedInV1(OpenAIError):
def __init__(self, *, symbol: str) -> None: ...
class APIRemovedInV1Proxy(LazyProxy[Any]):
def __init__(self, *, symbol: str) -> None: ...
def __load__(self) -> Any: ...
def __call__(self, *_args: Any, **_kwargs: Any) -> Any: ...
SYMBOLS = [
"Edit", "File", "Audio", "Image", "Model", "Engine",
"Customer", "FineTune", "Embedding", "Completion",
"Deployment", "Moderation", "ErrorObject", "FineTuningJob",
"ChatCompletion",
]
Import
from openai.lib._old_api import APIRemovedInV1, APIRemovedInV1Proxy
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| symbol | str | Yes | The name of the removed API symbol (e.g., "ChatCompletion") |
Outputs
| Name | Type | Description |
|---|---|---|
| __load__() result | APIRemovedInV1Proxy (self) | Returns itself to defer the error until invocation |
| __call__() | Never (raises) | Raises APIRemovedInV1 with migration instructions |
Usage Examples
Basic Usage
import openai
# Accessing an old symbol does not immediately error:
old_symbol = openai.ChatCompletion # Returns proxy silently
# But calling it raises an informative error:
try:
openai.ChatCompletion.create(model="gpt-4o")
except openai.OpenAIError as e:
print(e)
# "You tried to access openai.ChatCompletion, but this is no longer
# supported in openai>=1.0.0 - see the README..."