fix(providers): honour config.yaml api_key for anthropic provider - #7581
Open
FrankSen wants to merge 1 commit into
Open
fix(providers): honour config.yaml api_key for anthropic provider#7581FrankSen wants to merge 1 commit into
FrankSen wants to merge 1 commit into
Conversation
The anthropic provider code path in `resolve_runtime_provider()` only checked env vars (ANTHROPIC_TOKEN, ANTHROPIC_API_KEY) and credential files for API key resolution, completely ignoring `model.api_key` from config.yaml. This is inconsistent with all other providers (openrouter, custom, minimax, etc.) which read config.yaml api_key as a candidate. Users who configure `provider: anthropic` with `api_key` in config.yaml (e.g. pointing to a self-hosted proxy) were forced to duplicate the key in env vars, which is confusing and unnecessary. This change adds config.yaml `model.api_key` (and `model.api` alias) as a candidate source in both the main anthropic resolution path and the explicit override path, consistent with how other providers handle it. Priority order is now: 1. Explicit API key (CLI flag) 2. config.yaml model.api_key / model.api 3. ANTHROPIC_TOKEN env var 4. CLAUDE_CODE_OAUTH_TOKEN env var 5. Claude Code credential files 6. ANTHROPIC_API_KEY env var Co-Authored-By: Franksen <youngsenman@163.com>
Author
|
Friendly ping — any feedback on this fix? Happy to adjust if needed. |
Collaborator
teknium1
reviewed
Jul 12, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for identifying the missing Anthropic configuration path. The underlying non-Azure gap still exists on current main: hermes_cli/runtime_provider.py:1901-1908 calls resolve_anthropic_token() without considering model.api_key.
Problems
- The resolver was substantially refactored after this PR. The current explicit path is
hermes_cli/runtime_provider.py:1367-1392and the normal native path is:1849-1916, so this patch needs a focused port rather than a direct cherry-pick. - The new tests cover only the normal resolver. They do not exercise the explicit branch changed by the PR, which is entered only with an explicit runtime argument (
hermes_cli/runtime_provider.py:1362-1365,:1658-1666). - Current configuration/docs define
model.api_keyas custom-endpoint-only (hermes_cli/config.py:4555-4559;website/docs/user-guide/features/credential-pools.md:188). Extending it to native Anthropic needs that contract reconciled.
Suggested changes
- Port both branches and add one explicit-base-url regression with only
model.api_keyconfigured. - Update the configuration/docs contract if native Anthropic inline keys are intentional.
Automated hermes-sweeper review.
| assert resolved.get("credential_pool") is None | ||
|
|
||
|
|
||
| def test_resolve_runtime_provider_anthropic_respects_config_api_key(monkeypatch): |
Contributor
There was a problem hiding this comment.
This covers the normal resolver only. Please add a regression for the _resolve_explicit_runtime path as well: pass explicit_base_url with no explicit_api_key, provide model.api_key, and assert it wins without calling resolve_anthropic_token.
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.
Summary
Fixes #7579
model.api_key/model.apifromconfig.yamlas a candidate source for the anthropic provider, consistent with how all other providers (openrouter, custom, minimax, etc.) handle itresolve_runtime_provider) and the explicit override path (_resolve_explicit_runtime)Priority order after fix
--api-keyflag)config.yamlmodel.api_key/model.apiANTHROPIC_TOKENenv varCLAUDE_CODE_OAUTH_TOKENenv varANTHROPIC_API_KEYenv varTest plan
pytest tests/hermes_cli/test_runtime_provider_resolution.py)hermes chatworks with onlyconfig.yamlapi_key set (no env vars)