Skip to content

fix(tts): use get_env_value for API key resolution from ~/.hermes/.env#17262

Closed
zhanggttry wants to merge 3 commits into
NousResearch:mainfrom
zhanggttry:fix/tts-env-value
Closed

fix(tts): use get_env_value for API key resolution from ~/.hermes/.env#17262
zhanggttry wants to merge 3 commits into
NousResearch:mainfrom
zhanggttry:fix/tts-env-value

Conversation

@zhanggttry

Copy link
Copy Markdown
Contributor

Summary

Fixes #17140 — TTS provider tools fail to read API keys from ~/.hermes/.env.

Problem

TTS provider tools (elevenlabs, minimax, mistral, xai, gemini) use os.getenv("X_API_KEY") directly, which does not read values stored in ~/.hermes/.env. The hermes config system uses get_env_value() from hermes_cli.config which reads .env directly, but the TTS tools bypass this, causing "API key not set" errors even when keys are correctly configured.

Solution

Replace all os.getenv() calls for API keys and base URLs in tools/tts_tool.py with _get_env_value() (aliased from hermes_cli.config.get_env_value), following the same pattern already used by hermes_cli/auth.py and hermes_cli/gateway.py.

Changes

Added _get_env_value import with fallback (lines 53-59):

try:
    from hermes_cli.config import get_env_value as _get_env_value
except Exception:
    def _get_env_value(key, default=None):
        return os.getenv(key, default)

Replaced all os.getenv() calls for env vars in tts_tool.py:

Line Before After
244 os.getenv("ELEVENLABS_API_KEY", "") _get_env_value("ELEVENLABS_API_KEY") or ""
338 os.getenv("XAI_API_KEY", "").strip() (_get_env_value("XAI_API_KEY") or "").strip()
349 os.getenv("XAI_BASE_URL") _get_env_value("XAI_BASE_URL")
411 os.getenv("MINIMAX_API_KEY", "") _get_env_value("MINIMAX_API_KEY") or ""
488 os.getenv("MISTRAL_API_KEY", "") _get_env_value("MISTRAL_API_KEY") or ""
583 os.getenv("GEMINI_API_KEY") or os.getenv("GOOGLE_API_KEY") _get_env_value("GEMINI_API_KEY") or _get_env_value("GOOGLE_API_KEY")
594 os.getenv("GEMINI_BASE_URL") _get_env_value("GEMINI_BASE_URL")
990 os.getenv("ELEVENLABS_API_KEY") _get_env_value("ELEVENLABS_API_KEY")
1000 os.getenv("MINIMAX_API_KEY") _get_env_value("MINIMAX_API_KEY")
1002 os.getenv("XAI_API_KEY") _get_env_value("XAI_API_KEY")
1004 os.getenv("GEMINI_API_KEY") or os.getenv("GOOGLE_API_KEY") _get_env_value("GEMINI_API_KEY") or _get_env_value("GOOGLE_API_KEY")
1008 os.getenv("MISTRAL_API_KEY") _get_env_value("MISTRAL_API_KEY")
1110 os.getenv("ELEVENLABS_API_KEY", "") _get_env_value("ELEVENLABS_API_KEY") or ""
1296 os.getenv('ELEVENLABS_API_KEY') _get_env_value('ELEVENLABS_API_KEY')
1302 os.getenv('MINIMAX_API_KEY') _get_env_value('MINIMAX_API_KEY')

Safety

  • Fallback to os.getenv() if hermes_cli.config is unavailable — no behavior change for existing installations
  • get_env_value() checks os.environ first, then .env file — fully backward-compatible
  • No new dependencies, no API surface changes

Testing

  • Python syntax check passes (py_compile)
  • Pattern matches existing usage in hermes_cli/auth.py (line 332) and hermes_cli/gateway.py (lines 2388+)

Closes #17140

TTS provider tools (elevenlabs, xai, minimax, mistral, gemini) used os.getenv()
directly which cannot see keys stored in ~/.hermes/.env. This replaces all
os.getenv() calls with get_env_value() from hermes_cli.config, which properly
reads the .env file.

Closes NousResearch#17140
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists tool/tts Text-to-speech and transcription labels Apr 29, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #17163 — both fix #17140 by replacing os.getenv() with get_env_value() in tts_tool.py.

@zhanggttry

Copy link
Copy Markdown
Contributor Author

Closing as duplicate of #17163 by @briandevans, which includes comprehensive regression tests and passes the supply chain audit. The approach in #17163 is more complete — I will support that PR instead.

Note: The test failures and supply chain audit failure on this PR are pre-existing issues on the main branch (Tests also fail on main: run 25090500778). Our change only touches tools/tts_tool.py and does not introduce any new risks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Medium — degraded but workaround exists tool/tts Text-to-speech and transcription type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: TTS tools fail to read API keys from ~/.hermes/.env — os.getenv() doesn't see dotenv values

2 participants