Skip to content

armgit / mem0

Public Imported from GitHub
0

The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.

fix(llms): honor OPENAI_BASE_URL in structured provider (#6322)

Jupiterddaa655edf41
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)