Skip to content

fix(auxiliary): propagate explicit_api_key to _try_openrouter()#18341

Closed
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/issue-18338-openrouter-explicit-api-key
Closed

fix(auxiliary): propagate explicit_api_key to _try_openrouter()#18341
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/issue-18338-openrouter-explicit-api-key

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

Summary

  • Add explicit_api_key parameter to _try_openrouter() and honor it
  • Update resolve_provider_client() to pass explicit_api_key when calling _try_openrouter()

Root cause

_try_openrouter() had no explicit_api_key parameter, so when
resolve_provider_client() received an explicit_api_key and routed to OpenRouter,
the explicit key was silently ignored and the function fell back to the
OPENROUTER_API_KEY environment variable (or pool entry).

This caused auth failures when auxiliary tasks used runtime credential pool keys
for OpenRouter fallback — the pool key was passed to resolve_provider_client()
but not to _try_openrouter().

Fix

  • Add explicit_api_key: str = None parameter to _try_openrouter()
  • Prioritize explicit_api_key over pool key and env var in the non-pool path
  • Update resolve_provider_client() call site: _try_openrouter(explicit_api_key=explicit_api_key)

Testing

  • All 113 tests in tests/agent/test_auxiliary_client.py pass
  • New regression tests verify:
    • explicit_api_key is passed to OpenAI client when provided
    • Fallback to OPENROUTER_API_KEY still works when explicit_api_key is None

Affected files

  • agent/auxiliary_client.py - _try_openrouter() signature and logic
  • tests/agent/test_auxiliary_client.py - Regression tests

Closes #18338

When resolve_provider_client() passes explicit_api_key for OpenRouter auxiliary
tasks, _try_openrouter() now accepts and honors this parameter instead of
silently ignoring it and falling back to OPENROUTER_API_KEY env var.

Root cause: _try_openrouter() had no explicit_api_key parameter, so even
when callers wanted to pass a runtime credential pool key, it could not be used.

Fix:
- Add explicit_api_key: str = None parameter to _try_openrouter()
- Prioritize explicit_api_key over pool key and env var
- Update resolve_provider_client() call site to pass explicit_api_key

Regression coverage:
- Test that explicit_api_key is passed to OpenAI client when provided
- Test that fallback to OPENROUTER_API_KEY still works when explicit_api_key is None

Closes NousResearch#18338
@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/agent Core agent loop, run_agent.py, prompt builder provider/openrouter OpenRouter aggregator labels May 1, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Fix PR for #18338. Related to #5358 (similar provider fallback routing issue).

@alt-glitch

Copy link
Copy Markdown
Collaborator

Fix PR for #18338.

@liuhao1024 liuhao1024 closed this May 1, 2026
@liuhao1024 liuhao1024 reopened this May 1, 2026
@liuhao1024 liuhao1024 closed this May 1, 2026
@liuhao1024 liuhao1024 reopened this May 1, 2026
@liuhao1024

Copy link
Copy Markdown
Contributor Author

Closing: issue #18338 is already resolved by the automated batch fix PR #17246.

@teknium1

teknium1 commented May 2, 2026

Copy link
Copy Markdown
Contributor

Merged via #18768 — your commit cherry-picked onto current main with authorship preserved (rebase-merge). Resolved one test-file merge conflict (kept both the recently-landed dedup-tool-names tests and your explicit-api-key tests). Thanks!

#18768

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 P1 High — major feature broken, no workaround provider/openrouter OpenRouter aggregator type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: resolve_provider_client ignores explicit_api_key when calling _try_openrouter()

3 participants