Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix: preserve OpenHands proxy base_url for rewritten litellm_proxy profiles (#1148)

Vasco Schiavofae56f520b63
diff --git a/__tests__/components/settings/llm-profiles/llm-settings-local-view.test.tsx b/__tests__/components/settings/llm-profiles/llm-settings-local-view.test.tsx
index 8fff81b518..3ca4b23b1d 100644
--- a/__tests__/components/settings/llm-profiles/llm-settings-local-view.test.tsx
+++ b/__tests__/components/settings/llm-profiles/llm-settings-local-view.test.tsx
@@ -582,6 +582,49 @@ describe("LlmSettingsLocalView", () => {
expect(savedLlm.model).toBe("openhands/claude-opus-4-5-20251101");
expect(savedLlm.base_url).toBe(OPENHANDS_LLM_PROXY_BASE_URL);
});
+
+ it("keeps the proxy base_url for a stored litellm_proxy OpenHands model (issue #1146)", async () => {
+ // Arrange β€” the shape actually persisted after onboarding through the
+ // OpenHands provider: the SDK has already rewritten openhands/* to
+ // litellm_proxy/* and paired it with the All-Hands proxy base URL. A
+ // Basic-tab re-save must not strip that base URL, otherwise the profile
+ // is stranded as `litellm_proxy/* + base_url:null` and LiteLLM reroutes
+ // the OpenHands key to the default OpenAI endpoint.
+ const user = userEvent.setup();
+ vi.mocked(ProfilesService.getProfile).mockResolvedValue({
+ name: "gpt-4-profile",
+ api_key_set: true,
+ config: {
+ model: "litellm_proxy/claude-opus-4-8",
+ api_key: "gAAAA_encrypted_key",
+ base_url: OPENHANDS_LLM_PROXY_BASE_URL,
+ },
+ });
+ mockSaveMutateAsync.mockResolvedValueOnce({ success: true });
+
+ renderWithProviders(<LlmSettingsLocalView />);
+
+ // Act β€” open the profile in edit mode, force the Basic tab, and save
+ // without touching the model dropdown.
+ await user.click(screen.getAllByTestId("profile-menu-trigger")[0]);
+ await user.click(screen.getByTestId("profile-edit"));
+ await waitFor(() => {
+ expect(screen.getByTestId("profile-name-input")).toHaveValue(
+ "gpt-4-profile",
+ );
+ });
+ await user.click(await screen.findByTestId("sdk-section-basic-toggle"));
+ await waitFor(() => {
+ expect(screen.getByTestId("save-profile-btn")).not.toBeDisabled();
+ });
+ await user.click(screen.getByTestId("save-profile-btn"));
+
+ // Assert β€” the rewritten model is preserved and so is the proxy base URL.
+ await waitFor(() => expect(mockSaveMutateAsync).toHaveBeenCalled());
+ const savedLlm = mockSaveMutateAsync.mock.calls[0][0].request.llm;
+ expect(savedLlm.model).toBe("litellm_proxy/claude-opus-4-8");
+ expect(savedLlm.base_url).toBe(OPENHANDS_LLM_PROXY_BASE_URL);
+ });
});
describe("All tab save", () => {
diff --git a/__tests__/utils/openhands-llm.test.ts b/__tests__/utils/openhands-llm.test.ts
index 1ff73ef606..cd03abfea0 100644
--- a/__tests__/utils/openhands-llm.test.ts
+++ b/__tests__/utils/openhands-llm.test.ts
@@ -2,6 +2,8 @@ import { describe, expect, it } from "vitest";
import {
OPENHANDS_LLM_PROXY_BASE_URL,
isOpenHandsProviderModel,
+ isOpenHandsProxyBaseUrl,
+ isOpenHandsProxyModel,
} from "#/utils/openhands-llm";
describe("openhands LLM helpers", () => {
@@ -17,4 +19,62 @@ describe("openhands LLM helpers", () => {
"https://llm-proxy.app.all-hands.dev/",
);
});
+
+ it("recognizes the All-Hands proxy base URL regardless of trailing slash or /v1", () => {
+ expect(isOpenHandsProxyBaseUrl(OPENHANDS_LLM_PROXY_BASE_URL)).toBe(true);
+ expect(isOpenHandsProxyBaseUrl("https://llm-proxy.app.all-hands.dev")).toBe(
+ true,
+ );
+ expect(
+ isOpenHandsProxyBaseUrl("https://llm-proxy.app.all-hands.dev/v1"),
+ ).toBe(true);
+ expect(isOpenHandsProxyBaseUrl("https://other-proxy.example.com")).toBe(
+ false,
+ );
+ expect(isOpenHandsProxyBaseUrl(null)).toBe(false);
+ expect(isOpenHandsProxyBaseUrl(undefined)).toBe(false);
+ });
+
+ it("treats both openhands/* and the SDK-rewritten litellm_proxy/* form as OpenHands-backed (issue #1146)", () => {
+ // The `openhands/*` form the GUI submits β€” proxy is implied, base URL is
+ // irrelevant.
+ expect(isOpenHandsProxyModel("openhands/gpt-5.5", null)).toBe(true);
+ expect(isOpenHandsProxyModel("openhands/gpt-5.5", "anything")).toBe(true);
+
+ // The `litellm_proxy/*` form the SDK persists, paired with the proxy URL.
+ expect(
+ isOpenHandsProxyModel(
+ "litellm_proxy/claude-opus-4-8",
+ OPENHANDS_LLM_PROXY_BASE_URL,
+ ),
+ ).toBe(true);
+ expect(
+ isOpenHandsProxyModel(
+ "litellm_proxy/claude-opus-4-8",
+ "https://llm-proxy.app.all-hands.dev",
+ ),
+ ).toBe(true);
+ });
+
+ it("does not over-classify non-OpenHands models as proxy-backed", () => {
+ // A litellm_proxy model pointed at a third-party gateway is not OpenHands.
+ expect(
+ isOpenHandsProxyModel(
+ "litellm_proxy/claude-opus-4-8",
+ "https://other-proxy.example.com",
+ ),
+ ).toBe(false);
+ // An already-stranded profile (proxy URL lost) is not auto-recognized: it
+ // must be re-activated/re-selected, not silently re-stamped here.
+ expect(isOpenHandsProxyModel("litellm_proxy/claude-opus-4-8", null)).toBe(
+ false,
+ );
+ // Plain providers stay plain even when oddly paired with the proxy URL.
+ expect(
+ isOpenHandsProxyModel("openai/gpt-4o", OPENHANDS_LLM_PROXY_BASE_URL),
+ ).toBe(false);
+ expect(isOpenHandsProxyModel(null, OPENHANDS_LLM_PROXY_BASE_URL)).toBe(
+ false,
+ );
+ });
});
diff --git a/src/components/features/settings/llm-profiles/llm-settings-local-view.tsx b/src/components/features/settings/llm-profiles/llm-settings-local-view.tsx
index 430e7096b5..3309671f4a 100644
--- a/src/components/features/settings/llm-profiles/llm-settings-local-view.tsx
+++ b/src/components/features/settings/llm-profiles/llm-settings-local-view.tsx
@@ -37,7 +37,7 @@ import { Typography } from "#/ui/typography";
import { useSettingsSectionHeader } from "#/contexts/settings-section-header-context";
import {
OPENHANDS_LLM_PROXY_BASE_URL,
- isOpenHandsProviderModel,
+ isOpenHandsProxyModel,
} from "#/utils/openhands-llm";
type ViewMode = "list" | "create" | "edit";
@@ -254,12 +254,14 @@ export function LlmSettingsLocalView() {
const llmConfig: Record<string, unknown> = { ...baseConfig, ...dirtyLlm };
// The Basic tab has no base_url field; the provider implies it. Persist
- // the All-Hands proxy explicitly for OpenHands models because older local
- // agent-server builds do not infer the LiteLLM proxy api_base on their own.
- // For other providers, drop any stale custom value and let the backend use
- // its normal provider defaults.
+ // the All-Hands proxy explicitly for OpenHands models β€” including ones the
+ // SDK has already rewritten to `litellm_proxy/*` β€” because older local
+ // agent-server builds do not infer the LiteLLM proxy api_base on their own,
+ // and dropping it strands the profile as `litellm_proxy/* + base_url:null`
+ // (issue #1146). For other providers, drop any stale custom value and let
+ // the backend use its normal provider defaults.
if (saveControl.view === "basic") {
- if (isOpenHandsProviderModel(llmConfig.model)) {
+ if (isOpenHandsProxyModel(llmConfig.model, llmConfig.base_url)) {
llmConfig.base_url = OPENHANDS_LLM_PROXY_BASE_URL;
} else {
delete llmConfig.base_url;
diff --git a/src/routes/llm-settings.tsx b/src/routes/llm-settings.tsx
index 885b3903c0..f45c01de4f 100644
--- a/src/routes/llm-settings.tsx
+++ b/src/routes/llm-settings.tsx
@@ -24,7 +24,7 @@ import {
import { DEFAULT_SETTINGS } from "#/services/settings";
import {
OPENHANDS_LLM_PROXY_BASE_URL,
- isOpenHandsProviderModel,
+ isOpenHandsProxyModel,
} from "#/utils/openhands-llm";
const LLM_EXCLUDED_KEYS = new Set(["llm.model", "llm.api_key", "llm.base_url"]);
@@ -286,7 +286,8 @@ export function LlmSettingsScreen({
if (context.view === "basic") {
const model = llm.model ?? context.values["llm.model"];
- llm.base_url = isOpenHandsProviderModel(model)
+ const baseUrl = llm.base_url ?? context.values["llm.base_url"];
+ llm.base_url = isOpenHandsProxyModel(model, baseUrl)
? OPENHANDS_LLM_PROXY_BASE_URL
: getSchemaFieldDefaultValue(schema, "llm.base_url");
agentSettings.llm = llm;
diff --git a/src/utils/normalize-display-model.ts b/src/utils/normalize-display-model.ts
index c87da42f18..0ae6504e26 100644
--- a/src/utils/normalize-display-model.ts
+++ b/src/utils/normalize-display-model.ts
@@ -1,13 +1,7 @@
-const OPENHANDS_PROXY_BASE_URLS = new Set([
- "https://llm-proxy.app.all-hands.dev",
- "https://llm-proxy.app.all-hands.dev/v1",
-]);
+import { isOpenHandsProxyBaseUrl } from "#/utils/openhands-llm";
const LITELLM_PROXY_PREFIX = "litellm_proxy/";
-const stripTrailingSlashes = (value: string) =>
- value.trim().replace(/\/+$/, "");
-
/**
* Reverse the SDK's `openhands/* -> litellm_proxy/*` rewrite for display.
*
@@ -23,10 +17,7 @@ export function normalizeDisplayModel(
): string {
if (!rawModel) return "";
if (!rawModel.startsWith(LITELLM_PROXY_PREFIX)) return rawModel;
- if (!baseUrl) return rawModel;
- if (!OPENHANDS_PROXY_BASE_URLS.has(stripTrailingSlashes(baseUrl))) {
- return rawModel;
- }
+ if (!isOpenHandsProxyBaseUrl(baseUrl)) return rawModel;
const modelName = rawModel.slice(LITELLM_PROXY_PREFIX.length);
if (!openhandsVerifiedModels.includes(modelName)) return rawModel;
return `openhands/${modelName}`;
diff --git a/src/utils/openhands-llm.ts b/src/utils/openhands-llm.ts
index 3c5e23175c..1af7d80121 100644
--- a/src/utils/openhands-llm.ts
+++ b/src/utils/openhands-llm.ts
@@ -1,6 +1,47 @@
export const OPENHANDS_LLM_PROXY_BASE_URL =
"https://llm-proxy.app.all-hands.dev/";
+// Accepted spellings of the All-Hands LiteLLM proxy base URL, normalized
+// without a trailing slash. The agent-server stores curated OpenHands models
+// against one of these once its validator rewrites `openhands/*` to
+// `litellm_proxy/*`.
+const OPENHANDS_LLM_PROXY_BASE_URLS = new Set([
+ "https://llm-proxy.app.all-hands.dev",
+ "https://llm-proxy.app.all-hands.dev/v1",
+]);
+
+const LITELLM_PROXY_PREFIX = "litellm_proxy/";
+
export function isOpenHandsProviderModel(model: unknown): model is string {
return typeof model === "string" && model.startsWith("openhands/");
}
+
+/**
+ * True when `baseUrl` points at the All-Hands LiteLLM proxy, ignoring any
+ * trailing slash.
+ */
+export function isOpenHandsProxyBaseUrl(baseUrl: unknown): baseUrl is string {
+ return (
+ typeof baseUrl === "string" &&
+ OPENHANDS_LLM_PROXY_BASE_URLS.has(baseUrl.trim().replace(/\/+$/, ""))
+ );
+}
+
+/**
+ * True for any OpenHands-backed model: the `openhands/*` id the GUI submits, or
+ * the `litellm_proxy/*` id the SDK rewrites it to once it is paired with the
+ * OpenHands proxy base URL. Both forms must keep the proxy `base_url` on save β€”
+ * dropping it strips the api_base and silently reroutes the request to the
+ * default OpenAI endpoint, leaving an unusable profile (issue #1146).
+ */
+export function isOpenHandsProxyModel(
+ model: unknown,
+ baseUrl: unknown,
+): model is string {
+ if (isOpenHandsProviderModel(model)) return true;
+ return (
+ typeof model === "string" &&
+ model.startsWith(LITELLM_PROXY_PREFIX) &&
+ isOpenHandsProxyBaseUrl(baseUrl)
+ );
+}