From ddaa655edf41e3ed375b263fb227da0bcd42ccb9 Mon Sep 17 00:00:00 2001 From: Jupiter <134490903+Jupiter363@users.noreply.github.com> Date: Fri, 17 Jul 2026 23:15:58 +0800 Subject: [PATCH] fix(llms): honor OPENAI_BASE_URL in structured provider (#6322) --- mem0/llms/openai_structured.py | 2 +- tests/llms/test_openai_structured.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/mem0/llms/openai_structured.py b/mem0/llms/openai_structured.py index 2d5104039..5642da302 100644 --- a/mem0/llms/openai_structured.py +++ b/mem0/llms/openai_structured.py @@ -15,7 +15,7 @@ class OpenAIStructuredLLM(LLMBase): self.config.model = "gpt-5-mini" api_key = self.config.api_key or os.getenv("OPENAI_API_KEY") - base_url = self.config.openai_base_url or os.getenv("OPENAI_API_BASE") or "https://api.openai.com/v1" + base_url = self.config.openai_base_url or os.getenv("OPENAI_BASE_URL") or "https://api.openai.com/v1" self.client = OpenAI(api_key=api_key, base_url=base_url) def generate_response( diff --git a/tests/llms/test_openai_structured.py b/tests/llms/test_openai_structured.py index 4881d4b35..823f1c069 100644 --- a/tests/llms/test_openai_structured.py +++ b/tests/llms/test_openai_structured.py @@ -49,3 +49,14 @@ def test_regular_model_sends_sampling_params(mock_openai_client): assert "max_tokens" in call_kwargs # standard sampling params still forwarded assert "top_p" in call_kwargs assert call_kwargs["model"] == "gpt-4o" + + +def test_uses_openai_base_url_environment_variable(monkeypatch): + base_url = "https://gateway.example/v1" + monkeypatch.setenv("OPENAI_API_BASE", "https://legacy.example/v1") + monkeypatch.setenv("OPENAI_BASE_URL", base_url) + + with patch("mem0.llms.openai_structured.OpenAI") as mock_openai: + OpenAIStructuredLLM(OpenAIConfig(api_key="test-api-key")) + + mock_openai.assert_called_once_with(api_key="test-api-key", base_url=base_url)