Skip to content
Closed
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
19 changes: 14 additions & 5 deletions hermes_cli/model_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1515,18 +1515,27 @@ def _has_aws_sdk_creds_for_listing(slug: str) -> bool:
if fb:
models_list = list(fb)

# Prefer the endpoint's live /models list when credentials are
# available, unless the provider explicitly opts out via
# discover_models: false (e.g. dedicated endpoints that expose
# the entire aggregator catalog via /models).
# Prefer the endpoint's live /models list when discoverable,
# unless the provider explicitly opts out via discover_models: false.
# Policy mirrors Section 4's should_probe logic:
# - With an api_key: always probe (user opted into the endpoint).
# - Without an api_key but with explicit models: skip — the user
# is narrowing a public endpoint to a specific subset.
# - Without an api_key AND no explicit models: probe anyway so
# bare-endpoint providers (local llama.cpp / Ollama servers)
# still show their full model catalog.
api_key = str(ep_cfg.get("api_key", "") or "").strip()
if not api_key:
key_env = str(ep_cfg.get("key_env", "") or "").strip()
api_key = os.environ.get(key_env, "").strip() if key_env else ""
discover = ep_cfg.get("discover_models", True)
if isinstance(discover, str):
discover = discover.lower() not in {"false", "no", "0"}
if api_url and api_key and discover:
has_explicit_models = bool(models_list)
should_probe = bool(api_url) and discover and (
bool(api_key) or not has_explicit_models
)
if should_probe:
try:
from hermes_cli.models import fetch_api_models
live_models = fetch_api_models(api_key, api_url)
Expand Down