Skip to content

fix: prioritize OPENROUTER_API_KEY over OPENAI_API_KEY#290

Closed
ygd58 wants to merge 1 commit into
NousResearch:mainfrom
ygd58:fix/openrouter-api-key-priority
Closed

fix: prioritize OPENROUTER_API_KEY over OPENAI_API_KEY#290
ygd58 wants to merge 1 commit into
NousResearch:mainfrom
ygd58:fix/openrouter-api-key-priority

Conversation

@ygd58

@ygd58 ygd58 commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

Problem

When OPENAI_API_KEY is set in the environment (e.g. .bashrc),
it was being used instead of OPENROUTER_API_KEY when making
requests to OpenRouter, causing authentication failures.

Fix

Changed the key resolution order in cli.py line 850:

Before:

self.api_key = api_key or os.getenv("OPENAI_API_KEY") or os.getenv("OPENROUTER_API_KEY")

After:

self.api_key = api_key or os.getenv("OPENROUTER_API_KEY") or os.getenv("OPENAI_API_KEY")

Fixes #289

When OPENAI_API_KEY is set in environment, it was being used instead
of OPENROUTER_API_KEY causing auth failures with OpenRouter.

Fixes NousResearch#289
@teknium1

teknium1 commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

Closing in favor of #295 which was merged. This PR only fixed the key order in cli.py, but the same bug also existed in hermes_cli/runtime_provider.py. PR #295 fixes both code paths and adds regression tests. Thanks for looking into this though!

@teknium1 teknium1 closed this Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hermes prioritizes OPENAI_API_KEY

2 participants