Skip to content

The agent that grows with you

fix(runtime): api_mode_for_model None keeps the profile's declared api_mode

Tekniumd9e6d8159766
diff --git a/hermes_cli/runtime_provider.py b/hermes_cli/runtime_provider.py
index 14045da9f6a..8bbf1146149 100644
--- a/hermes_cli/runtime_provider.py
+++ b/hermes_cli/runtime_provider.py
@@ -288,13 +288,16 @@ def _profile_runtime_api_mode(provider: str, model_cfg: dict[str, Any], api_key:
and profile.api_mode_for_model(model_name) == "chat_completions"):
return "chat_completions"
return configured_mode
- if not model_name or profile is None:
+ if profile is None:
return "chat_completions"
+ declared = profile.api_mode or "chat_completions" # the hook's None means "keep the static api_mode"
+ if not model_name:
+ return declared
try:
- return profile.api_mode_for_model(model_name, api_key=api_key) or "chat_completions"
- except Exception: # plugin hook (live catalog fetch): degrade to chat_completions, never fail resolution
+ return profile.api_mode_for_model(model_name, api_key=api_key) or declared
+ except Exception: # plugin hook (live catalog fetch): degrade to the declared wire, never fail resolution
logger.debug("%s api_mode_for_model(%s) failed", provider, model_name, exc_info=True)
- return "chat_completions"
+ return declared
def _azure_inferred_api_mode(effective_model: str, api_mode: str) -> str:
diff --git a/tests/hermes_cli/test_runtime_api_mode_profile_default.py b/tests/hermes_cli/test_runtime_api_mode_profile_default.py
new file mode 100644
index 00000000000..e22be961202
--- /dev/null
+++ b/tests/hermes_cli/test_runtime_api_mode_profile_default.py
@@ -0,0 +1,40 @@
+"""``api_mode_for_model`` answering None keeps the profile's declared ``api_mode`` at runtime resolution
+(``providers/base.py`` contract), so a Responses-default provider with a few chat-only exceptions
+never sends its other models through Chat Completions."""
+
+import pytest
+
+
+def responses_default(monkeypatch):
+ import hermes_cli.auth
+ import providers
+ from providers.base import ProviderProfile
+
+ class ResponsesDefault(ProviderProfile):
+ def api_mode_for_model(self, model, *, api_key=None):
+ if model.startswith("broken"):
+ raise RuntimeError("live catalog unavailable")
+ return "chat_completions" if model.startswith("claude") else None
+
+ providers.list_providers() # discovery first, so the fake survives it
+ providers.register_provider(ResponsesDefault(
+ name="respdefault", base_url="https://api.respdefault.test/v1", api_mode="codex_responses",
+ env_vars=("RESPDEFAULT_API_KEY",)))
+ monkeypatch.setenv("RESPDEFAULT_API_KEY", "sk-fake")
+ yield
+ providers._REGISTRY.pop("respdefault", None)
+ providers._SOURCES.pop("respdefault", None)
+ providers._PROVIDER_LIST_CACHE = None
+ hermes_cli.auth.PROVIDER_REGISTRY.pop("respdefault", None)
+
+
[email protected](("model", "api_mode"), [
+ ("gpt-x", "codex_responses"), # hook None -> the declared default
+ ("claude-y", "chat_completions"), # the hook's per-model exception
+ ("broken-z", "codex_responses"), # a raising hook degrades to the declared default
+])
+def test_hook_none_keeps_the_profiles_declared_api_mode(responses_default, model, api_mode):
+ from hermes_cli.runtime_provider import resolve_runtime_provider
+
+ assert resolve_runtime_provider(requested="respdefault", target_model=model)["api_mode"] == api_mode