mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
The error message for missing provider API keys dynamically built the env var name as PROVIDER_API_KEY (e.g. ALIBABA_API_KEY), but some providers use different names (alibaba uses DASHSCOPE_API_KEY). Users following the error message set the wrong variable. Fix: look up the actual env var from PROVIDER_REGISTRY before building the error. Falls back to the dynamic name if the registry lookup fails. Closes #9506
This commit is contained in:
parent
0cb8c51fa5
commit
2918328009
1 changed files with 12 additions and 1 deletions
13
run_agent.py
13
run_agent.py
|
|
@ -1003,9 +1003,20 @@ class AIAgent:
|
|||
# message instead of silently routing through OpenRouter.
|
||||
_explicit = (self.provider or "").strip().lower()
|
||||
if _explicit and _explicit not in ("auto", "openrouter", "custom"):
|
||||
# Look up the actual env var name from the provider
|
||||
# config — some providers use non-standard names
|
||||
# (e.g. alibaba → DASHSCOPE_API_KEY, not ALIBABA_API_KEY).
|
||||
_env_hint = f"{_explicit.upper()}_API_KEY"
|
||||
try:
|
||||
from hermes_cli.auth import PROVIDER_REGISTRY
|
||||
_pcfg = PROVIDER_REGISTRY.get(_explicit)
|
||||
if _pcfg and _pcfg.api_key_env_vars:
|
||||
_env_hint = _pcfg.api_key_env_vars[0]
|
||||
except Exception:
|
||||
pass
|
||||
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"was found. Set the {_env_hint} environment "
|
||||
f"variable, or switch to a different provider with `hermes model`."
|
||||
)
|
||||
# Final fallback: try raw OpenRouter key
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue