fix(auxiliary): inherit model.api_key for custom endpoint when per-task key is empty (#9318) - #26
Open
hashbender wants to merge 1 commit into
Open
fix(auxiliary): inherit model.api_key for custom endpoint when per-task key is empty (#9318)#26hashbender wants to merge 1 commit into
hashbender wants to merge 1 commit into
Conversation
|
Review Complete Risk: 🟢 Low (18/100) — no findings · 148 LOC across 2 files Minor refactor in auxiliary_client.py adding _read_main_api_key() helper with consistent error-handling pattern. No high-confidence issues found. Files Reviewed (2 files) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When an auxiliary task is configured with
provider: custom, an explicitbase_url, and an emptyapi_key, theresolve_provider_client()custom provider branch falls through to the hardcoded"no-key-required"placeholder without ever consultingmodel.api_keyfrom config.yaml. This causes 401 auth errors for users on self-hosted gateways who share the same endpoint and credentials for both their main model and auxiliary tasks.Root Cause
The
custom_keyfallback chain inresolve_provider_client()(theprovider == "custom"branch withexplicit_base_url) only checks:explicit_api_key→ None (empty string stripped)os.getenv("OPENAI_API_KEY")→ often unset or wrong key"no-key-required"← wins, causing 401The main
model.api_keyfrom config.yaml is never consulted, unlike the_resolve_auto()path which already reads_RUNTIME_MAIN_API_KEY.Fix
Added
_read_main_api_key()— mirrors the existing_read_main_model()/_read_main_provider()pattern:_RUNTIME_MAIN_API_KEY(runtime override set byset_runtime_main())config.yaml→model.api_key""if neither is setInserted into the
custom_keyfallback chain before"no-key-required":This covers both the explicit
provider: custompath and (transitively) theprovider: autopath when auto-detection routes auxiliary tasks to the main custom endpoint.Tests
Added
TestCustomEndpointApiKeyInheritancewith 4 tests:test_inherits_main_api_key_when_aux_key_emptytest_runtime_override_key_is_used_RUNTIME_MAIN_API_KEYoverride takes precedence over configtest_explicit_api_key_takes_precedenceapi_keyparam wins over configtest_local_server_falls_to_no_key_required"no-key-required"for local serversRED phase verified: both RED→GREEN tests fail on
upstream/mainwithAssertionError: 'no-key-required' != 'sk-...'.Full suite: 278 passed, 0 failed in
tests/agent/test_auxiliary_client.py.Related PRs
provider: custom+ custom-gateway + empty-key scenario."custom". Does not apply whenprovider: customis explicitly set.This fix is complementary to both — it handles the case where a user intentionally uses
provider: customwith a self-hosted gateway and expects credential inheritance from the main model config.Closes NousResearch#9318.
Auto-published by Moonsong via Path B automated pipeline.
Mirror-of: NousResearch#55911
NousResearch#55911