Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix(settings): Only convert litellm_proxy/ to openhands/ for OpenHands proxy (#14173)

Chris Bagwell03f49a40a059
diff --git a/openhands/app_server/settings/settings_router.py b/openhands/app_server/settings/settings_router.py
index 4163cb5992..c28564e33e 100644
--- a/openhands/app_server/settings/settings_router.py
+++ b/openhands/app_server/settings/settings_router.py
@@ -125,18 +125,22 @@ async def load_settings(
provider_tokens_set=provider_tokens_set,
)
- # Convert litellm_proxy/ back to openhands/ for the frontend
+ # Convert litellm_proxy/ back to openhands/ for the frontend, but only
+ # if the base_url is the OpenHands proxy. Custom litellm_proxy endpoints
+ # should keep their litellm_proxy/ prefix.
resp_llm = settings_with_token_data.agent_settings.llm
+ normalized_base = (llm.base_url or '').rstrip('/')
+ normalized_proxy = LITE_LLM_API_URL.rstrip('/')
+
if resp_llm.model and resp_llm.model.startswith('litellm_proxy/'):
- resp_llm.model = (
- f'openhands/{resp_llm.model.removeprefix("litellm_proxy/")}'
- )
+ # Only convert to openhands/ if using the OpenHands proxy URL
+ if normalized_base == normalized_proxy:
+ resp_llm.model = (
+ f'openhands/{resp_llm.model.removeprefix("litellm_proxy/")}'
+ )
# If the base url matches the default for the provider, we don't send it
# So that the frontend can display basic mode.
- # Normalize trailing slashes for comparison since the SDK may add one.
- normalized_base = (llm.base_url or '').rstrip('/')
- normalized_proxy = LITE_LLM_API_URL.rstrip('/')
if is_openhands_model(llm.model):
if normalized_base == normalized_proxy:
resp_llm.base_url = None
diff --git a/openhands/storage/data_models/settings.py b/openhands/storage/data_models/settings.py
index b67fe4af80..e8ea079a83 100644
--- a/openhands/storage/data_models/settings.py
+++ b/openhands/storage/data_models/settings.py
@@ -348,25 +348,34 @@ class Settings(BaseModel):
def get_agent_settings_display(self) -> dict[str, Any]:
"""Return agent_settings dict with display-friendly model names.
- ``litellm_proxy/`` prefixes are normalised to ``openhands/``.
+ ``litellm_proxy/`` prefixes are normalised to ``openhands/`` only when
+ using the OpenHands proxy URL. Custom litellm_proxy endpoints keep their
+ litellm_proxy/ prefix.
The LiteLLM proxy ``base_url`` is cleared for managed models so
that the frontend can display "basic" mode.
Secrets are masked by Pydantic's default serialiser.
"""
+ from openhands.app_server.settings.settings_router import LITE_LLM_API_URL
from openhands.utils.llm import is_openhands_model
data = self.agent_settings.model_dump(mode='json')
llm = data.get('llm')
if isinstance(llm, dict):
model = llm.get('model')
+ base_url = llm.get('base_url')
+
+ # Only convert litellm_proxy/ to openhands/ if using the OpenHands proxy
if isinstance(model, str) and model.startswith('litellm_proxy/'):
- llm['model'] = f'openhands/{model.removeprefix("litellm_proxy/")}'
+ normalized_base = (base_url or '').rstrip('/')
+ normalized_proxy = LITE_LLM_API_URL.rstrip('/')
+ if normalized_base == normalized_proxy:
+ llm['model'] = f'openhands/{model.removeprefix("litellm_proxy/")}'
+
# Clear the proxy base_url for managed models so the frontend
# sees null and can display the simple "basic" settings view.
if is_openhands_model(model):
- base_url = llm.get('base_url')
- if isinstance(base_url, str) and base_url.rstrip('/').endswith(
- 'llm-proxy.app.all-hands.dev'
- ):
+ normalized_base = (base_url or '').rstrip('/')
+ normalized_proxy = LITE_LLM_API_URL.rstrip('/')
+ if normalized_base == normalized_proxy:
llm['base_url'] = None
return data
diff --git a/tests/unit/storage/data_models/test_settings.py b/tests/unit/storage/data_models/test_settings.py
index 687199ca9d..3d0318a4d6 100644
--- a/tests/unit/storage/data_models/test_settings.py
+++ b/tests/unit/storage/data_models/test_settings.py
@@ -5,6 +5,7 @@ import pytest
from fastmcp.mcp_config import MCPConfig
from pydantic import SecretStr
+from openhands.app_server.settings.settings_router import LITE_LLM_API_URL
from openhands.core.config.llm_config import LLMConfig
from openhands.core.config.openhands_config import OpenHandsConfig
from openhands.core.config.sandbox_config import SandboxConfig
@@ -348,3 +349,57 @@ def test_settings_no_pydantic_frozen_field_warning():
assert len(frozen_warnings) == 0, (
f'Pydantic frozen field warnings found: {[str(w.message) for w in frozen_warnings]}'
)
+
+
+def test_litellm_proxy_to_openhands_conversion_with_openhands_proxy():
+ """Test that litellm_proxy/ is converted to openhands/ when using OpenHands proxy."""
+ settings = Settings(
+ agent_settings=AgentSettings(
+ llm=LLM(
+ model='litellm_proxy/claude-opus-4-5-20251101',
+ base_url=LITE_LLM_API_URL,
+ )
+ )
+ )
+
+ # Internal representation should be litellm_proxy/
+ assert settings.agent_settings.llm.model == 'litellm_proxy/claude-opus-4-5-20251101'
+
+ # Display representation should convert to openhands/
+ api_data = settings.get_agent_settings_display()
+ assert api_data['llm']['model'] == 'openhands/claude-opus-4-5-20251101'
+
+
+def test_litellm_proxy_custom_endpoint_keeps_prefix():
+ """Test that custom litellm_proxy endpoints keep their litellm_proxy/ prefix."""
+ settings = Settings(
+ agent_settings=AgentSettings(
+ llm=LLM(
+ model='litellm_proxy/gpt-5.3-codex',
+ base_url='http://custom-proxy.example.com:4000',
+ )
+ )
+ )
+
+ # Internal representation
+ assert settings.agent_settings.llm.model == 'litellm_proxy/gpt-5.3-codex'
+
+ # Display should NOT convert to openhands/ because it's a custom endpoint
+ api_data = settings.get_agent_settings_display()
+ assert api_data['llm']['model'] == 'litellm_proxy/gpt-5.3-codex'
+
+
+def test_openhands_model_converts_to_litellm_proxy_internally():
+ """Test that openhands/ models are stored as litellm_proxy/ internally."""
+ settings = Settings(
+ agent_settings=AgentSettings(
+ llm=LLM(model='openhands/claude-opus-4-5-20251101')
+ )
+ )
+
+ # Internal representation should be litellm_proxy/
+ assert settings.agent_settings.llm.model == 'litellm_proxy/claude-opus-4-5-20251101'
+
+ # Display representation should convert back to openhands/
+ api_data = settings.get_agent_settings_display()
+ assert api_data['llm']['model'] == 'openhands/claude-opus-4-5-20251101'