diff --git a/litellm/main.py b/litellm/main.py index 17edafcdfca..5fc55ba7a5a 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -1065,7 +1065,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 053d4da035f..f65fc0946d9 100644 --- a/tests/test_litellm/llms/ollama/test_ollama_model_info.py +++ b/tests/test_litellm/llms/ollama/test_ollama_model_info.py @@ -227,6 +227,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 4f7a51eb531..302a4e6bdb5 100644 --- a/tests/test_litellm/test_main.py +++ b/tests/test_litellm/test_main.py @@ -750,6 +750,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.