From 49894b2b634a51a6113923e3bc18ac826b48c6f4 Mon Sep 17 00:00:00 2001 From: Achuth Reddy Date: Sat, 15 Aug 2026 17:01:27 -0500 Subject: [PATCH] fix(ollama): forward completion api_base to model-info lookup The responses API bridge already accepted api_base but never passed it to _get_model_info_helper, so Ollama /api/show fell back to localhost and paid silent connect timeouts on every completion. --- litellm/main.py | 6 +++- .../llms/ollama/test_ollama_model_info.py | 30 +++++++++++++++++++ tests/test_litellm/test_main.py | 24 +++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/litellm/main.py b/litellm/main.py index 2a8ed6c87b6..5fd301638c0 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -1015,7 +1015,11 @@ def responses_api_bridge_check( try: model_info = cast( dict, - _get_model_info_helper(model=model, custom_llm_provider=custom_llm_provider), + _get_model_info_helper( + model=model, + custom_llm_provider=custom_llm_provider, + api_base=api_base, + ), ) if model_info.get("mode") is None and model.startswith("responses/"): model = model.replace("responses/", "") diff --git a/tests/test_litellm/llms/ollama/test_ollama_model_info.py b/tests/test_litellm/llms/ollama/test_ollama_model_info.py index 8d46151ecce..c47b739d271 100644 --- a/tests/test_litellm/llms/ollama/test_ollama_model_info.py +++ b/tests/test_litellm/llms/ollama/test_ollama_model_info.py @@ -231,6 +231,36 @@ class TestOllamaModelInfo: class TestOllamaGetModelInfo: """Tests for OllamaConfig.get_model_info() api_base threading and graceful fallback.""" + def test_responses_api_bridge_check_uses_provided_api_base_for_ollama( + self, monkeypatch + ): + """Bridge lookup must hit the completion api_base, not localhost:11434. + + Regression for https://github.com/BerriAI/litellm/issues/37041 + """ + from litellm.main import responses_api_bridge_check + + captured_urls = [] + + def mock_post(url, json, headers=None): + captured_urls.append(url) + return DummyResponse({"template": "", "model_info": {}}, status_code=200) + + monkeypatch.setattr("litellm.module_level_client.post", mock_post) + monkeypatch.delenv("OLLAMA_API_BASE", raising=False) + + responses_api_bridge_check( + model="unknown-custom-model", + custom_llm_provider="ollama", + api_base="http://my-remote-server:30000", + ) + + assert captured_urls + assert all( + url.startswith("http://my-remote-server:30000") for url in captured_urls + ) + assert not any("localhost:11434" in url for url in captured_urls) + def test_get_model_info_uses_provided_api_base(self, monkeypatch): """When api_base is passed, get_model_info should use it instead of env var or default.""" from litellm.llms.ollama.completion.transformation import OllamaConfig diff --git a/tests/test_litellm/test_main.py b/tests/test_litellm/test_main.py index 58373df024c..094abe60184 100644 --- a/tests/test_litellm/test_main.py +++ b/tests/test_litellm/test_main.py @@ -743,6 +743,30 @@ def test_responses_api_bridge_check_strips_responses_prefix(): assert model_info["mode"] == "responses" +def test_responses_api_bridge_check_forwards_api_base_to_model_info_helper(): + """completion() api_base must reach Ollama /api/show, not localhost:11434. + + Regression for https://github.com/BerriAI/litellm/issues/37041 + """ + from litellm.main import responses_api_bridge_check + + with patch("litellm.main._get_model_info_helper") as mock_get_model_info: + mock_get_model_info.return_value = {"mode": "chat"} + api_base = "http://my-host:30000" + + responses_api_bridge_check( + model="my-custom-model", + custom_llm_provider="ollama", + api_base=api_base, + ) + + mock_get_model_info.assert_called_once_with( + model="my-custom-model", + custom_llm_provider="ollama", + api_base=api_base, + ) + + def test_responses_api_bridge_check_gpt_5_4_pro(): """Test that gpt-5.4-pro routes through responses API bridge, not chat completions.