Skip to content

The agent that grows with you

fix(gateway): let GET /api/model/options opt out of unconfigured skeleton rows

Austin Pickett82f2dcb28631
diff --git a/gateway/platforms/api_server.py b/gateway/platforms/api_server.py
index bbb97ea0725..530f80c39a4 100644
--- a/gateway/platforms/api_server.py
+++ b/gateway/platforms/api_server.py
@@ -296,37 +296,10 @@ def _clean_request_string(value: Any) -> Optional[str]:
return (value.strip() or None) if isinstance(value, str) else None
-def _request_reasoning_config(model_options: Any) -> Optional[Dict[str, Any]]:
- """Translate model_options (structured ``reasoning`` or legacy ``reasoning_effort``) into
- AIAgent reasoning_config; unknown effort values are ignored, never raised."""
- if not isinstance(model_options, dict):
- return None
- reasoning = model_options.get("reasoning")
- enabled: Any = None
- effort: Any = model_options.get("reasoning_effort")
- if isinstance(reasoning, dict):
- enabled = reasoning.get("enabled")
- effort = reasoning.get("effort", effort)
- effort_norm = str(effort).strip().lower() if effort is not None else ""
- if enabled is False or effort_norm == "none":
- return {"enabled": False}
- if effort_norm in _REASONING_EFFORTS and effort_norm != "none":
- return {"enabled": True, "effort": effort_norm}
- if enabled is True:
- return {"enabled": True}
- return None
-
-
-def _request_service_tier(model_options: Any) -> Any:
- """Return a per-request service_tier override or _REQUEST_OPTION_MISSING."""
- if not isinstance(model_options, dict):
- return _REQUEST_OPTION_MISSING
- if "service_tier" in model_options:
- raw_tier = model_options.get("service_tier")
- return _clean_request_string(raw_tier) if isinstance(raw_tier, str) else raw_tier
- if "fast" in model_options:
- return "priority" if _coerce_request_bool(model_options.get("fast"), default=False) else None
- return _REQUEST_OPTION_MISSING
+# model_options decoding lives in the topical sibling (line-cap offset);
+# re-exported here so importers are unaffected.
+from gateway.platforms.api_server_request_options import ( # noqa: E402
+ _request_reasoning_config, _request_service_tier)
def _apply_runtime_agent_overrides(
@@ -2520,12 +2493,14 @@ class APIServerAdapter(OpenAICompatRoutesMixin, BasePlatformAdapter):
"""GET /api/model/options — the dashboard/TUI model-picker inventory, so external clients
can sync to the configured provider catalog instead of scraping /v1/models."""
refresh = _coerce_request_bool(request.query.get("refresh"), default=False)
+ include_unconfigured = _coerce_request_bool(
+ request.query.get("include_unconfigured"), default=True)
try:
from hermes_cli.inventory import build_model_options_payload, load_picker_context
def _build_payload() -> Dict[str, Any]:
return build_model_options_payload(
- load_picker_context(), include_unconfigured=True, refresh=refresh)
+ load_picker_context(), include_unconfigured=include_unconfigured, refresh=refresh)
# Enrichment can fetch pricing/provider catalogs: keep it off the event loop.
payload = await asyncio.to_thread(_build_payload)
return web.json_response(payload)
diff --git a/gateway/platforms/api_server_request_options.py b/gateway/platforms/api_server_request_options.py
new file mode 100644
index 00000000000..564331bf3c2
--- /dev/null
+++ b/gateway/platforms/api_server_request_options.py
@@ -0,0 +1,48 @@
+"""Per-request ``model_options`` decoding, lifted from ``platforms/api_server.py``.
+
+Keeps the api_server facade under its frozen line cap (root AGENTS.md god-file
+guidance: move code into a topical sibling). ``api_server.py`` re-exports
+``_request_service_tier`` and ``_request_reasoning_config`` so existing importers
+are unaffected; the helpers those two read stay in the facade and are imported
+lazily (call time) to avoid an import cycle.
+"""
+
+from typing import Any, Dict, Optional
+
+
+def _request_reasoning_config(model_options: Any) -> Optional[Dict[str, Any]]:
+ """Translate model_options (structured ``reasoning`` or legacy ``reasoning_effort``) into
+ AIAgent reasoning_config; unknown effort values are ignored, never raised."""
+ if not isinstance(model_options, dict):
+ return None
+ reasoning = model_options.get("reasoning")
+ enabled: Any = None
+ effort: Any = None
+ if isinstance(reasoning, dict):
+ enabled = reasoning.get("enabled")
+ effort = reasoning.get("effort")
+ effort = model_options.get("reasoning_effort", effort)
+ effort_norm = str(effort).strip().lower() if effort is not None else ""
+ if enabled is False or effort_norm == "none":
+ return {"enabled": False}
+ from gateway.platforms.api_server import _REASONING_EFFORTS
+
+ if effort_norm in _REASONING_EFFORTS and effort_norm != "none":
+ return {"enabled": True, "effort": effort_norm}
+ if enabled is True:
+ return {"enabled": True}
+ return None
+
+
+def _request_service_tier(model_options: Any) -> Any:
+ """Return a per-request service_tier override or _REQUEST_OPTION_MISSING."""
+ from gateway.platforms.api_server import _REQUEST_OPTION_MISSING, _clean_request_string, _coerce_request_bool
+
+ if not isinstance(model_options, dict):
+ return _REQUEST_OPTION_MISSING
+ if "service_tier" in model_options:
+ raw_tier = model_options.get("service_tier")
+ return _clean_request_string(raw_tier) if isinstance(raw_tier, str) else raw_tier
+ if "fast" in model_options:
+ return "priority" if _coerce_request_bool(model_options.get("fast"), default=False) else None
+ return _REQUEST_OPTION_MISSING
diff --git a/tests/gateway/test_api_server_model_options_include_unconfigured.py b/tests/gateway/test_api_server_model_options_include_unconfigured.py
new file mode 100644
index 00000000000..f82be91d5b2
--- /dev/null
+++ b/tests/gateway/test_api_server_model_options_include_unconfigured.py
@@ -0,0 +1,50 @@
+"""GET /api/model/options must forward ``include_unconfigured`` from the query
+string (default true) to ``build_model_options_payload`` instead of hardcoding
+it — external API consumers need a way to request the explicit-only view, and the
+unconfigured-row path must honor ``model_catalog.excluded_providers``
+(#68816)."""
+
+from unittest.mock import patch
+
+import pytest
+from aiohttp import web
+from aiohttp.test_utils import TestClient, TestServer
+
+from gateway.config import PlatformConfig
+from gateway.platforms.api_server import APIServerAdapter
+
+
+def _make_adapter() -> APIServerAdapter:
+ return APIServerAdapter(PlatformConfig(enabled=True))
+
+
+def _create_app(adapter: APIServerAdapter) -> web.Application:
+ """Minimal app exposing only the route under test (no key configured → auth passes)."""
+ app = web.Application()
+ app.router.add_get("/api/model/options", adapter._handle_model_options)
+ return app
+
+
+async def _captured_include_unconfigured(adapter, query: str) -> tuple[int, bool]:
+ app = _create_app(adapter)
+ with patch("hermes_cli.inventory.load_picker_context", return_value=object()), \
+ patch("hermes_cli.inventory.build_model_options_payload",
+ return_value={"providers": []}) as build:
+ async with TestClient(TestServer(app)) as cli:
+ response = await cli.get(f"/api/model/options{query}")
+ return response.status, bool(build.call_args.kwargs.get("include_unconfigured"))
+
+
+async def test_default_keeps_unconfigured_rows():
+ status, flag = await _captured_include_unconfigured(_make_adapter(), "")
+ assert status == 200
+ assert flag is True, "default (no query param) must stay include_unconfigured=True"
+
+
+async def test_false_query_param_disables_unconfigured_rows():
+ status, flag = await _captured_include_unconfigured(
+ _make_adapter(), "?include_unconfigured=false")
+ assert status == 200
+ assert flag is False, "explicit include_unconfigured=false must reach the payload builder"