Skip to content

The agent that grows with you

fix(picker): Entra-only Azure Foundry stays listed in /model without an API key

teknium141a0c3f17cb9
diff --git a/hermes_cli/model_switch_providers.py b/hermes_cli/model_switch_providers.py
index 152b60c205b..9e45c97151e 100644
--- a/hermes_cli/model_switch_providers.py
+++ b/hermes_cli/model_switch_providers.py
@@ -355,9 +355,23 @@ def _overlay_has_env_creds(pid: str, hermes_slug: str, overlay, read_env) -> boo
pcfg = PROVIDER_REGISTRY.get(key)
if pcfg and pcfg.api_key_env_vars and _any_env(pcfg.api_key_env_vars, read_env):
return True
+ if not has_creds and hermes_slug == "azure-foundry":
+ has_creds = _azure_entra_configured(read_env)
return has_creds
+def _azure_entra_configured(read_env=os.environ.get) -> bool:
+ """Azure Foundry under ``model.auth_mode: entra_id`` mints a per-request bearer, so no
+ ``AZURE_FOUNDRY_API_KEY`` ever exists; the row is configured once the runtime resolver's own
+ inputs are (provider + auth_mode + an endpoint). No token is minted here (#27989)."""
+ from hermes_cli.models import _get_model_config_dict
+ model_cfg = _get_model_config_dict()
+ if (str(model_cfg.get("provider") or "").strip().lower() != "azure-foundry"
+ or str(model_cfg.get("auth_mode") or "").strip().lower() != "entra_id"):
+ return False
+ return bool(str(model_cfg.get("base_url") or "").strip() or read_env("AZURE_FOUNDRY_BASE_URL"))
+
+
def _has_fast_aws_sdk_signal() -> bool:
"""True when explicit AWS auth config is present in the environment.
diff --git a/tests/hermes_cli/test_user_providers_model_switch.py b/tests/hermes_cli/test_user_providers_model_switch.py
index b8a00d02e8d..c981a9cdea6 100644
--- a/tests/hermes_cli/test_user_providers_model_switch.py
+++ b/tests/hermes_cli/test_user_providers_model_switch.py
@@ -634,3 +634,27 @@ def test_overlay_provider_row_merges_configured_models(monkeypatch):
assert row["source"] == "hermes"
assert row["models"] == ["gpt-5.5", "shared", "gpt-4.1-mini", "gpt-5.6-sol"]
assert row["total_models"] == 4
+
+
[email protected]("base_url, listed", [("https://r.openai.azure.com/openai/v1", True), ("", False)])
+def test_entra_only_azure_foundry_row_is_listed_without_api_key(monkeypatch, base_url, listed):
+ """``model.auth_mode: entra_id`` mints a per-request bearer, so no ``AZURE_FOUNDRY_API_KEY``
+ ever exists; the picker and the prefetch scan must still treat the provider as configured
+ once its endpoint is set — and not before (#27989). No token is minted for the listing."""
+ from hermes_cli.model_switch_providers import _collect_authed_provider_slugs
+ from hermes_cli.providers import HERMES_OVERLAYS
+
+ monkeypatch.setattr("agent.models_dev.fetch_models_dev", lambda: {})
+ monkeypatch.setattr("agent.models_dev.PROVIDER_TO_MODELS_DEV", {})
+ monkeypatch.setattr("hermes_cli.providers.HERMES_OVERLAYS", {"azure-foundry": HERMES_OVERLAYS["azure-foundry"]})
+ monkeypatch.setattr("hermes_cli.models.cached_provider_model_ids", lambda *_a, **_k: ["gpt-5.6-sol"])
+ monkeypatch.setattr("hermes_cli.models._get_model_config_dict",
+ lambda: {"provider": "azure-foundry", "auth_mode": "entra_id", "base_url": base_url})
+ monkeypatch.delenv("AZURE_FOUNDRY_API_KEY", raising=False)
+ monkeypatch.delenv("AZURE_FOUNDRY_BASE_URL", raising=False)
+ monkeypatch.setattr("hermes_cli.runtime_provider_backends._azure_entra_credentials",
+ lambda *_a, **_k: pytest.fail("listing must not mint an Entra token"))
+
+ rows = list_authenticated_providers(current_provider="", max_models=50)
+ assert ("azure-foundry" in [r["slug"] for r in rows]) is listed
+ assert ("azure-foundry" in _collect_authed_provider_slugs({}, {}, [])) is listed
diff --git a/website/docs/guides/azure-foundry.md b/website/docs/guides/azure-foundry.md
index 9ca8121f294..a137c79b5db 100644
--- a/website/docs/guides/azure-foundry.md
+++ b/website/docs/guides/azure-foundry.md
@@ -278,6 +278,7 @@ What Hermes can do:
- Azure OpenAI v1 endpoints (`<resource>.openai.azure.com/openai/v1`) expose `GET /models` with the resource's **available** model catalog. Hermes uses this list to prefill the setup wizard's model picker **and** the in-session `/model azure-foundry` picker (CLI, TUI, Desktop, gateway), so you can switch deployments without re-running `hermes setup`.
- Microsoft Foundry `/anthropic` routes: detected via URL path, model name entered manually (no `/models` there — the `/model` picker shows only the current selection and any `providers.azure-foundry.models` you declare).
- Private / firewalled endpoints: manual entry with a friendly "couldn't probe" message.
+- Entra ID (`model.auth_mode: entra_id`, no `AZURE_FOUNDRY_API_KEY`): the `/model` picker lists the provider as soon as `model.base_url` (or `AZURE_FOUNDRY_BASE_URL`) is set — no token is minted just to show the row.
You can always type a deployment name directly — Hermes does not validate against the returned list.