From d337713976b33d3c9394e4f368195ec966fcf879 Mon Sep 17 00:00:00 2001 From: Ryan Crabbe Date: Sat, 7 Feb 2026 11:01:40 -0800 Subject: [PATCH] test: add tests for isinstance guard on api_base fast path --- .../litellm_core_utils/test_get_api_base.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/test_litellm/litellm_core_utils/test_get_api_base.py diff --git a/tests/test_litellm/litellm_core_utils/test_get_api_base.py b/tests/test_litellm/litellm_core_utils/test_get_api_base.py new file mode 100644 index 00000000000..19cc5b8e28b --- /dev/null +++ b/tests/test_litellm/litellm_core_utils/test_get_api_base.py @@ -0,0 +1,16 @@ +from litellm.litellm_core_utils.llm_response_utils.get_api_base import get_api_base + + +def test_get_api_base_rejects_non_string_api_base(): + """When api_base is in dict but not a string, fast path should be skipped.""" + result = get_api_base(model="gpt-3.5-turbo", optional_params={"api_base": 123}) + assert result is None or isinstance(result, str) + + +def test_get_api_base_fast_path_returns_string(): + """When api_base is a valid string in dict, fast path should return it directly.""" + result = get_api_base( + model="gpt-3.5-turbo", + optional_params={"api_base": "https://my-proxy.example.com"}, + ) + assert result == "https://my-proxy.example.com"