Skip to content

[Bug]: alibaba provider error message shows wrong env var name (ALIBABA_API_KEY instead of DASHSCOPE_API_KEY) #9506

@Nami4D

Description

@Nami4D

Bug Description

When the alibaba provider is set in config.yaml but no API key is found, the error message instructs the user to set ALIBABA_API_KEY. However, the actual environment variable that Hermes reads is DASHSCOPE_API_KEY.

This causes confusion because setting ALIBABA_API_KEY has no effect -- the agent continues to fail with the same error.

Steps to Reproduce

  1. Set provider: alibaba in ~/.hermes/config.yaml
  2. Set only ALIBABA_API_KEY (not DASHSCOPE_API_KEY) in ~/.hermes/.env
  3. Start Hermes CLI or gateway
  4. Error: RuntimeError: Provider 'alibaba' is set in config.yaml but no API key was found. Set the ALIBABA_API_KEY environment variable, or switch to a different provider with hermes model.

Expected Behavior

Either:

  1. The error message should say DASHSCOPE_API_KEY (the actual env var name), OR
  2. Better: Accept both DASHSCOPE_API_KEY and ALIBABA_API_KEY for the alibaba provider, for backward compatibility and usability

Actual Behavior

even if ALIBABA_API_KEY is set, Hermes reacts like:

Sorry, I encountered an error (RuntimeError).
Provider 'alibaba' is set in config.yaml but no API key was found. Set the ALIBABA_API_KEY environment variable, or switch to a different provider with hermes model.
Try again or use /reset to start a fresh session.

Affected Component

Gateway (Telegram/Discord/Slack/WhatsApp), Setup / Installation

Messaging Platform (if gateway-related)

No response

Debug Report

Report       https://paste.rs/0rGof
agent.log    https://paste.rs/YgcC5
gateway.log  https://paste.rs/tfp2P

Operating System

macOS 26.4

Python Version

3.11.15

Hermes Version

0.8.0

Additional Logs / Traceback (optional)

Root Cause Analysis (optional)

In run_agent.py line 933-935:

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`."
)

This dynamically constructs ALIBABA_API_KEY from provider="alibaba", but the actual credential resolution in hermes_cli/auth.py and hermes_cli/config.py expects DASHSCOPE_API_KEY.

Proposed Fix (optional)

Option A: Fix error message only

Add a provider-to-env-var mapping for accurate error messages:

_PROVIDER_ENV_VAR_MAP = {
    "alibaba": "DASHSCOPE_API_KEY",
}
env_var_name = _PROVIDER_ENV_VAR_MAP.get(_explicit, f"{_explicit.upper()}_API_KEY")

Option B: Accept both env vars (recommended for UX)

In the credential resolution code, fall back to ALIBABA_API_KEY if DASHSCOPE_API_KEY is not set:

alibaba_key = os.getenv("DASHSCOPE_API_KEY") or os.getenv("ALIBABA_API_KEY")

And fix the error message to mention both:

"Set the DASHSCOPE_API_KEY (or ALIBABA_API_KEY) environment variable..."

### Are you willing to submit a PR for this?

- [x] I'd like to fix this myself and submit a PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions