fix(auxiliary): resolve API key from base_url pattern for custom endpoints - #18378
Closed
kevin-lucifer wants to merge 1 commit into
Closed
fix(auxiliary): resolve API key from base_url pattern for custom endpoints#18378kevin-lucifer wants to merge 1 commit into
kevin-lucifer wants to merge 1 commit into
Conversation
Collaborator
…oints
When auxiliary tasks configure a custom base_url without an explicit
api_key (e.g. auxiliary.vision.base_url with api_key: null), the
resolve_provider_client custom branch would only fall back to
OPENAI_API_KEY, causing 401 errors for providers like Alibaba/DashScope,
DeepSeek, MiniMax, etc.
This fix adds:
- _BASE_URL_TO_PROVIDER: mapping of base_url patterns to provider credentials
- _get_api_key_for_base_url(): lookup chain (credential pool → env var → .env file)
- Integration in resolve_provider_client() custom branch
Resolution order for custom endpoints:
1. Explicit api_key parameter (highest priority)
2. Credential pool lookup based on base_url pattern match
3. Environment variable (provider-specific, e.g. DASHSCOPE_API_KEY)
4. Direct .env file read (bypasses stale/masked gateway env)
5. OPENAI_API_KEY fallback
6. "no-key-required" for local servers
Also handles masked placeholder values ('***') that gateway processes
may have in their environment, by reading directly from .env file.
Fixes scenario where config.yaml has:
auxiliary:
vision:
provider: alibaba
base_url: https://coding.dashscope.aliyuncs.com/v1
api_key: null
The vision task will now correctly resolve DASHSCOPE_API_KEY from
credential pool or environment.
kevin-lucifer
force-pushed
the
fix/auxiliary-base-url-api-key-resolution
branch
from
May 21, 2026 15:52
917cdd0 to
a213400
Compare
Contributor
|
Thanks for the detailed reproduction and credential-resolution coverage. This is an automated hermes-sweeper review; current
Closing as implemented on main. |
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 auxiliary tasks configure a custom
base_urlwithout an explicitapi_key(e.g.auxiliary.vision.base_urlwithapi_key: null), theresolve_provider_clientcustom branch would only fall back toOPENAI_API_KEY, causing 401 errors for providers like Alibaba/DashScope, DeepSeek, MiniMax, Moonshot, Zhipu, SiliconFlow, ModelScope, etc.Example Config That Would Fail
Before this fix,
resolve_provider_client(provider="custom", explicit_base_url="https://coding.dashscope.aliyuncs.com/v1", explicit_api_key=None)would:explicit_api_key→ NoneOPENAI_API_KEY→ not set or wrong key"no-key-required"→ 401 errorSolution
This PR adds:
_BASE_URL_TO_PROVIDER: Static mapping of base_url hostname patterns to (provider_name, env_var_name):dashscope.aliyuncs.com→ alibaba / DASHSCOPE_API_KEYcoding.dashscope.aliyuncs.com→ alibaba / DASHSCOPE_API_KEYapi.moonshot.cn→ moonshot / MOONSHOT_API_KEYapi.deepseek.com→ deepseek / DEEPSEEK_API_KEYapi.minimax.chat→ minimax / MINIMAX_API_KEYapi.zhipuai.cn→ zhipu / ZHIPU_API_KEYapi.siliconflow.cn→ siliconflow / SILICONFLOW_API_KEYapi-inference.modelscope.cn→ modelscope / MODELSCOPE_API_KEY_get_api_key_for_base_url(): Resolution chain that looks up credentials based on base_url pattern:_select_pool_entry).envfile read (bypasses stale/masked gateway env)Integration in
resolve_provider_client(): The custom branch now calls_get_api_key_for_base_url(custom_base)before falling back toOPENAI_API_KEY.Resolution Order for Custom Endpoints
api_keyparameter (highest priority)DASHSCOPE_API_KEY).envfile read (handles masked***values in gateway processes)OPENAI_API_KEYfallback"no-key-required"for local serversHandles Masked Placeholder Values
Gateway processes may have
***masked placeholder values in their environment. The fix skips these and falls back to reading the actual value from.envfile directly.Tests
Added comprehensive tests in
tests/agent/test_auxiliary_base_url_api_key.py:TestBaseUrlToProviderMapping: Validates all provider mappingsTestReadEnvVarFromFile: Tests .env file reading with masked value handlingTestGetApiKeyForBaseUrl: Tests the full resolution chainTestResolveProviderClientCustomBranch: Integration testsTestIntegrationWithAuxiliaryConfig: Simulates the bug scenarioAll 29 tests pass.
Files Changed
agent/auxiliary_client.py: +115 lines (mapping + helper function + integration)tests/agent/test_auxiliary_base_url_api_key.py: +296 lines (new test file)