diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py index 163ad007..9589edad 100644 --- a/agent/auxiliary_client.py +++ b/agent/auxiliary_client.py @@ -1451,8 +1451,18 @@ def call_llm( api_key=resolved_api_key, ) if client is None: - # Fallback: try openrouter - if resolved_provider != "openrouter" and not resolved_base_url: + # When the user explicitly chose a non-OpenRouter provider but no + # credentials were found, fail fast instead of silently routing + # through OpenRouter (which causes confusing 404s). + _explicit = (resolved_provider or "").strip().lower() + if _explicit and _explicit not in ("auto", "openrouter", "custom"): + raise RuntimeError( + f"Provider '{_explicit}' is set in config.yaml but no API key " + f"was found. Set the {_explicit.upper()}_API_KEY environment " + f"variable, or switch to a different provider with `hermes model`." + ) + # For auto/custom, fall back to OpenRouter + if not resolved_base_url: logger.warning("Provider %s unavailable, falling back to openrouter", resolved_provider) client, final_model = _get_cached_client( @@ -1534,7 +1544,14 @@ async def async_call_llm( api_key=resolved_api_key, ) if client is None: - if resolved_provider != "openrouter" and not resolved_base_url: + _explicit = (resolved_provider or "").strip().lower() + if _explicit and _explicit not in ("auto", "openrouter", "custom"): + raise RuntimeError( + f"Provider '{_explicit}' is set in config.yaml but no API key " + f"was found. Set the {_explicit.upper()}_API_KEY environment " + f"variable, or switch to a different provider with `hermes model`." + ) + if not resolved_base_url: logger.warning("Provider %s unavailable, falling back to openrouter", resolved_provider) client, final_model = _get_cached_client( diff --git a/run_agent.py b/run_agent.py index 1074bba3..29df5373 100644 --- a/run_agent.py +++ b/run_agent.py @@ -736,6 +736,16 @@ class AIAgent: if hasattr(_routed_client, '_default_headers') and _routed_client._default_headers: client_kwargs["default_headers"] = dict(_routed_client._default_headers) else: + # When the user explicitly chose a non-OpenRouter provider + # but no credentials were found, fail fast with a clear + # message instead of silently routing through OpenRouter. + _explicit = (self.provider or "").strip().lower() + if _explicit and _explicit not in ("auto", "openrouter", "custom"): + raise RuntimeError( + f"Provider '{_explicit}' is set in config.yaml but no API key " + f"was found. Set the {_explicit.upper()}_API_KEY environment " + f"variable, or switch to a different provider with `hermes model`." + ) # Final fallback: try raw OpenRouter key client_kwargs = { "api_key": os.getenv("OPENROUTER_API_KEY", ""),