Skip to content

fix(anthropic): honor model.api_key from config.yaml - #11713

Closed
konsisumer wants to merge 1 commit into
NousResearch:mainfrom
konsisumer:fix/anthropic-config-api-key-7579
Closed

fix(anthropic): honor model.api_key from config.yaml#11713
konsisumer wants to merge 1 commit into
NousResearch:mainfrom
konsisumer:fix/anthropic-config-api-key-7579

Conversation

@konsisumer

Copy link
Copy Markdown
Contributor

Summary

  • Fixes Anthropic provider ignores config.yaml api_key, requiring duplicate env var configuration #7579: Anthropic provider paths ignored model.api_key in config.yaml, forcing users to duplicate their key as an env var. Inconsistent with every other provider.
  • Both the main anthropic branch (runtime_provider.py L845) and the explicit-override branch (L539) now read model.api_key (and the api alias used elsewhere) before falling back to resolve_anthropic_token().
  • Gated on model.provider == "anthropic" so an unrelated key configured for a different provider can't leak into Anthropic requests — mirrors the existing cfg_base_url guard.

Test plan

  • New unit test: model.api_key is used and resolve_anthropic_token() is not called when config has provider: anthropic + api_key.
  • New unit test: model.api_key is ignored when model.provider is a different provider (no cross-provider key leak).
  • New unit test: --base-url override combined with config.yaml api_key resolves correctly.
  • Full tests/hermes_cli/test_runtime_provider_resolution.py + test_anthropic_oauth_flow.py + test_anthropic_provider_persistence.py pass (75 tests) via scripts/run_tests.sh.

The anthropic provider paths in resolve_runtime_provider() hardcoded API
key resolution to resolve_anthropic_token(), which only reads env vars
and credential files. Users who configure model.api_key in config.yaml
(common with self-hosted proxies like LiteLLM/OneAPI) were forced to
also set ANTHROPIC_API_KEY as an environment variable, inconsistent
with every other provider.

Both the main anthropic branch and the explicit-override branch now
read model.api_key (gated on model.provider == "anthropic" so unrelated
keys don't leak) before falling back to resolve_anthropic_token().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Anthropic provider ignores config.yaml api_key, requiring duplicate env var configuration

1 participant