fix: fail fast when explicit provider has no API key instead of silent OpenRouter fallback#2272
Closed
StefanIsMe wants to merge 1 commit intoNousResearch:mainfrom
Closed
Conversation
…t OpenRouter fallback When provider: minimax (or any non-OpenRouter provider) is set in config.yaml but the corresponding API key environment variable is not set, Hermes was silently falling back to OpenRouter. This produces confusing 404 errors since OpenRouter routes the model name to a different endpoint than the user intended. The fix adds a fail-fast check in two locations: 1. run_agent.py AIAgent.__init__: after resolve_provider_client() returns None, raise RuntimeError with the exact env var to set (e.g. MINIMAX_API_KEY) and the command to switch providers. 2. auxiliary_client.py call_llm(): same fail-fast for the same condition. auto/custom/openrouter providers are exempted — their OpenRouter fallback behavior is preserved since those are auto-detection scenarios.
teknium1
pushed a commit
that referenced
this pull request
Mar 22, 2026
…t OpenRouter fallback When a non-OpenRouter provider (e.g. minimax, anthropic) is set in config.yaml but its API key is missing, Hermes silently fell back to OpenRouter, causing confusing 404 errors. Now checks if the user explicitly configured a provider before falling back. Explicit providers raise RuntimeError with a clear message naming the missing env var. Auto/openrouter/custom providers still fall through to OpenRouter as before. Three code paths fixed: - run_agent.py AIAgent.__init__ — main client initialization - auxiliary_client.py call_llm — sync auxiliary calls - auxiliary_client.py call_llm_streaming — async auxiliary calls Based on PR #2272 by @StefanIsMe. Applied manually to fix a pconfig NameError in the original and extend to call_llm_streaming.
teknium1
added a commit
that referenced
this pull request
Mar 22, 2026
…t OpenRouter fallback (#2445) When a non-OpenRouter provider (e.g. minimax, anthropic) is set in config.yaml but its API key is missing, Hermes silently fell back to OpenRouter, causing confusing 404 errors. Now checks if the user explicitly configured a provider before falling back. Explicit providers raise RuntimeError with a clear message naming the missing env var. Auto/openrouter/custom providers still fall through to OpenRouter as before. Three code paths fixed: - run_agent.py AIAgent.__init__ — main client initialization - auxiliary_client.py call_llm — sync auxiliary calls - auxiliary_client.py call_llm_streaming — async auxiliary calls Based on PR #2272 by @StefanIsMe. Applied manually to fix a pconfig NameError in the original and extend to call_llm_streaming. Co-authored-by: StefanIsMe <StefanIsMe@users.noreply.github.com>
Contributor
|
Merged via PR #2445. Your fix was applied manually onto current main with two improvements:
Your authorship is preserved on the commit. Thanks @StefanIsMe! |
outsourc-e
pushed a commit
to outsourc-e/hermes-agent
that referenced
this pull request
Mar 26, 2026
…t OpenRouter fallback (NousResearch#2445) When a non-OpenRouter provider (e.g. minimax, anthropic) is set in config.yaml but its API key is missing, Hermes silently fell back to OpenRouter, causing confusing 404 errors. Now checks if the user explicitly configured a provider before falling back. Explicit providers raise RuntimeError with a clear message naming the missing env var. Auto/openrouter/custom providers still fall through to OpenRouter as before. Three code paths fixed: - run_agent.py AIAgent.__init__ — main client initialization - auxiliary_client.py call_llm — sync auxiliary calls - auxiliary_client.py call_llm_streaming — async auxiliary calls Based on PR NousResearch#2272 by @StefanIsMe. Applied manually to fix a pconfig NameError in the original and extend to call_llm_streaming. Co-authored-by: StefanIsMe <StefanIsMe@users.noreply.github.com>
aashizpoudel
pushed a commit
to aashizpoudel/hermes-agent
that referenced
this pull request
Mar 30, 2026
…t OpenRouter fallback (NousResearch#2445) When a non-OpenRouter provider (e.g. minimax, anthropic) is set in config.yaml but its API key is missing, Hermes silently fell back to OpenRouter, causing confusing 404 errors. Now checks if the user explicitly configured a provider before falling back. Explicit providers raise RuntimeError with a clear message naming the missing env var. Auto/openrouter/custom providers still fall through to OpenRouter as before. Three code paths fixed: - run_agent.py AIAgent.__init__ — main client initialization - auxiliary_client.py call_llm — sync auxiliary calls - auxiliary_client.py call_llm_streaming — async auxiliary calls Based on PR NousResearch#2272 by @StefanIsMe. Applied manually to fix a pconfig NameError in the original and extend to call_llm_streaming. Co-authored-by: StefanIsMe <StefanIsMe@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When
provider: minimax(or any non-OpenRouter provider) is set inconfig.yamlbut the corresponding API key environment variable (MINIMAX_API_KEY) is not set, Hermes silently falls back to OpenRouter.This causes a confusing 404 error because:
Root Cause
Two code paths silently fell back to OpenRouter when a provider had no credentials:
1.
run_agent.pyAIAgent.init (lines 734-744):2.
auxiliary_client.pycall_llm(lines 1429-1435):Fix
In both locations, before falling back to OpenRouter, check if the user explicitly configured a non-OpenRouter provider. If so, raise RuntimeError with a clear message:
For
auto/custom/openrouterproviders, the OpenRouter fallback behavior is preserved — appropriate for auto-detection scenarios where the user hasn't pinned a specific provider.Testing
Logic verified:
'minimax'with no key → raises error telling user to setMINIMAX_API_KEY'anthropic'with no key → raises error telling user to setANTHROPIC_API_KEY'auto'/'openrouter'/'custom'→ falls through to OpenRouter (unchanged)