Skip to content

πŸ™Œ OpenHands: AI-Driven Development

refactor: single source of truth for verified models (#13421)

Graham Neubig3e1e8f00f740
diff --git a/enterprise/server/verified_models/verified_model_router.py b/enterprise/server/verified_models/verified_model_router.py
index a798878b0d..f34efe1ba6 100644
--- a/enterprise/server/verified_models/verified_model_router.py
+++ b/enterprise/server/verified_models/verified_model_router.py
@@ -17,7 +17,7 @@ from server.verified_models.verified_model_service import (
from openhands.app_server.config import get_db_session
from openhands.server.routes import public
-from openhands.utils.llm import get_supported_llm_models
+from openhands.utils.llm import ModelsResponse, get_supported_llm_models
api_router = APIRouter(prefix='/api/admin/verified-models', tags=['Verified Models'])
@@ -117,7 +117,7 @@ async def delete_verified_model(
)
-async def get_saas_llm_models_dependency(request: Request) -> list[str]:
+async def get_saas_llm_models_dependency(request: Request) -> ModelsResponse:
"""SaaS implementation for the LLM models endpoint."""
async with get_db_session(request.state, request) as db_session:
# Prevent circular import
diff --git a/frontend/__tests__/components/modals/settings/model-selector.test.tsx b/frontend/__tests__/components/modals/settings/model-selector.test.tsx
index cacc6fad10..ed2d6cfd73 100644
--- a/frontend/__tests__/components/modals/settings/model-selector.test.tsx
+++ b/frontend/__tests__/components/modals/settings/model-selector.test.tsx
@@ -3,7 +3,6 @@ import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { ModelSelector } from "#/components/shared/modals/settings/model-selector";
-// Mock react-i18next
vi.mock("react-i18next", () => ({
useTranslation: () => ({
t: (key: string) => {
@@ -32,15 +31,20 @@ describe("ModelSelector", () => {
separator: "/",
models: ["chat-bison", "chat-bison-32k"],
},
- cohere: {
- separator: ".",
- models: ["command-r-v1:0"],
- },
};
+ const verifiedModels = ["gpt-4o", "gpt-4o-mini"];
+ const verifiedProviders = ["openai"];
+
it("should display the provider selector", async () => {
const user = userEvent.setup();
- render(<ModelSelector models={models} />);
+ render(
+ <ModelSelector
+ models={models}
+ verifiedModels={verifiedModels}
+ verifiedProviders={verifiedProviders}
+ />,
+ );
const selector = screen.getByLabelText("LLM Provider");
expect(selector).toBeInTheDocument();
@@ -50,12 +54,17 @@ describe("ModelSelector", () => {
expect(screen.getByText("OpenAI")).toBeInTheDocument();
expect(screen.getByText("Azure")).toBeInTheDocument();
expect(screen.getByText("VertexAI")).toBeInTheDocument();
- expect(screen.getByText("cohere")).toBeInTheDocument();
});
it("should disable the model selector if the provider is not selected", async () => {
const user = userEvent.setup();
- render(<ModelSelector models={models} />);
+ render(
+ <ModelSelector
+ models={models}
+ verifiedModels={verifiedModels}
+ verifiedProviders={verifiedProviders}
+ />,
+ );
const modelSelector = screen.getByLabelText("LLM Model");
expect(modelSelector).toBeDisabled();
@@ -71,7 +80,13 @@ describe("ModelSelector", () => {
it("should display the model selector", async () => {
const user = userEvent.setup();
- render(<ModelSelector models={models} />);
+ render(
+ <ModelSelector
+ models={models}
+ verifiedModels={verifiedModels}
+ verifiedProviders={verifiedProviders}
+ />,
+ );
const providerSelector = screen.getByLabelText("LLM Provider");
await user.click(providerSelector);
@@ -84,51 +99,43 @@ describe("ModelSelector", () => {
expect(screen.getByText("ada")).toBeInTheDocument();
expect(screen.getByText("gpt-35-turbo")).toBeInTheDocument();
-
- await user.click(providerSelector);
- const vertexProvider = screen.getByText("VertexAI");
- await user.click(vertexProvider);
-
- await user.click(modelSelector);
-
- // Test fails when expecting these values to be present.
- // My hypothesis is that it has something to do with NextUI's
- // list virtualization
-
- // expect(screen.getByText("chat-bison")).toBeInTheDocument();
- // expect(screen.getByText("chat-bison-32k")).toBeInTheDocument();
});
- it("should call onModelChange when the model is changed", async () => {
+ it("should call onChange when the provider and model change", async () => {
const user = userEvent.setup();
- render(<ModelSelector models={models} />);
+ const onChange = vi.fn();
- const providerSelector = screen.getByLabelText("LLM Provider");
- const modelSelector = screen.getByLabelText("LLM Model");
+ render(
+ <ModelSelector
+ models={models}
+ verifiedModels={verifiedModels}
+ verifiedProviders={verifiedProviders}
+ onChange={onChange}
+ />,
+ );
+ const providerSelector = screen.getByLabelText("LLM Provider");
await user.click(providerSelector);
await user.click(screen.getByText("Azure"));
+ const modelSelector = screen.getByLabelText("LLM Model");
await user.click(modelSelector);
await user.click(screen.getByText("ada"));
- await user.click(modelSelector);
- await user.click(screen.getByText("gpt-35-turbo"));
-
- await user.click(providerSelector);
- await user.click(screen.getByText("cohere"));
-
- await user.click(modelSelector);
-
- // Test fails when expecting this values to be present.
- // My hypothesis is that it has something to do with NextUI's
- // list virtualization
-
- // await user.click(screen.getByText("command-r-v1:0"));
+ expect(onChange).toHaveBeenNthCalledWith(1, "azure", null);
+ expect(onChange).toHaveBeenNthCalledWith(2, "azure", "ada");
});
+
it("should have a default value if passed", async () => {
- render(<ModelSelector models={models} currentModel="azure/ada" />);
+ render(
+ <ModelSelector
+ models={models}
+ verifiedModels={verifiedModels}
+ verifiedProviders={verifiedProviders}
+ currentModel="azure/ada"
+ />,
+ );
expect(screen.getByLabelText("LLM Provider")).toHaveValue("Azure");
expect(screen.getByLabelText("LLM Model")).toHaveValue("ada");
diff --git a/frontend/__tests__/components/shared/modals/settings/settings-form.test.tsx b/frontend/__tests__/components/shared/modals/settings/settings-form.test.tsx
index b820be5829..f5ab44d2df 100644
--- a/frontend/__tests__/components/shared/modals/settings/settings-form.test.tsx
+++ b/frontend/__tests__/components/shared/modals/settings/settings-form.test.tsx
@@ -17,6 +17,8 @@ describe("SettingsForm", () => {
<SettingsForm
settings={DEFAULT_SETTINGS}
models={[DEFAULT_SETTINGS.llm_model]}
+ verifiedModels={[]}
+ verifiedProviders={["openhands"]}
onClose={onCloseMock}
/>
),
diff --git a/frontend/__tests__/utils/extract-model-and-provider.test.ts b/frontend/__tests__/utils/extract-model-and-provider.test.ts
index 36e6cac6e8..9739317f59 100644
--- a/frontend/__tests__/utils/extract-model-and-provider.test.ts
+++ b/frontend/__tests__/utils/extract-model-and-provider.test.ts
@@ -2,7 +2,7 @@ import { describe, it, expect } from "vitest";
import { extractModelAndProvider } from "../../src/utils/extract-model-and-provider";
describe("extractModelAndProvider", () => {
- it("should work", () => {
+ it("should split on / separator", () => {
expect(extractModelAndProvider("azure/ada")).toEqual({
provider: "azure",
model: "ada",
@@ -23,12 +23,6 @@ describe("extractModelAndProvider", () => {
separator: "/",
});
- expect(extractModelAndProvider("cohere.command-r-v1:0")).toEqual({
- provider: "cohere",
- model: "command-r-v1:0",
- separator: ".",
- });
-
expect(
extractModelAndProvider(
"cloudflare/@cf/mistral/mistral-7b-instruct-v0.1",
@@ -38,66 +32,50 @@ describe("extractModelAndProvider", () => {
model: "@cf/mistral/mistral-7b-instruct-v0.1",
separator: "/",
});
+ });
+
+ it("should return dotted or bare models as-is", () => {
+ expect(extractModelAndProvider("cohere.command-r-v1:0")).toEqual({
+ provider: "",
+ model: "cohere.command-r-v1:0",
+ separator: "",
+ });
expect(extractModelAndProvider("together-ai-21.1b-41b")).toEqual({
provider: "",
model: "together-ai-21.1b-41b",
separator: "",
});
- });
- it("should add provider for popular models", () => {
expect(extractModelAndProvider("gpt-4o-mini")).toEqual({
- provider: "openai",
+ provider: "",
model: "gpt-4o-mini",
- separator: "/",
+ separator: "",
});
- expect(extractModelAndProvider("gpt-4o")).toEqual({
- provider: "openai",
- model: "gpt-4o",
- separator: "/",
+ expect(extractModelAndProvider("claude-opus-4-6")).toEqual({
+ provider: "",
+ model: "claude-opus-4-6",
+ separator: "",
});
+ });
- expect(extractModelAndProvider("gpt-5.2")).toEqual({
+ it("should correctly parse already-prefixed models", () => {
+ expect(extractModelAndProvider("openai/gpt-5.2")).toEqual({
provider: "openai",
model: "gpt-5.2",
separator: "/",
});
- expect(extractModelAndProvider("gpt-5.2-codex")).toEqual({
- provider: "openai",
- model: "gpt-5.2-codex",
- separator: "/",
- });
-
- expect(extractModelAndProvider("claude-3-5-sonnet-20240620")).toEqual({
- provider: "anthropic",
- model: "claude-3-5-sonnet-20240620",
- separator: "/",
- });
-
- expect(extractModelAndProvider("claude-3-7-sonnet-20250219")).toEqual({
+ expect(extractModelAndProvider("anthropic/claude-opus-4-6")).toEqual({
provider: "anthropic",
- model: "claude-3-7-sonnet-20250219",
+ model: "claude-opus-4-6",
separator: "/",
});
- expect(extractModelAndProvider("claude-sonnet-4-20250514")).toEqual({
- provider: "anthropic",
- model: "claude-sonnet-4-20250514",
- separator: "/",
- });
-
- expect(extractModelAndProvider("claude-opus-4-20250514")).toEqual({
- provider: "anthropic",
- model: "claude-opus-4-20250514",
- separator: "/",
- });
-
- expect(extractModelAndProvider("claude-opus-4-1-20250805")).toEqual({
- provider: "anthropic",
- model: "claude-opus-4-1-20250805",
+ expect(extractModelAndProvider("openhands/claude-opus-4-5-20251101")).toEqual({
+ provider: "openhands",
+ model: "claude-opus-4-5-20251101",
separator: "/",
});
});
diff --git a/frontend/__tests__/utils/is-custom-model.test.ts b/frontend/__tests__/utils/is-custom-model.test.ts
index 1da5667920..f011a1c71c 100644
--- a/frontend/__tests__/utils/is-custom-model.test.ts
+++ b/frontend/__tests__/utils/is-custom-model.test.ts
@@ -3,6 +3,7 @@ import { isCustomModel } from "#/utils/is-custom-model";
describe("isCustomModel", () => {
const models = ["anthropic/claude-3.5", "openai/gpt-3.5-turbo", "gpt-4o"];
+ const prefixedModels = ["anthropic/claude-3.5", "openai/gpt-4o"];
it("should return false by default", () => {
expect(isCustomModel(models, "")).toBe(false);
@@ -17,4 +18,8 @@ describe("isCustomModel", () => {
expect(isCustomModel(models, "openai/gpt-3.5-turbo")).toBe(false);
expect(isCustomModel(models, "openai/gpt-4o")).toBe(false);
});
+
+ it("treats bare and prefixed OpenAI models as the same model", () => {
+ expect(isCustomModel(prefixedModels, "gpt-4o")).toBe(false);
+ });
});
diff --git a/frontend/__tests__/utils/organize-models-and-providers.test.ts b/frontend/__tests__/utils/organize-models-and-providers.test.ts
index cf37ba9bbd..7df8be9cea 100644
--- a/frontend/__tests__/utils/organize-models-and-providers.test.ts
+++ b/frontend/__tests__/utils/organize-models-and-providers.test.ts
@@ -1,7 +1,9 @@
import { expect, test } from "vitest";
import { organizeModelsAndProviders } from "../../src/utils/organize-models-and-providers";
-test("organizeModelsAndProviders", () => {
+test("organizeModelsAndProviders β€” models already prefixed by backend", () => {
+ // The backend now assigns provider prefixes to bare LiteLLM names.
+ // The frontend only needs to parse slash-prefixed provider/model strings.
const models = [
"azure/ada",
"azure/gpt-35-turbo",
@@ -12,14 +14,10 @@ test("organizeModelsAndProviders", () => {
"sagemaker/meta-textgeneration-llama-2-13b",
"cohere.command-r-v1:0",
"cloudflare/@cf/mistral/mistral-7b-instruct-v0.1",
- "gpt-4o",
- "together-ai-21.1b-41b",
- "gpt-4o-mini",
+ "openai/gpt-4o",
+ "openai/gpt-4o-mini",
"anthropic/claude-3-5-sonnet-20241022",
- "claude-3-haiku-20240307",
- "claude-2",
- "claude-2.1",
- "anthropic.unsafe-claude-2.1",
+ "together-ai-21.1b-41b",
];
const object = organizeModelsAndProviders(models);
@@ -39,7 +37,6 @@ test("organizeModelsAndProviders", () => {
models: ["chat-bison", "chat-bison-32k"],
},
sagemaker: { separator: "/", models: ["meta-textgeneration-llama-2-13b"] },
- cohere: { separator: ".", models: ["command-r-v1:0"] },
cloudflare: {
separator: "/",
models: ["@cf/mistral/mistral-7b-instruct-v0.1"],
@@ -50,18 +47,11 @@ test("organizeModelsAndProviders", () => {
},
anthropic: {
separator: "/",
- models: [
- "claude-3-5-sonnet-20241022",
- ],
+ models: ["claude-3-5-sonnet-20241022"],
},
other: {
separator: "",
- models: [
- "together-ai-21.1b-41b",
- "claude-3-haiku-20240307",
- "claude-2",
- "claude-2.1",
- ],
+ models: ["cohere.command-r-v1:0", "together-ai-21.1b-41b"],
},
});
});
diff --git a/frontend/src/api/option-service/option-service.api.ts b/frontend/src/api/option-service/option-service.api.ts
index 149956a13d..fc14c301fa 100644
--- a/frontend/src/api/option-service/option-service.api.ts
+++ b/frontend/src/api/option-service/option-service.api.ts
@@ -1,16 +1,18 @@
import { openHands } from "../open-hands-axios";
-import { WebClientConfig } from "./option.types";
+import { ModelsResponse, WebClientConfig } from "./option.types";
/**
* Service for handling API options endpoints
*/
class OptionService {
/**
- * Retrieve the list of models available
- * @returns List of models available
+ * Retrieve the structured models response from the backend.
+ *
+ * The backend is the single source of truth for verified models,
+ * verified providers, and provider assignment for bare model names.
*/
- static async getModels(): Promise<string[]> {
- const { data } = await openHands.get<string[]>("/api/options/models");
+ static async getModels(): Promise<ModelsResponse> {
+ const { data } = await openHands.get<ModelsResponse>("/api/options/models");
return data;
}
diff --git a/frontend/src/api/option-service/option.types.ts b/frontend/src/api/option-service/option.types.ts
index 45fcdb2586..3fcc0201a3 100644
--- a/frontend/src/api/option-service/option.types.ts
+++ b/frontend/src/api/option-service/option.types.ts
@@ -1,5 +1,22 @@
import { Provider } from "#/types/settings";
+/**
+ * Structured response from ``GET /api/options/models``.
+ *
+ * The backend is the single source of truth β€” the frontend no longer carries
+ * its own hardcoded verified-model lists.
+ */
+export interface ModelsResponse {
+ /** Flat list of ``provider/model`` strings (bare names already prefixed). */
+ models: string[];
+ /** Model names (without provider) that OpenHands has verified to work well. */
+ verified_models: string[];
+ /** Provider names shown in the "Verified" section of the model selector. */
+ verified_providers: string[];
+ /** Recommended default model id (e.g. ``openhands/claude-opus-4-5-20251101``). */
+ default_model: string;
+}
+
export interface WebClientFeatureFlags {
enable_billing: boolean;
hide_llm_settings: boolean;
diff --git a/frontend/src/components/shared/modals/settings/model-selector.tsx b/frontend/src/components/shared/modals/settings/model-selector.tsx
index b542c4e695..a07bd1cc72 100644
--- a/frontend/src/components/shared/modals/settings/model-selector.tsx
+++ b/frontend/src/components/shared/modals/settings/model-selector.tsx
@@ -7,11 +7,6 @@ import React from "react";
import { useTranslation } from "react-i18next";
import { I18nKey } from "#/i18n/declaration";
import { mapProvider } from "#/utils/map-provider";
-import {
- VERIFIED_MODELS,
- VERIFIED_PROVIDERS,
- VERIFIED_OPENHANDS_MODELS,
-} from "#/utils/verified-models";
import { extractModelAndProvider } from "#/utils/extract-model-and-provider";
import { cn } from "#/utils/utils";
import { HelpLink } from "#/ui/help-link";
@@ -20,6 +15,10 @@ import { PRODUCT_URL } from "#/utils/constants";
interface ModelSelectorProps {
isDisabled?: boolean;
models: Record<string, { separator: string; models: string[] }>;
+ /** Model names (no provider prefix) the backend considers verified. */
+ verifiedModels: string[];
+ /** Provider names the backend considers verified. */
+ verifiedProviders: string[];
currentModel?: string;
onChange?: (provider: string | null, model: string | null) => void;
onDefaultValuesChanged?: (
@@ -33,6 +32,8 @@ interface ModelSelectorProps {
export function ModelSelector({
isDisabled,
models,
+ verifiedModels,
+ verifiedProviders,
currentModel,
onChange,
onDefaultValuesChanged,
@@ -45,14 +46,6 @@ export function ModelSelector({
);
const [selectedModel, setSelectedModel] = React.useState<string | null>(null);
- // Get the appropriate verified models array based on the selected provider
- const getVerifiedModels = () => {
- if (selectedProvider === "openhands") {
- return VERIFIED_OPENHANDS_MODELS;
- }
- return VERIFIED_MODELS;
- };
-
React.useEffect(() => {
if (currentModel) {
// runs when resetting to defaults
@@ -130,23 +123,23 @@ export function ModelSelector({
}}
>
<AutocompleteSection title={t(I18nKey.MODEL_SELECTOR$VERIFIED)}>
- {VERIFIED_PROVIDERS.filter((provider) => models[provider]).map(
- (provider) => (
+ {verifiedProviders
+ .filter((provider) => models[provider])
+ .map((provider) => (
<AutocompleteItem
data-testid={`provider-item-${provider}`}
key={provider}
>
{mapProvider(provider)}
</AutocompleteItem>
- ),
- )}
+ ))}
</AutocompleteSection>
{Object.keys(models).some(
- (provider) => !VERIFIED_PROVIDERS.includes(provider),
+ (provider) => !verifiedProviders.includes(provider),
) ? (
<AutocompleteSection title={t(I18nKey.MODEL_SELECTOR$OTHERS)}>
{Object.keys(models)
- .filter((provider) => !VERIFIED_PROVIDERS.includes(provider))
+ .filter((provider) => !verifiedProviders.includes(provider))
.map((provider) => (
<AutocompleteItem key={provider}>
{mapProvider(provider)}
@@ -197,7 +190,7 @@ export function ModelSelector({
}}
>
<AutocompleteSection title={t(I18nKey.MODEL_SELECTOR$VERIFIED)}>
- {getVerifiedModels()
+ {verifiedModels
.filter((model) =>
models[selectedProvider || ""]?.models?.includes(model),
)
@@ -206,11 +199,11 @@ export function ModelSelector({
))}
</AutocompleteSection>
{models[selectedProvider || ""]?.models?.some(
- (model) => !getVerifiedModels().includes(model),
+ (model) => !verifiedModels.includes(model),
) ? (
<AutocompleteSection title={t(I18nKey.MODEL_SELECTOR$OTHERS)}>
{models[selectedProvider || ""]?.models
- .filter((model) => !getVerifiedModels().includes(model))
+ .filter((model) => !verifiedModels.includes(model))
.map((model) => (
<AutocompleteItem
data-testid={`model-item-${model}`}
diff --git a/frontend/src/components/shared/modals/settings/settings-form.tsx b/frontend/src/components/shared/modals/settings/settings-form.tsx
index b31b04eb53..e373170248 100644
--- a/frontend/src/components/shared/modals/settings/settings-form.tsx
+++ b/frontend/src/components/shared/modals/settings/settings-form.tsx
@@ -18,10 +18,18 @@ import { SETTINGS_FORM } from "#/utils/constants";
interface SettingsFormProps {
settings: Settings;
models: string[];
+ verifiedModels: string[];
+ verifiedProviders: string[];
onClose: () => void;
}
-export function SettingsForm({ settings, models, onClose }: SettingsFormProps) {
+export function SettingsForm({
+ settings,
+ models,
+ verifiedModels,
+ verifiedProviders,
+ onClose,
+}: SettingsFormProps) {
const posthog = usePostHog();
const { mutate: saveUserSettings } = useSaveSettings();
@@ -80,6 +88,8 @@ export function SettingsForm({ settings, models, onClose }: SettingsFormProps) {
<div className="flex flex-col gap-[17px]">
<ModelSelector
models={organizeModelsAndProviders(models)}
+ verifiedModels={verifiedModels}
+ verifiedProviders={verifiedProviders}
currentModel={settings.llm_model}
wrapperClassName="!flex-col !gap-[17px]"
labelClassName={SETTINGS_FORM.LABEL_CLASSNAME}
diff --git a/frontend/src/components/shared/modals/settings/settings-modal.tsx b/frontend/src/components/shared/modals/settings/settings-modal.tsx
index 0fca7d2ea4..9a56d9659f 100644
--- a/frontend/src/components/shared/modals/settings/settings-modal.tsx
+++ b/frontend/src/components/shared/modals/settings/settings-modal.tsx
@@ -49,6 +49,8 @@ export function SettingsModal({ onClose, settings }: SettingsModalProps) {
<SettingsForm
settings={settings || DEFAULT_SETTINGS}
models={aiConfigOptions.data?.models}
+ verifiedModels={aiConfigOptions.data?.verifiedModels ?? []}
+ verifiedProviders={aiConfigOptions.data?.verifiedProviders ?? []}
onClose={onClose}
/>
)}
diff --git a/frontend/src/hooks/query/use-ai-config-options.ts b/frontend/src/hooks/query/use-ai-config-options.ts
index 50ec828b74..86ea0c6179 100644
--- a/frontend/src/hooks/query/use-ai-config-options.ts
+++ b/frontend/src/hooks/query/use-ai-config-options.ts
@@ -1,11 +1,17 @@
import { useQuery } from "@tanstack/react-query";
import OptionService from "#/api/option-service/option-service.api";
-const fetchAiConfigOptions = async () => ({
- models: await OptionService.getModels(),
- agents: await OptionService.getAgents(),
- securityAnalyzers: await OptionService.getSecurityAnalyzers(),
-});
+const fetchAiConfigOptions = async () => {
+ const modelsResponse = await OptionService.getModels();
+ return {
+ models: modelsResponse.models,
+ verifiedModels: modelsResponse.verified_models,
+ verifiedProviders: modelsResponse.verified_providers,
+ defaultModel: modelsResponse.default_model,
+ agents: await OptionService.getAgents(),
+ securityAnalyzers: await OptionService.getSecurityAnalyzers(),
+ };
+};
export const useAIConfigOptions = () =>
useQuery({
diff --git a/frontend/src/mocks/settings-handlers.ts b/frontend/src/mocks/settings-handlers.ts
index 19079e3655..7ff9c2aeb6 100644
--- a/frontend/src/mocks/settings-handlers.ts
+++ b/frontend/src/mocks/settings-handlers.ts
@@ -72,21 +72,38 @@ export const resetTestHandlersMockSettings = () => {
export const SETTINGS_HANDLERS = [
http.get("/api/options/models", async () =>
- HttpResponse.json([
- "gpt-3.5-turbo",
- "gpt-4o",
- "gpt-4o-mini",
- "anthropic/claude-3.5",
- "anthropic/claude-sonnet-4-20250514",
- "anthropic/claude-sonnet-4-5-20250929",
- "anthropic/claude-haiku-4-5-20251001",
- "anthropic/claude-opus-4-5-20251101",
- "openhands/claude-sonnet-4-20250514",
- "openhands/claude-sonnet-4-5-20250929",
- "openhands/claude-haiku-4-5-20251001",
- "openhands/claude-opus-4-5-20251101",
- "sambanova/Meta-Llama-3.1-8B-Instruct",
- ]),
+ HttpResponse.json({
+ models: [
+ "anthropic/claude-3.5",
+ "anthropic/claude-sonnet-4-20250514",
+ "anthropic/claude-sonnet-4-5-20250929",
+ "anthropic/claude-haiku-4-5-20251001",
+ "anthropic/claude-opus-4-5-20251101",
+ "openai/gpt-3.5-turbo",
+ "openai/gpt-4o",
+ "openai/gpt-4o-mini",
+ "openhands/claude-sonnet-4-20250514",
+ "openhands/claude-sonnet-4-5-20250929",
+ "openhands/claude-haiku-4-5-20251001",
+ "openhands/claude-opus-4-5-20251101",
+ "sambanova/Meta-Llama-3.1-8B-Instruct",
+ ],
+ verified_models: [
+ "claude-opus-4-5-20251101",
+ "claude-sonnet-4-5-20250929",
+ ],
+ verified_providers: [
+ "openhands",
+ "anthropic",
+ "openai",
+ "mistral",
+ "gemini",
+ "deepseek",
+ "moonshot",
+ "minimax",
+ ],
+ default_model: "openhands/claude-opus-4-5-20251101",
+ }),
),
http.get("/api/options/agents", async () =>
diff --git a/frontend/src/routes/llm-settings.tsx b/frontend/src/routes/llm-settings.tsx
index 4aba314773..e24f918b98 100644
--- a/frontend/src/routes/llm-settings.tsx
+++ b/frontend/src/routes/llm-settings.tsx
@@ -28,11 +28,12 @@ import { LlmSettingsInputsSkeleton } from "#/components/features/settings/llm-se
import { KeyStatusIcon } from "#/components/features/settings/key-status-icon";
import { DEFAULT_SETTINGS } from "#/services/settings";
import { getProviderId } from "#/utils/map-provider";
-import { DEFAULT_OPENHANDS_MODEL } from "#/utils/verified-models";
import { useMe } from "#/hooks/query/use-me";
import { usePermission } from "#/hooks/organizations/use-permissions";
import { useOrgTypeAndAccess } from "#/hooks/use-org-type-and-access";
+const DEFAULT_OPENHANDS_MODEL = "openhands/claude-opus-4-5-20251101";
+
interface OpenHandsApiKeyHelpProps {
testId: string;
}
@@ -134,6 +135,9 @@ function LlmSettingsScreen() {
const modelsAndProviders = organizeModelsAndProviders(
resources?.models || [],
);
+ const verifiedModels = resources?.verifiedModels || [];
+ const verifiedProviders = resources?.verifiedProviders || [];
+ const defaultModel = resources?.defaultModel || DEFAULT_OPENHANDS_MODEL;
// Determine if we should hide the API key input and use OpenHands-managed key (when using OpenHands provider in SaaS mode)
const currentModel = currentSelectedModel || settings?.llm_model;
@@ -547,7 +551,9 @@ function LlmSettingsScreen() {
<>
<ModelSelector
models={modelsAndProviders}
- currentModel={settings.llm_model || DEFAULT_OPENHANDS_MODEL}
+ verifiedModels={verifiedModels}
+ verifiedProviders={verifiedProviders}
+ currentModel={settings.llm_model || defaultModel}
onChange={handleModelIsDirty}
onDefaultValuesChanged={onDefaultValuesChanged}
wrapperClassName="!flex-col !gap-6"
@@ -598,8 +604,8 @@ function LlmSettingsScreen() {
testId="llm-custom-model-input"
name="llm-custom-model-input"
label={t(I18nKey.SETTINGS$CUSTOM_MODEL)}
- defaultValue={settings.llm_model || DEFAULT_OPENHANDS_MODEL}
- placeholder={DEFAULT_OPENHANDS_MODEL}
+ defaultValue={settings.llm_model || defaultModel}
+ placeholder={defaultModel}
type="text"
className="w-full max-w-[680px]"
onChange={handleCustomModelIsDirty}
diff --git a/frontend/src/utils/extract-model-and-provider.ts b/frontend/src/utils/extract-model-and-provider.ts
index ab0836079f..e3bba03407 100644
--- a/frontend/src/utils/extract-model-and-provider.ts
+++ b/frontend/src/utils/extract-model-and-provider.ts
@@ -1,63 +1,20 @@
-import { isNumber } from "./is-number";
-import {
- VERIFIED_ANTHROPIC_MODELS,
- VERIFIED_MISTRAL_MODELS,
- VERIFIED_OPENAI_MODELS,
- VERIFIED_OPENHANDS_MODELS,
-} from "./verified-models";
-
/**
- * Checks if the split array is actually a version number.
- * @param split The split array of the model string
- * @returns Boolean indicating if the split is actually a version number
+ * Given a model string, extract the provider and model name.
*
- * @example
- * const split = ["gpt-3", "5-turbo"] // incorrectly split from "gpt-3.5-turbo"
- * splitIsActuallyVersion(split) // returns true
- */
-const splitIsActuallyVersion = (split: string[]) =>
- split[1]?.[0] && isNumber(split[1][0]);
-
-/**
- * Given a model string, extract the provider and model name. Currently the supported separators are "/" and "."
- * @param model The model string
- * @returns An object containing the provider, model name, and separator
+ * Provider assignment for bare model names is handled by the backend before
+ * the model list reaches the frontend. This function only parses slash-based
+ * ``provider/model`` strings and leaves everything else as a bare model.
*
* @example
* extractModelAndProvider("azure/ada")
* // returns { provider: "azure", model: "ada", separator: "/" }
- *
- * extractModelAndProvider("cohere.command-r-v1:0")
- * // returns { provider: "cohere", model: "command-r-v1:0", separator: "." }
*/
export const extractModelAndProvider = (model: string) => {
- let separator = "/";
- let split = model.split(separator);
- if (split.length === 1) {
- // no "/" separator found, try with "."
- separator = ".";
- split = model.split(separator);
- if (splitIsActuallyVersion(split)) {
- split = [split.join(separator)]; // undo the split
- }
- }
- if (split.length === 1) {
- // no "/" or "." separator found
- if (VERIFIED_OPENAI_MODELS.includes(split[0])) {
- return { provider: "openai", model: split[0], separator: "/" };
- }
- if (VERIFIED_ANTHROPIC_MODELS.includes(split[0])) {
- return { provider: "anthropic", model: split[0], separator: "/" };
- }
- if (VERIFIED_MISTRAL_MODELS.includes(split[0])) {
- return { provider: "mistral", model: split[0], separator: "/" };
- }
- if (VERIFIED_OPENHANDS_MODELS.includes(split[0])) {
- return { provider: "openhands", model: split[0], separator: "/" };
- }
- // return as model only
+ const [provider, ...modelId] = model.split("/");
+
+ if (!provider || modelId.length === 0) {
return { provider: "", model, separator: "" };
}
- const [provider, ...modelId] = split;
- return { provider, model: modelId.join(separator), separator };
+
+ return { provider, model: modelId.join("/"), separator: "/" };
};
diff --git a/frontend/src/utils/is-custom-model.ts b/frontend/src/utils/is-custom-model.ts
index b4d5418f38..42bc692d9d 100644
--- a/frontend/src/utils/is-custom-model.ts
+++ b/frontend/src/utils/is-custom-model.ts
@@ -1,5 +1,15 @@
import { extractModelAndProvider } from "./extract-model-and-provider";
-import { organizeModelsAndProviders } from "./organize-models-and-providers";
+
+const isEquivalentOpenAIModel = (left: string, right: string) => {
+ const leftParts = extractModelAndProvider(left);
+ const rightParts = extractModelAndProvider(right);
+
+ return (
+ leftParts.model === rightParts.model &&
+ ((leftParts.provider === "openai" && !rightParts.provider) ||
+ (!leftParts.provider && rightParts.provider === "openai"))
+ );
+};
/**
* Check if a model is a custom model. A custom model is a model that is not part of the default models.
@@ -10,13 +20,11 @@ import { organizeModelsAndProviders } from "./organize-models-and-providers";
export const isCustomModel = (models: string[], model: string): boolean => {
if (!model) return false;
- const organizedModels = organizeModelsAndProviders(models);
- const { provider: extractedProvider, model: extractedModel } =
- extractModelAndProvider(model);
-
- const isKnownModel =
- extractedProvider in organizedModels &&
- organizedModels[extractedProvider].models.includes(extractedModel);
+ const isKnownModel = models.some(
+ (availableModel) =>
+ availableModel === model ||
+ isEquivalentOpenAIModel(availableModel, model),
+ );
return !isKnownModel;
};
diff --git a/frontend/src/utils/organize-models-and-providers.ts b/frontend/src/utils/organize-models-and-providers.ts
index e115b58403..3f2f9843e1 100644
--- a/frontend/src/utils/organize-models-and-providers.ts
+++ b/frontend/src/utils/organize-models-and-providers.ts
@@ -1,16 +1,12 @@
import { extractModelAndProvider } from "./extract-model-and-provider";
/**
- * Given a list of models, organize them by provider
+ * Given a list of models, organize them by provider.
* @param models The list of models
* @returns An object containing the provider and models
*
* @example
- * const models = [
- * "azure/ada",
- * "azure/gpt-35-turbo",
- * "cohere.command-r-v1:0",
- * ];
+ * const models = ["azure/ada", "azure/gpt-35-turbo", "gpt-4o"];
*
* organizeModelsAndProviders(models);
* // returns {
@@ -18,9 +14,9 @@ import { extractModelAndProvider } from "./extract-model-and-provider";
* // separator: "/",
* // models: ["ada", "gpt-35-turbo"],
* // },
- * // cohere: {
- * // separator: ".",
- * // models: ["command-r-v1:0"],
+ * // other: {
+ * // separator: "",
+ * // models: ["gpt-4o"],
* // },
* // }
*/
@@ -34,12 +30,6 @@ export const organizeModelsAndProviders = (models: string[]) => {
model: modelId,
} = extractModelAndProvider(model);
- // Ignore "anthropic" providers with a separator of "."
- // These are outdated and incompatible providers.
- if (provider === "anthropic" && separator === ".") {
- return;
- }
-
const key = provider || "other";
if (!object[key]) {
object[key] = { separator, models: [] };
diff --git a/frontend/src/utils/verified-models.ts b/frontend/src/utils/verified-models.ts
deleted file mode 100644
index 97c97eb617..0000000000
--- a/frontend/src/utils/verified-models.ts
+++ /dev/null
@@ -1,81 +0,0 @@
-// Here are the list of verified models and providers that we know work well with OpenHands.
-export const VERIFIED_PROVIDERS = [
- "openhands",
- "anthropic",
- "openai",
- "mistral",
- "lemonade",
- "clarifai",
-];
-export const VERIFIED_MODELS = [
- "claude-opus-4-6",
- "claude-opus-4-5-20251101",
- "claude-sonnet-4-6",
- "claude-sonnet-4-5-20250929",
- "gpt-5.2-codex",
- "gpt-5.2",
- "minimax-m2.5",
- "gemini-3-pro-preview",
- "gemini-3.1-pro-preview",
- "gemini-3-flash-preview",
- "deepseek-chat",
- "devstral-medium-2512",
- "kimi-k2-0711-preview",
- "kimi-k2.5",
- "qwen3-coder-480b",
- "qwen3-coder-next",
- "glm-4.7",
- "glm-5",
-];
-
-// LiteLLM does not return OpenAI models with the provider, so we list them here to set them ourselves for consistency
-// (e.g., they return `gpt-4o` instead of `openai/gpt-4o`)
-export const VERIFIED_OPENAI_MODELS = [
- "gpt-5.2",
- "gpt-5.2-codex",
- "gpt-4o",
- "gpt-4o-mini",
-];
-
-// LiteLLM does not return the compatible Anthropic models with the provider, so we list them here to set them ourselves
-// (e.g., they return `claude-3-5-sonnet-20241022` instead of `anthropic/claude-3-5-sonnet-20241022`)
-export const VERIFIED_ANTHROPIC_MODELS = [
- "claude-opus-4-6",
- "claude-opus-4-5-20251101",
- "claude-sonnet-4-5-20250929",
- "claude-3-5-sonnet-20240620",
- "claude-3-5-sonnet-20241022",
- "claude-3-7-sonnet-20250219",
- "claude-sonnet-4-20250514",
- "claude-opus-4-20250514",
- "claude-opus-4-1-20250805",
-];
-
-// LiteLLM does not return the compatible Mistral models with the provider, so we list them here to set them ourselves
-// (e.g., they return `devstral-small-2505` instead of `mistral/devstral-small-2505`)
-export const VERIFIED_MISTRAL_MODELS = ["devstral-medium-2512"];
-
-// LiteLLM does not return the compatible OpenHands models with the provider, so we list them here to set them ourselves
-// (e.g., they return `claude-sonnet-4-20250514` instead of `openhands/claude-sonnet-4-20250514`)
-export const VERIFIED_OPENHANDS_MODELS = [
- "claude-opus-4-6",
- "claude-opus-4-5-20251101",
- "claude-sonnet-4-6",
- "claude-sonnet-4-5-20250929",
- "gpt-5.2-codex",
- "gpt-5.2",
- "minimax-m2.5",
- "gemini-3-pro-preview",
- "gemini-3.1-pro-preview",
- "gemini-3-flash-preview",
- "devstral-medium-2512",
- "kimi-k2-0711-preview",
- "kimi-k2.5",
- "qwen3-coder-480b",
- "qwen3-coder-next",
- "glm-4.7",
- "glm-5",
-];
-
-// Default model for OpenHands provider
-export const DEFAULT_OPENHANDS_MODEL = "openhands/claude-opus-4-5-20251101";
diff --git a/openhands/server/mock/listen.py b/openhands/server/mock/listen.py
index 1b26bf37da..bd7709f512 100644
--- a/openhands/server/mock/listen.py
+++ b/openhands/server/mock/listen.py
@@ -39,13 +39,27 @@ def read_root() -> dict[str, str]:
@app.get('/api/options/models')
-def read_llm_models() -> list[str]:
- return [
- 'gpt-4',
- 'gpt-4-turbo-preview',
- 'gpt-4-0314',
- 'gpt-4-0613',
- ]
+def read_llm_models() -> dict:
+ return {
+ 'models': [
+ 'openai/gpt-4',
+ 'openai/gpt-4-turbo-preview',
+ 'openai/gpt-4-0314',
+ 'openai/gpt-4-0613',
+ ],
+ 'verified_models': [],
+ 'verified_providers': [
+ 'openhands',
+ 'anthropic',
+ 'openai',
+ 'mistral',
+ 'gemini',
+ 'deepseek',
+ 'moonshot',
+ 'minimax',
+ ],
+ 'default_model': 'openhands/claude-opus-4-5-20251101',
+ }
@app.get('/api/options/agents')
diff --git a/openhands/server/routes/public.py b/openhands/server/routes/public.py
index 1b21463add..0b3fa72150 100644
--- a/openhands/server/routes/public.py
+++ b/openhands/server/routes/public.py
@@ -15,25 +15,24 @@ from openhands.controller.agent import Agent
from openhands.security.options import SecurityAnalyzers
from openhands.server.dependencies import get_dependencies
from openhands.server.shared import config, server_config
-from openhands.utils.llm import get_supported_llm_models
+from openhands.utils.llm import ModelsResponse, get_supported_llm_models
app = APIRouter(prefix='/api/options', dependencies=get_dependencies())
-async def get_llm_models_dependency(request: Request) -> list[str]:
+async def get_llm_models_dependency(request: Request) -> ModelsResponse:
"""Returns a callable that provides the LLM models implementation.
Returns a factory that produces the actual implementation function.
Override this in enterprise/saas mode via app.dependency_overrides.
"""
-
- return get_supported_llm_models(config, [])
+ return get_supported_llm_models(config)
@app.get('/models')
async def get_litellm_models(
- models: list[str] = Depends(get_llm_models_dependency),
-) -> list[str]:
+ models: ModelsResponse = Depends(get_llm_models_dependency),
+) -> ModelsResponse:
return models
diff --git a/openhands/utils/llm.py b/openhands/utils/llm.py
index 66e6c130b8..8c23de8d7b 100644
--- a/openhands/utils/llm.py
+++ b/openhands/utils/llm.py
@@ -1,6 +1,7 @@
import warnings
import httpx
+from pydantic import BaseModel
with warnings.catch_warnings():
warnings.simplefilter('ignore')
@@ -11,28 +12,32 @@ from openhands.core.config import LLMConfig, OpenHandsConfig
from openhands.core.logger import openhands_logger as logger
from openhands.llm import bedrock
-# Hardcoded OpenHands provider models used in self-hosted mode.
-# In SaaS mode these are loaded from the database instead.
-OPENHANDS_MODELS = [
- 'openhands/claude-opus-4-6',
- 'openhands/claude-opus-4-5-20251101',
- 'openhands/claude-sonnet-4-6',
- 'openhands/claude-sonnet-4-5-20250929',
- 'openhands/gpt-5.2-codex',
- 'openhands/gpt-5.2',
- 'openhands/minimax-m2.5',
- 'openhands/gemini-3-pro-preview',
- 'openhands/gemini-3.1-pro-preview',
- 'openhands/gemini-3-flash-preview',
- 'openhands/deepseek-chat',
- 'openhands/devstral-medium-2512',
- 'openhands/kimi-k2-0711-preview',
- 'openhands/kimi-k2.5',
- 'openhands/qwen3-coder-480b',
- 'openhands/qwen3-coder-next',
- 'openhands/glm-4.7',
- 'openhands/glm-5',
-]
+# ---------------------------------------------------------------------------
+# The ``openhands-sdk`` package is the **single source of truth** for which
+# models are verified and how bare LiteLLM names map to providers.
+#
+# Self-hosted mode builds the ``openhands/…`` model list from the SDK's
+# ``VERIFIED_OPENHANDS_MODELS``. SaaS mode overrides it with the database
+# (via ``get_openhands_models``).
+# ---------------------------------------------------------------------------
+from openhands.sdk.llm.utils.verified_models import ( # noqa: E402
+ VERIFIED_ANTHROPIC_MODELS as _SDK_ANTHROPIC,
+)
+from openhands.sdk.llm.utils.verified_models import (
+ VERIFIED_MISTRAL_MODELS as _SDK_MISTRAL,
+)
+from openhands.sdk.llm.utils.verified_models import (
+ VERIFIED_MODELS as _SDK_VERIFIED_MODELS,
+)
+from openhands.sdk.llm.utils.verified_models import (
+ VERIFIED_OPENAI_MODELS as _SDK_OPENAI,
+)
+from openhands.sdk.llm.utils.verified_models import (
+ VERIFIED_OPENHANDS_MODELS as _SDK_OPENHANDS,
+)
+
+# Build the ``openhands/…`` model list from the SDK.
+OPENHANDS_MODELS: list[str] = [f'openhands/{m}' for m in _SDK_OPENHANDS]
CLARIFAI_MODELS = [
'clarifai/openai.chat-completion.gpt-oss-120b',
@@ -50,6 +55,42 @@ CLARIFAI_MODELS = [
'clarifai/moonshotai.kimi.Kimi-K2-Instruct',
]
+# ---------------------------------------------------------------------------
+# Provider-assignment tables β€” derived from the SDK.
+#
+# LiteLLM returns some well-known models as *bare* names (e.g. ``gpt-5.2``
+# instead of ``openai/gpt-5.2``). The backend uses these sets to assign
+# the canonical provider prefix *before* sending the list to the frontend.
+# ---------------------------------------------------------------------------
+VERIFIED_PROVIDERS: list[str] = list(_SDK_VERIFIED_MODELS.keys())
+
+_BARE_OPENAI_MODELS: set[str] = set(_SDK_OPENAI)
+_BARE_ANTHROPIC_MODELS: set[str] = set(_SDK_ANTHROPIC)
+_BARE_MISTRAL_MODELS: set[str] = set(_SDK_MISTRAL)
+
+DEFAULT_OPENHANDS_MODEL = 'openhands/claude-opus-4-5-20251101'
+
+
+# ---------------------------------------------------------------------------
+# Structured API response returned by ``/api/options/models``.
+# ---------------------------------------------------------------------------
+class ModelsResponse(BaseModel):
+ """Structured response from the models endpoint.
+
+ * ``models`` β€” flat list of ``provider/model`` strings (same shape as
+ before, but bare names are now properly prefixed).
+ * ``verified_models`` β€” model names (without provider prefix) that
+ OpenHands has verified to work well.
+ * ``verified_providers`` β€” provider names shown in the "Verified"
+ section of the model selector.
+ * ``default_model`` β€” the recommended default model id.
+ """
+
+ models: list[str]
+ verified_models: list[str]
+ verified_providers: list[str]
+ default_model: str
+
def is_openhands_model(model: str | None) -> bool:
"""Check if the model uses the OpenHands provider.
@@ -106,22 +147,74 @@ def get_provider_api_base(model: str) -> str | None:
return None
-def get_supported_llm_models(
- config: OpenHandsConfig,
+def get_openhands_models(
verified_models: list[str] | None = None,
) -> list[str]:
- """Get all models supported by LiteLLM.
+ """Return the list of OpenHands-provider model strings.
- This function combines models from litellm and Bedrock, removing any
- error-prone Bedrock models.
+ In self-hosted mode *verified_models* is ``None`` (or empty) and the
+ hardcoded ``OPENHANDS_MODELS`` list is used. In SaaS mode the caller
+ passes the database-backed list which takes precedence.
Args:
- config: The OpenHands configuration.
- verified_models: Optional list of verified model strings from the database
- (SaaS mode). When provided, these replace the hardcoded OPENHANDS_MODELS.
+ verified_models: Optional list of ``"openhands/<name>"`` strings
+ loaded from the verified-models database table.
Returns:
- list[str]: A sorted list of unique model names.
+ A list such as ``["openhands/claude-opus-4-6", ...]``.
+ """
+ return verified_models if verified_models else OPENHANDS_MODELS
+
+
+def _assign_provider(model: str) -> str:
+ """Prefix a bare model name with its canonical provider.
+
+ Models that already contain a ``/`` provider separator are returned
+ unchanged. Only well-known bare names (OpenAI, Anthropic, Mistral)
+ are prefixed.
+ """
+ if '/' in model:
+ return model
+
+ # Prefix well-known bare SDK model names with their canonical provider.
+ # The provider sets are loaded from the SDK once at import time.
+ if model in _BARE_OPENAI_MODELS:
+ return f'openai/{model}'
+ if model in _BARE_ANTHROPIC_MODELS:
+ return f'anthropic/{model}'
+ if model in _BARE_MISTRAL_MODELS:
+ return f'mistral/{model}'
+ return model
+
+
+def _derive_verified_models(openhands_models: list[str]) -> list[str]:
+ """Extract the bare model names from the ``openhands/…`` model list."""
+ return [
+ m.removeprefix('openhands/')
+ for m in openhands_models
+ if m.startswith('openhands/')
+ ]
+
+
+def get_supported_llm_models(
+ config: OpenHandsConfig,
+ verified_models: list[str] | None = None,
+) -> ModelsResponse:
+ """Collect every model available to this server and return structured data.
+
+ The returned ``ModelsResponse`` contains:
+
+ * a flat list of ``provider/model`` strings (bare LiteLLM names are
+ prefixed with the correct provider),
+ * a list of *verified* model names (the OpenHands-curated subset),
+ * the set of verified providers, and
+ * the recommended default model.
+
+ Args:
+ config: The OpenHands configuration.
+ verified_models: Optional list of ``"openhands/<name>"`` strings
+ from the database (SaaS mode). When provided these replace the
+ hardcoded ``OPENHANDS_MODELS``.
"""
litellm_model_list = litellm.model_list + list(litellm.model_cost.keys())
litellm_model_list_without_bedrock = bedrock.remove_error_modelId(
@@ -129,7 +222,7 @@ def get_supported_llm_models(
)
# TODO: for bedrock, this is using the default config
llm_config: LLMConfig = config.get_llm_config()
- bedrock_model_list = []
+ bedrock_model_list: list[str] = []
if (
llm_config.aws_region_name
and llm_config.aws_access_key_id
@@ -156,8 +249,17 @@ def get_supported_llm_models(
except httpx.HTTPError as e:
logger.error(f'Error getting OLLAMA models: {e}')
- # Use database-backed models if provided (SaaS), otherwise use hardcoded list
- openhands_models = verified_models if verified_models else OPENHANDS_MODELS
- model_list = openhands_models + CLARIFAI_MODELS + model_list
+ openhands_models = get_openhands_models(verified_models)
+
+ # Assign canonical provider prefixes to bare LiteLLM names, then dedupe.
+ all_models = (
+ openhands_models + CLARIFAI_MODELS + [_assign_provider(m) for m in model_list]
+ )
+ unique_models = sorted(set(all_models))
- return sorted(set(model_list))
+ return ModelsResponse(
+ models=unique_models,
+ verified_models=_derive_verified_models(openhands_models),
+ verified_providers=VERIFIED_PROVIDERS,
+ default_model=DEFAULT_OPENHANDS_MODEL,
+ )
diff --git a/tests/unit/utils/test_llm_utils.py b/tests/unit/utils/test_llm_utils.py
index 67a8a0696b..665a20a997 100644
--- a/tests/unit/utils/test_llm_utils.py
+++ b/tests/unit/utils/test_llm_utils.py
@@ -1,6 +1,12 @@
"""Tests for openhands.utils.llm module."""
-from openhands.utils.llm import get_provider_api_base, is_openhands_model
+from openhands.utils import llm as llm_utils
+from openhands.utils.llm import (
+ _assign_provider,
+ _derive_verified_models,
+ get_provider_api_base,
+ is_openhands_model,
+)
class TestIsOpenhandsModel:
@@ -34,6 +40,55 @@ class TestIsOpenhandsModel:
assert is_openhands_model('OPENHANDS/model') is False # Wrong case
+class TestAssignProvider:
+ """Tests for the _assign_provider helper."""
+
+ def test_known_bare_models_get_prefixed(self, monkeypatch):
+ """Test that known bare models get the expected provider prefix."""
+ monkeypatch.setattr(llm_utils, '_BARE_OPENAI_MODELS', {'gpt-5.2'})
+ monkeypatch.setattr(
+ llm_utils, '_BARE_ANTHROPIC_MODELS', {'claude-sonnet-4-5-20250929'}
+ )
+ monkeypatch.setattr(llm_utils, '_BARE_MISTRAL_MODELS', {'mistral-large-latest'})
+
+ assert _assign_provider('gpt-5.2') == 'openai/gpt-5.2'
+ assert (
+ _assign_provider('claude-sonnet-4-5-20250929')
+ == 'anthropic/claude-sonnet-4-5-20250929'
+ )
+ assert (
+ _assign_provider('mistral-large-latest') == 'mistral/mistral-large-latest'
+ )
+
+ def test_prefixed_and_unknown_models_remain_unchanged(self, monkeypatch):
+ """Test that only known bare models are rewritten."""
+ monkeypatch.setattr(llm_utils, '_BARE_OPENAI_MODELS', {'gpt-5.2'})
+ monkeypatch.setattr(llm_utils, '_BARE_ANTHROPIC_MODELS', set())
+ monkeypatch.setattr(llm_utils, '_BARE_MISTRAL_MODELS', set())
+
+ assert _assign_provider('openai/gpt-5.2') == 'openai/gpt-5.2'
+ assert _assign_provider('cohere.command-r-v1:0') == 'cohere.command-r-v1:0'
+ assert _assign_provider('custom-model') == 'custom-model'
+
+
+class TestDeriveVerifiedModels:
+ """Tests for the _derive_verified_models helper."""
+
+ def test_extracts_openhands_model_names(self):
+ """Test that only openhands-prefixed models are returned bare."""
+ models = [
+ 'openhands/claude-opus-4-5-20251101',
+ 'openhands/gpt-5',
+ 'openai/gpt-5',
+ 'gpt-4o',
+ ]
+
+ assert _derive_verified_models(models) == [
+ 'claude-opus-4-5-20251101',
+ 'gpt-5',
+ ]
+
+
class TestGetProviderApiBase:
"""Tests for the get_provider_api_base function."""