From 6e87b4b98514f428dd0f2492940371f921b73c70 Mon Sep 17 00:00:00 2001 From: jibanez-staticduo Date: Wed, 9 Sep 2026 13:32:33 +0200 Subject: [PATCH] fix(chatgpt): resolve gateway URLs without touching token storage --- litellm/llms/chatgpt/authenticator.py | 3 ++- litellm/llms/chatgpt/images.py | 4 ++-- litellm/llms/chatgpt/realtime.py | 4 ++-- tests/test_litellm/llms/chatgpt/test_images.py | 5 ++++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/litellm/llms/chatgpt/authenticator.py b/litellm/llms/chatgpt/authenticator.py index a516fb2fe09..4a5045e02e7 100644 --- a/litellm/llms/chatgpt/authenticator.py +++ b/litellm/llms/chatgpt/authenticator.py @@ -49,7 +49,8 @@ class Authenticator: self.auth_file = os.path.join(self.token_dir, os.getenv("CHATGPT_AUTH_FILE", "auth.json")) self._ensure_token_dir() - def get_api_base(self, default_base: str = CHATGPT_API_BASE) -> str: + @staticmethod + def get_api_base(default_base: str = CHATGPT_API_BASE) -> str: return os.getenv("CHATGPT_API_BASE") or os.getenv("OPENAI_CHATGPT_API_BASE") or default_base def get_access_token(self) -> str: diff --git a/litellm/llms/chatgpt/images.py b/litellm/llms/chatgpt/images.py index 97a0da5f518..3467b68c31f 100644 --- a/litellm/llms/chatgpt/images.py +++ b/litellm/llms/chatgpt/images.py @@ -82,7 +82,7 @@ class ChatGPTImageGenerationConfig(GPTImageGenerationConfig): litellm_params: Mapping[str, object], stream: bool | None = None, ) -> str: - return f"{(api_base or Authenticator().get_api_base()).rstrip('/')}/images/generations" + return f"{(api_base or Authenticator.get_api_base()).rstrip('/')}/images/generations" def transform_image_generation_request( self, @@ -107,7 +107,7 @@ class ChatGPTImageEditConfig(OpenAIImageEditConfig): return image_headers(headers, model, litellm_params or MappingProxyType({})) def get_complete_url(self, model: str, api_base: str | None, litellm_params: Mapping[str, object]) -> str: - return f"{(api_base or Authenticator().get_api_base()).rstrip('/')}/images/edits" + return f"{(api_base or Authenticator.get_api_base()).rstrip('/')}/images/edits" def use_multipart_form_data(self) -> bool: return False diff --git a/litellm/llms/chatgpt/realtime.py b/litellm/llms/chatgpt/realtime.py index 5be3e766b99..26e2f0ffad9 100644 --- a/litellm/llms/chatgpt/realtime.py +++ b/litellm/llms/chatgpt/realtime.py @@ -46,7 +46,7 @@ def realtime_endpoint(model: str) -> str: class ChatGPTRealtime(OpenAIRealtime): @staticmethod def get_api_base(api_base: str | None = None) -> str: - return api_base or Authenticator().get_api_base(default_base="https://api.openai.com/v1") + return api_base or Authenticator.get_api_base(default_base="https://api.openai.com/v1") def __init__(self, params: GenericLiteLLMParams, headers: Mapping[str, str]) -> None: super().__init__() @@ -94,7 +94,7 @@ class ChatGPTRealtimeHTTPConfig(OpenAIRealtimeHTTPConfig): api_base: str | None, **kwargs: object, # kwargs-ok: provider interface accepts optional credentials ) -> str: - return api_base or Authenticator().get_api_base() + return api_base or Authenticator.get_api_base() def get_api_key( self, diff --git a/tests/test_litellm/llms/chatgpt/test_images.py b/tests/test_litellm/llms/chatgpt/test_images.py index 911183ba50b..6b69a83839d 100644 --- a/tests/test_litellm/llms/chatgpt/test_images.py +++ b/tests/test_litellm/llms/chatgpt/test_images.py @@ -120,7 +120,10 @@ def test_edit_accepts_filesystem_path(tmp_path, as_tuple): @pytest.mark.parametrize("env_name", ["CHATGPT_API_BASE", "OPENAI_CHATGPT_API_BASE"]) @pytest.mark.parametrize("api_base", [None, "https://deployment.example/codex"]) -def test_image_routes_use_configured_gateway(monkeypatch, env_name, api_base): +def test_image_routes_use_configured_gateway(monkeypatch, env_name, api_base, tmp_path): + token_path = tmp_path / "unavailable-token-directory" + token_path.write_text("not a directory") + monkeypatch.setenv("CHATGPT_TOKEN_DIR", str(token_path)) monkeypatch.delenv("CHATGPT_API_BASE", raising=False) monkeypatch.delenv("OPENAI_CHATGPT_API_BASE", raising=False) monkeypatch.setenv(env_name, "https://gateway.example/codex/")