Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openhands-sdk/openhands/sdk/llm/utils/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ These lists are a curated set of models that work well, not a catalog of everyth
- When you add a new version, remove the oldest version in the same line, in every list where it appears (the provider list and `VERIFIED_OPENHANDS_MODELS`).
- Every entry in `VERIFIED_OPENHANDS_MODELS` must also appear in a provider list, unless it is OpenHands-only; `tests/sdk/llm/test_model_list.py` checks this.
- Do not add a model just because LiteLLM or OpenRouter knows about it. The unverified catalog (`unverified_models.py`) covers that.
- `openrouter` is a verified provider. Its entries are OpenRouter ids with the `openrouter/` prefix stripped (so `anthropic/claude-opus-5` corresponds to `openrouter/anthropic/claude-opus-5`), because OpenRouter namespaces every model under its upstream vendor. Every entry must be a real LiteLLM catalog id (`openrouter/<entry>` must resolve via `get_supported_llm_models()`), otherwise the route has no known context window. Keep only the frontier routes the OpenHands proxy serves, not OpenRouter's full catalog.
- `openrouter` is a verified provider. Its entries are actual OpenRouter ids with the `openrouter/` prefix stripped (so `anthropic/claude-opus-5` corresponds to `openrouter/anthropic/claude-opus-5`), because OpenRouter namespaces every model under its upstream vendor. Do not require these routes to appear in LiteLLM's cost map; OpenRouter's endpoints API supplies runtime context limits. Keep only the frontier routes the OpenHands proxy serves, not OpenRouter's full catalog.
13 changes: 8 additions & 5 deletions openhands-sdk/openhands/sdk/llm/utils/unverified_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,18 @@ def get_supported_llm_models(
aws_access_key_id: SecretStr | None = None,
aws_secret_access_key: SecretStr | None = None,
) -> list[str]:
"""Get all models supported by LiteLLM.
"""Get models from LiteLLM, verified OpenRouter routes, and Bedrock.

This function combines models from litellm and Bedrock, removing any
error-prone Bedrock models.
Bedrock models are excluded unless AWS credentials are configured.

Returns:
list[str]: A sorted list of unique model names.
list[str]: Available model identifiers.
"""
litellm_model_list = litellm.model_list + list(litellm.model_cost.keys())
litellm_model_list = (
litellm.model_list
+ list(litellm.model_cost.keys())
+ [f"openrouter/{model}" for model in VERIFIED_MODELS["openrouter"]]
)
litellm_model_list_without_bedrock = list(
filter(lambda m: not m.startswith("bedrock"), litellm_model_list)
)
Expand Down
7 changes: 2 additions & 5 deletions openhands-sdk/openhands/sdk/llm/utils/verified_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,8 @@

# OpenRouter routes other vendors' models. Entries are the OpenRouter id with
# the ``openrouter/`` prefix stripped (so ``anthropic/claude-opus-5`` here
# corresponds to ``openrouter/anthropic/claude-opus-5``), and every entry must
# be a real LiteLLM catalog id (``openrouter/<entry>`` must resolve in
# ``get_supported_llm_models()``) so the route has known context-window
# metadata. Only the frontier routes the OpenHands proxy itself serves are
# kept; the long tail stays in the unverified catalog.
# corresponds to ``openrouter/anthropic/claude-opus-5``). Keep only the frontier
# routes the OpenHands proxy serves, using OpenRouter's actual model ids.
VERIFIED_OPENROUTER_MODELS = [
"anthropic/claude-opus-5",
"anthropic/claude-sonnet-5",
Expand Down
49 changes: 29 additions & 20 deletions tests/agent_server/test_llm_router.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Tests for LLM router."""

import litellm
import pytest
from fastapi.testclient import TestClient

Expand Down Expand Up @@ -54,27 +55,35 @@ async def test_list_models_filtered_by_provider():
assert len(response.models) < len(all_models_response.models)


@pytest.mark.asyncio
async def test_list_models_filtered_by_openrouter_provider():
"""OpenRouter's verified entries are namespaced ids (the ``openrouter/``
prefix stripped, e.g. ``deepseek/deepseek-chat``). Those same strings are
also genuine LiteLLM catalog models routed to their upstream provider, so a
naive verified-list match would leak the upstream-direct models into the
OpenRouter response. Every returned model must be an ``openrouter/`` route.
"""
response = await list_models(provider="openrouter")
assert len(response.models) > 0
assert all(m.startswith("openrouter/") for m in response.models), (
"OpenRouter response must only contain openrouter/-prefixed routes, "
f"got non-prefixed entries: "
f"{[m for m in response.models if not m.startswith('openrouter/')]}"
@pytest.mark.parametrize("openrouter_in_catalog", [False, True])
def test_list_models_filtered_by_openrouter_provider(
client, monkeypatch, openrouter_in_catalog
):
"""Verified routes survive catalog removal without leaking direct models."""
catalog = [
"deepseek/deepseek-chat",
"deepseek/deepseek-v4-pro",
"deepseek/deepseek-v4-flash",
]
if openrouter_in_catalog:
catalog.append("openrouter/deepseek/deepseek-chat")
monkeypatch.setattr(litellm, "model_list", catalog)
monkeypatch.setattr(
litellm,
"model_cost",
{"openrouter/custom/model": {}} if openrouter_in_catalog else {},
)
# A namespaced entry that collides with a deepseek-direct catalog model must
# resolve to the OpenRouter route, not the DeepSeek-direct model.
assert "openrouter/deepseek/deepseek-chat" in response.models
assert "deepseek/deepseek-chat" not in response.models
assert "deepseek/deepseek-v4-pro" not in response.models
assert "deepseek/deepseek-v4-flash" not in response.models

response = client.get("/api/llm/models?provider=openrouter")

assert response.status_code == 200
models = response.json()["models"]
assert "openrouter/deepseek/deepseek-chat" in models
assert all(model.startswith("openrouter/") for model in models)
assert models == sorted(set(models))
if openrouter_in_catalog:
assert "openrouter/custom/model" in models
assert set(models) <= set(client.get("/api/llm/models").json()["models"])


@pytest.mark.asyncio
Expand Down
30 changes: 19 additions & 11 deletions tests/sdk/llm/test_model_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"""

import pytest
from litellm import get_supported_openai_params
from litellm.utils import supports_vision

from openhands.sdk.llm.utils.model_features import (
Expand Down Expand Up @@ -66,17 +67,6 @@ def test_model_matches(name, pattern, expected):
("moonshot/kimi-k2.5", False),
("moonshot/kimi-k2-thinking", False),
("litellm_proxy/moonshot/kimi-k2-thinking", False),
# Route-dependent, and both directions are correct: OpenRouter accepts
# `reasoning_effort` and translates it, while Moonshot's own API does
# not take the parameter at all (see the two rows above). These follow
# LiteLLM's per-route `supported_openai_params` rather than an SDK
# override, so a value here tracks upstream and may move again (#4877).
("openrouter/moonshotai/kimi-k2.5", True),
("openrouter/moonshotai/kimi-k2-thinking", True),
# OpenRouter reasoning-capable models per LiteLLM metadata
("openrouter/deepseek/deepseek-r1", True),
("openrouter/anthropic/claude-opus-4.5", True),
("openrouter/openai/gpt-5", True),
# Eval LiteLLM proxy wrapper should not affect capability detection.
("litellm_proxy/gpt-5", True),
("litellm_proxy/claude-opus-4-5", True),
Expand Down Expand Up @@ -109,6 +99,24 @@ def test_reasoning_effort_support(model, expected_reasoning):
assert features.supports_reasoning_effort == expected_reasoning


@pytest.mark.parametrize(
"model",
[
"openrouter/moonshotai/kimi-k2.5",
"openrouter/moonshotai/kimi-k2-thinking",
"openrouter/deepseek/deepseek-r1",
"openrouter/anthropic/claude-opus-4.5",
"openrouter/openai/gpt-5",
],
)
def test_openrouter_reasoning_effort_follows_supported_params(model):
supported_params = get_supported_openai_params(model=model) or []
expected = "reasoning_effort" in supported_params

assert get_features(model).supports_reasoning_effort == expected
assert get_features(f"litellm_proxy/{model}").supports_reasoning_effort == expected


@pytest.mark.parametrize(
"model,expected_extended_thinking",
[
Expand Down
30 changes: 16 additions & 14 deletions tests/sdk/llm/test_model_list.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import sys
from unittest.mock import patch

import litellm

from openhands.sdk.llm.utils.unverified_models import (
_list_bedrock_foundation_models,
get_supported_llm_models,
Expand Down Expand Up @@ -144,21 +146,21 @@ def test_openrouter_is_a_verified_provider():
assert not any(m.startswith("openrouter/") for m in VERIFIED_MODELS["openrouter"])


def test_openrouter_entries_are_real_catalog_ids():
"""Every OpenRouter verified entry must resolve to a real LiteLLM catalog
model (``openrouter/<entry>``), so the route has known context-window
metadata for condensation. An alias-only id like ``openai/gpt-5.6`` that no
catalog exposes must not be listed.
"""
catalog = set(get_supported_llm_models())
missing = [
entry
for entry in VERIFIED_MODELS["openrouter"]
if f"openrouter/{entry}" not in catalog
]
assert not missing, (
f"OpenRouter verified entries are not real LiteLLM catalog ids: {missing}"
def test_openrouter_models_remain_discoverable_without_litellm_catalog(monkeypatch):
monkeypatch.setattr(
litellm,
"model_list",
["deepseek/deepseek-chat", "bedrock/anthropic.claude-3"],
)
monkeypatch.setattr(litellm, "model_cost", {})

models = get_supported_llm_models()

assert "openrouter/deepseek/deepseek-chat" in models
assert "deepseek/deepseek-chat" in models
assert "bedrock/anthropic.claude-3" not in models
assert "openrouter/openai/gpt-5.6" not in models
assert "openrouter" not in get_unverified_models()


def test_nemotron_3_super_uses_full_infra_name():
Expand Down
14 changes: 7 additions & 7 deletions tests/sdk/tool/test_mcp_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ class MCPComplexAction(Action):
string_list: list[str] = Field(default_factory=list, description="List of strings")


class CustomAliasedAction(Action):
mcp_schema_alias_specs: ClassVar[dict[str, dict[str, Any]]] = {
"extra_field": {"type": "string"}
}
mcp_schema_alias_required: ClassVar[set[str]] = {"extra_field"}


class MCPSchemaTestObservation(Observation):
"""Test observation class for MCP schema testing."""

Expand Down Expand Up @@ -500,13 +507,6 @@ def test_schema_mcp_aliases_use_declared_class_apis():
assert model.mcp_schema_alias_specs == {}
assert model.mcp_schema_alias_required == set()

# Dynamic model with alias specs
class CustomAliasedAction(Action):
mcp_schema_alias_specs: ClassVar[dict[str, dict[str, Any]]] = {
"extra_field": {"type": "string"}
}
mcp_schema_alias_required: ClassVar[set[str]] = {"extra_field"}

exported = CustomAliasedAction.to_mcp_schema()
assert "extra_field" in exported.get("properties", {})
assert "extra_field" in exported.get("required", [])
Loading