Merge branch 'pr-20013' into litellm_perf_ryan_staging

This commit is contained in:
Ryan Crabbe 2026-02-16 13:36:24 -08:00
commit 5ca4e54f98
2 changed files with 23 additions and 0 deletions

View file

@ -28,6 +28,13 @@ def get_api_base(
```
"""
# Fast path: if api_base is already in the dict, return it directly
# without constructing a full LiteLLM_Params Pydantic model.
if isinstance(optional_params, dict):
_api_base = optional_params.get("api_base")
if isinstance(_api_base, str):
return _api_base
try:
if isinstance(optional_params, LiteLLM_Params):
_optional_params = optional_params

View file

@ -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"