Repository navigation
fix(cli): validate a community's own Anthropic key, not just OpenRouter - #391
Merged
neuromechanist merged 2 commits intoSep 17, 2026
Conversation
The CLI's light paths cannot import anthropic_llm: it pulls in langchain-anthropic from the server extra, and src/cli/main.py downgrades osa validate to a stub when importing src/cli/validate.py fails. A dependency-free module lets the validator use the same endpoint constant the runtime does. No behavior change.
osa validate read only openrouter_api_key_env_var, so a community funding its own Anthropic usage was told 'Not configured (using platform key)' and never got the warning that exists to catch surprise platform billing. Resolve the env var with the same precedence the runtime uses (Anthropic first, matching _resolve_provider and health.py) and report which provider owns it. --test-api-key now tests the key against its own provider: a community Anthropic key against the first-party /v1/models, because create_anthropic_llm pins base_url there whenever an explicit key is passed, so that is where the community's requests go. The flag's help text no longer says OpenRouter. Tests cover both providers, the precedence between them, and that src/cli/validate.py still imports with the server extra blocked, which is what keeps file-mode validation working on a CLI-only install. Verified by reverting each fix and watching the new tests fail. Closes #390
neuromechanist
merged commit Sep 17, 2026
b60b367
into
feature/issue-360-epic-anthropic-platform
3 of 4 checks passed
This was referenced Sep 17, 2026
Merged
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.
Closes #390. Part of #360.
Found while writing the Phase 5 troubleshooting docs:
osa validatehad not been migrated with the rest of the platform.What was wrong
src/cli/validate.pyread onlyopenrouter_api_key_env_var. A community that funds its own Anthropic usage throughanthropic_api_key_env_varfell into theelsebranch and was told the opposite of the truth:It also never got the missing-env-var warning, which is the one that exists to prevent surprise platform billing.
--test-api-keycould only test an OpenRouter key, and said so in its own help text.The runtime already resolves this correctly, in both places that matter:
_resolve_provider(src/api/routers/community.py) andsrc/api/routers/health.py:30.What changed
_community_key_env_varresolves the community's own key env var with the runtime's precedence, Anthropic first, and returns the provider that owns it. Output now names the provider:✓ ANTHROPIC_API_KEY_HED is set (Anthropic).--test-api-keytests the key against that provider. A community Anthropic key goes to the first-partyGET /v1/modelswithx-api-key, becausecreate_anthropic_llmpinsbase_urlto the first-party API whenever an explicit key is passed, so that is the endpoint the community's requests use. Probing the AWS platform endpoint instead would fail a perfectly good key.src/core/services/anthropic_endpoints.py. Importing it fromanthropic_llm.pyinstead would have been a quiet regression: that module needs langchain-anthropic from theserverextra, andsrc/cli/main.pyreplacesosa validatewith a "requires server dependencies" stub whensrc/cli/validate.pyfails to import, so CLI-only installs would have lost file-mode validation entirely. Caught by trying it.Tests
--test-api-keyrouting per provider, asserted at the HTTP boundary (respx) on URL and auth header, plus the 401 path.network-marked test against the live endpoint, which is the assertion a fixture cannot make: that the path and header names are the ones Anthropic actually accepts (a wrong path answers 404, and a fixture would happily fake either).src/cli/validate.pywith theserverextra blocked, so the packaging trap above cannot come back. It is paired with a test that the blocker really blocks, so it cannot pass vacuously.Each fix was verified by reverting it and confirming the new tests fail: removing the Anthropic precedence fails 6 tests, importing the constant from
anthropic_llmfails the CLI-only import test.Full offline suite: 2115 passed. The one failure,
test_version_shows_version, is pre-existing on the base branch (Rich ANSI codes in the version string).