Skip to content

fix: fall through to OPENROUTER_API_KEY env var when credential pool is exhausted (#23452)#23903

Closed
LiWeny16 wants to merge 1 commit into
NousResearch:mainfrom
LiWeny16:fix/23452-try-openrouter-env-fallback
Closed

fix: fall through to OPENROUTER_API_KEY env var when credential pool is exhausted (#23452)#23903
LiWeny16 wants to merge 1 commit into
NousResearch:mainfrom
LiWeny16:fix/23452-try-openrouter-env-fallback

Conversation

@LiWeny16

Copy link
Copy Markdown

Summary

When using the credential pool for OpenRouter, if the pool exists but contains no usable keys (all previously tried entries failed), _try_openrouter() currently exits early with None, None without falling through to the OPENROUTER_API_KEY environment variable.

This fix ensures that when a credential pool is present but has no usable entry, the code continues to check the OPENROUTER_API_KEY env var as a fallback.

Root cause

The condition if pool_present: was true even when no valid entry was found, causing an early return before reaching the env var fallback logic.\n\n## Fix
Changed the early-return guard to check both pool_present AND entry is not None, allowing the fallthrough when the pool is empty of usable keys.

Fixes #23452

@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent loop, run_agent.py, prompt builder provider/openrouter OpenRouter aggregator P2 Medium — degraded but workaround exists duplicate This issue or pull request already exists labels May 11, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #23495 — same OpenRouter credential pool exhaustion fallthrough fix. This PR bundles 3 unrelated fixes (identical diff to #23905 and #23904) from a stacked branch.

…ool is exhausted

When the credential pool exists but contains no usable entry (all previously
tried keys failed), _try_openrouter() was returning (None, None) instead of
falling through to the OPENROUTER_API_KEY env var.

Changed the guard to check both pool_present AND entry is not None, and
restructured so that when the pool has no usable key the code continues
to the env-var fallback path instead of exiting early.

Fixes: NousResearch#23452
@LiWeny16 LiWeny16 force-pushed the fix/23452-try-openrouter-env-fallback branch from 305feb8 to 19905e6 Compare May 11, 2026 17:44
@LiWeny16

Copy link
Copy Markdown
Author

Thanks for the review. I've rebuilt the branches from latest main — each PR now contains only its single targeted fix instead of stacked commits.

@LiWeny16 LiWeny16 closed this May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists provider/openrouter OpenRouter aggregator type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: _try_openrouter() returns (None,None) when credential pool is exhausted, blocking env var fallback

2 participants