From bdac541d1ee20aa8545d908a01e18c65b8e319de Mon Sep 17 00:00:00 2001 From: teknium1 Date: Tue, 17 Feb 2026 03:11:17 -0800 Subject: [PATCH] Rename OPENAI_API_KEY to HERMES_OPENAI_API_KEY in configuration and codebase for clarity and to avoid conflicts. Update related documentation and error messages to reflect the new key name, ensuring backward compatibility with existing setups. --- .env.example | 9 +++++---- gateway/run.py | 4 ++-- hermes_cli/config.py | 12 ++++++------ tools/transcription_tools.py | 9 ++++++--- tools/tts_tool.py | 8 ++++---- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/.env.example b/.env.example index 689517d3d..e95866f44 100644 --- a/.env.example +++ b/.env.example @@ -143,12 +143,13 @@ BROWSER_INACTIVITY_TIMEOUT=120 # Contains full conversation history in trajectory format for debugging/replay # ============================================================================= -# VOICE TRANSCRIPTION (Speech-to-Text) +# VOICE TRANSCRIPTION & OPENAI TTS # ============================================================================= -# Required for automatic voice message transcription on messaging platforms. -# Uses OpenAI's Whisper API directly (not via OpenRouter). +# Required for voice message transcription (Whisper) and OpenAI TTS voices. +# Uses OpenAI's API directly (not via OpenRouter). +# Named HERMES_OPENAI_API_KEY to avoid interference with OpenRouter. # Get at: https://platform.openai.com/api-keys -OPENAI_API_KEY= +HERMES_OPENAI_API_KEY= # ============================================================================= # SLACK INTEGRATION diff --git a/gateway/run.py b/gateway/run.py index 9b03de5ec..e7262d8ee 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -700,10 +700,10 @@ class GatewayRunner: ) else: error = result.get("error", "unknown error") - if "OPENAI_API_KEY" in error: + if "OPENAI_API_KEY" in error or "HERMES_OPENAI_API_KEY" in error: enriched_parts.append( "[The user sent a voice message but I can't listen " - "to it right now~ OPENAI_API_KEY isn't set up yet " + "to it right now~ HERMES_OPENAI_API_KEY isn't set up yet " "(';w;') Let them know!]" ) else: diff --git a/hermes_cli/config.py b/hermes_cli/config.py index 4251cb22d..4dc380f23 100644 --- a/hermes_cli/config.py +++ b/hermes_cli/config.py @@ -201,11 +201,11 @@ OPTIONAL_ENV_VARS = { "password": False, "advanced": True, # Hide from standard migrate flow }, - "OPENAI_API_KEY": { - "description": "OpenAI API key (voice transcription + custom endpoint)", - "prompt": "OpenAI API Key", + "HERMES_OPENAI_API_KEY": { + "description": "OpenAI API key for voice transcription (Whisper) and OpenAI TTS", + "prompt": "OpenAI API Key (for Whisper STT + TTS)", "url": "https://platform.openai.com/api-keys", - "tools": ["voice_transcription"], + "tools": ["voice_transcription", "openai_tts"], "password": True, }, "SLACK_BOT_TOKEN": { @@ -603,7 +603,7 @@ def show_config(): keys = [ ("OPENROUTER_API_KEY", "OpenRouter"), ("ANTHROPIC_API_KEY", "Anthropic"), - ("OPENAI_API_KEY", "OpenAI"), + ("HERMES_OPENAI_API_KEY", "OpenAI (STT/TTS)"), ("FIRECRAWL_API_KEY", "Firecrawl"), ("BROWSERBASE_API_KEY", "Browserbase"), ("FAL_KEY", "FAL"), @@ -703,7 +703,7 @@ def set_config_value(key: str, value: str): """Set a configuration value.""" # Check if it's an API key (goes to .env) api_keys = [ - 'OPENROUTER_API_KEY', 'ANTHROPIC_API_KEY', 'OPENAI_API_KEY', + 'OPENROUTER_API_KEY', 'ANTHROPIC_API_KEY', 'HERMES_OPENAI_API_KEY', 'FIRECRAWL_API_KEY', 'BROWSERBASE_API_KEY', 'BROWSERBASE_PROJECT_ID', 'FAL_KEY', 'TELEGRAM_BOT_TOKEN', 'DISCORD_BOT_TOKEN', 'TERMINAL_SSH_HOST', 'TERMINAL_SSH_USER', 'TERMINAL_SSH_KEY', diff --git a/tools/transcription_tools.py b/tools/transcription_tools.py index 18a000ef5..01992cde9 100644 --- a/tools/transcription_tools.py +++ b/tools/transcription_tools.py @@ -47,12 +47,15 @@ def transcribe_audio(file_path: str, model: Optional[str] = None) -> dict: - "transcript" (str): The transcribed text (empty on failure) - "error" (str, optional): Error message if success is False """ - api_key = os.getenv("OPENAI_API_KEY") + # Use HERMES_OPENAI_API_KEY to avoid interference with the OpenAI SDK's + # auto-detection of OPENAI_API_KEY (which would break OpenRouter calls). + # Falls back to OPENAI_API_KEY for backward compatibility. + api_key = os.getenv("HERMES_OPENAI_API_KEY") or os.getenv("OPENAI_API_KEY") if not api_key: return { "success": False, "transcript": "", - "error": "OPENAI_API_KEY not set", + "error": "HERMES_OPENAI_API_KEY not set", } audio_path = Path(file_path) @@ -100,4 +103,4 @@ def transcribe_audio(file_path: str, model: Optional[str] = None) -> dict: def check_stt_requirements() -> bool: """Check if OpenAI API key is available for speech-to-text.""" - return bool(os.getenv("OPENAI_API_KEY")) + return bool(os.getenv("HERMES_OPENAI_API_KEY") or os.getenv("OPENAI_API_KEY")) diff --git a/tools/tts_tool.py b/tools/tts_tool.py index 3d1d3d2fb..8e23a9646 100644 --- a/tools/tts_tool.py +++ b/tools/tts_tool.py @@ -207,9 +207,9 @@ def _generate_openai_tts(text: str, output_path: str, tts_config: Dict[str, Any] Returns: Path to the saved audio file. """ - api_key = os.getenv("OPENAI_API_KEY", "") + api_key = os.getenv("HERMES_OPENAI_API_KEY") or os.getenv("OPENAI_API_KEY", "") if not api_key: - raise ValueError("OPENAI_API_KEY not set. Get one at https://platform.openai.com/api-keys") + raise ValueError("HERMES_OPENAI_API_KEY not set. Get one at https://platform.openai.com/api-keys") oai_config = tts_config.get("openai", {}) model = oai_config.get("model", DEFAULT_OPENAI_MODEL) @@ -389,7 +389,7 @@ def check_tts_requirements() -> bool: return True if _HAS_ELEVENLABS and os.getenv("ELEVENLABS_API_KEY"): return True - if _HAS_OPENAI and os.getenv("OPENAI_API_KEY"): + if _HAS_OPENAI and (os.getenv("HERMES_OPENAI_API_KEY") or os.getenv("OPENAI_API_KEY")): return True return False @@ -406,7 +406,7 @@ if __name__ == "__main__": print(f" ElevenLabs: {'✅ installed' if _HAS_ELEVENLABS else '❌ not installed (pip install elevenlabs)'}") print(f" API Key: {'✅ set' if os.getenv('ELEVENLABS_API_KEY') else '❌ not set'}") print(f" OpenAI: {'✅ installed' if _HAS_OPENAI else '❌ not installed'}") - print(f" API Key: {'✅ set' if os.getenv('OPENAI_API_KEY') else '❌ not set'}") + print(f" API Key: {'✅ set' if (os.getenv('HERMES_OPENAI_API_KEY') or os.getenv('OPENAI_API_KEY')) else '❌ not set'}") print(f" ffmpeg: {'✅ found' if _has_ffmpeg() else '❌ not found (needed for Telegram Opus)'}") print(f"\n Output dir: {DEFAULT_OUTPUT_DIR}")