Skip to content

fix: resolve OPENROUTER_API_KEY before OPENAI_API_KEY in all code paths#295

Merged
teknium1 merged 1 commit intoNousResearch:mainfrom
0xbyt4:fix/openrouter-key-priority
Mar 3, 2026
Merged

fix: resolve OPENROUTER_API_KEY before OPENAI_API_KEY in all code paths#295
teknium1 merged 1 commit intoNousResearch:mainfrom
0xbyt4:fix/openrouter-key-priority

Conversation

@0xbyt4
Copy link
Copy Markdown
Contributor

@0xbyt4 0xbyt4 commented Mar 2, 2026

Summary

  • When both OPENROUTER_API_KEY and OPENAI_API_KEY are set (e.g. OPENAI_API_KEY exported in .bashrc), the wrong key was sent to OpenRouter causing authentication failures.
  • Fixed key resolution order in both cli.py and hermes_cli/runtime_provider.py to check OPENROUTER_API_KEY first.
  • Added 2 regression tests verifying correct priority and fallback behavior.

Fixes #289

Test plan

  • test_openrouter_key_takes_priority_over_openai_key -- both keys set, OpenRouter key wins
  • test_openai_key_used_when_no_openrouter_key -- fallback still works when only OPENAI_API_KEY is set
  • All existing provider resolution tests pass (7/7)
When both OPENROUTER_API_KEY and OPENAI_API_KEY are set (e.g. OPENAI_API_KEY
in .bashrc), the wrong key was sent to OpenRouter causing auth failures.

Fixed key resolution order in cli.py and runtime_provider.py.

Fixes NousResearch#289
@0xbyt4 0xbyt4 changed the title fix: prioritize OPENROUTER_API_KEY over OPENAI_API_KEY Mar 2, 2026
@teknium1 teknium1 merged commit 221e422 into NousResearch:main Mar 3, 2026
@teknium1
Copy link
Copy Markdown
Contributor

teknium1 commented Mar 3, 2026

Merged in 221e422. This was the right fix — covers both cli.py and runtime_provider.py (PR #290 only caught cli.py). Regression tests are a nice touch. Thanks for the contribution!

teknium1 added a commit that referenced this pull request Mar 7, 2026
…iority

Authored by manuelschipper. Adds GLM-4.7 and GLM-5 context lengths (202752)
to model_metadata.py. The key priority fix (prefer OPENAI_API_KEY for
non-OpenRouter endpoints) was already applied in PR #295; merged the Z.ai
mention into the comment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants