Closed
Description
Confirm this is an issue with the Python library and not an underlying OpenAI API
- This is an issue with the Python library
Describe the bug
I encountered an issue where the base_url
of an OpenAI client instance couldn't be modified. This is due to the setter method of base_url
not updating self._base_url
.
Possible Solution
I suggest modifying the setter method for base_url to ensure self._base_url is also updated. Additionally, incorporate handling for the trailing slash of the URL, as done in the init method:
@base_url.setter
def base_url(self, url: URL | str) -> None:
url = url if isinstance(url, URL) else URL(url)
url = self._enforce_trailing_slash(url)
self._base_url = url
self._client.base_url = url
To Reproduce
- Set up an OpenAI client instance with initial parameters including base_url.
- Attempt to modifybase_url.
- Observe that self._base_url within the client instance remains unchanged, indicating that the modification has not been applied.
Code snippets
import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("OPENAI_API_KEY"),
base_url="https://api.openai.com/v1",
)
print(client.base_url)
client.base_url = "https://newurl.example.com/v1"
print(client.base_url)
OS
Windows11
Python version
Python 3.12.0
Library version
1.3.6