Skip to content

fix(cli): honor api_key from config.yaml for anthropic provider - #9105

Open
Tranquil-Flow wants to merge 1 commit into
NousResearch:mainfrom
Tranquil-Flow:fix/anthropic-config-api-key
Open

fix(cli): honor api_key from config.yaml for anthropic provider#9105
Tranquil-Flow wants to merge 1 commit into
NousResearch:mainfrom
Tranquil-Flow:fix/anthropic-config-api-key

Conversation

@Tranquil-Flow

@Tranquil-Flow Tranquil-Flow commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Runtime provider resolution did not honor model.api_key from config.yaml for the Anthropic provider in the intended scoped path. This PR allows configured Anthropic API keys to be used for Anthropic only, avoiding cross-provider key leakage.

Related Issue

Related to Anthropic runtime provider config resolution.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • Honor model.api_key in hermes_cli/runtime_provider.py when the configured provider is Anthropic.
  • Keep provider scoping strict so the configured key is not leaked to unrelated providers.
  • Add focused runtime provider resolution regression coverage.

How to Test

  1. Check out this PR branch.
  2. Run: .venv/bin/python -m pytest -o 'addopts=' tests/hermes_cli/test_runtime_provider_resolution.py -q
  3. Expected result: 131 passed

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass — focused pytest passed; full suite was not run in this salvage pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: Linux container / Python 3.11

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

Focused verification:

`.venv/bin/python -m pytest -o 'addopts=' tests/hermes_cli/test_runtime_provider_resolution.py -q` — 131 passed

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cli CLI entry point, hermes_cli/, setup wizard provider/anthropic Anthropic native Messages API area/config Config system, migrations, profiles labels Apr 27, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #11713 (closed) — same fix: honor model.api_key from config.yaml for anthropic provider. Also related to #16346, #16254 (broader api_key/api_mode config issues).

@Tranquil-Flow
Tranquil-Flow force-pushed the fix/anthropic-config-api-key branch 2 times, most recently from b83c579 to 7d74a9e Compare May 25, 2026 14:00
@Tranquil-Flow
Tranquil-Flow force-pushed the fix/anthropic-config-api-key branch 2 times, most recently from 7c796a9 to d70b7c6 Compare May 26, 2026 00:03
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for isolating the normal native-Anthropic resolution path and retaining provider scoping. The premise remains valid on current main: the non-Azure branch still calls resolve_anthropic_token() directly at hermes_cli/runtime_provider.py:1902-1903.

Problems

  • The explicit-runtime sibling remains unfixed. _resolve_explicit_runtime() activates when an explicit base URL is provided (hermes_cli/runtime_provider.py:1364), but its Anthropic branch falls through to resolve_anthropic_token() at :1375-1380 without considering the scoped model.api_key.

Suggested changes

  • Apply the same provider-gated config-key fallback in _resolve_explicit_runtime() before the environment/credential fallback, and add coverage for explicit base URL plus config-only key and the cross-provider no-leak case.
  • Add a temp-HERMES_HOME config-loading regression test for this resolution chain.

GitHub currently reports this branch as conflicting, and the resolver has moved; salvage will require manual conflict resolution rather than a clean cherry-pick. This is an automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 12, 2026
Re-port of NousResearch#9105 onto current upstream/main (af250d8).

The non-Azure branch in resolve_runtime_provider() did not check
model_cfg.get('api_key'), so users who configured an inline api_key
under model: in config.yaml had it silently ignored for native
Anthropic.  Now:

- The Azure branch already read config api_key; add source tracking.
- The non-Azure (OAuth/env) branch now reads model.api_key first
  when cfg_provider == 'anthropic', falling back to
  resolve_anthropic_token() as before.
- 'source' distinguishes 'config' vs 'env' for observability.

Cross-provider leak is prevented: a config api_key from a different
provider (e.g. openrouter) is never read by the anthropic branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Config system, migrations, profiles comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists provider/anthropic Anthropic native Messages API sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants