Add Claude as an LLM provider (API key + subscription CLI) - #96
Open
msohailse wants to merge 1 commit into
Open
Conversation
Author
msohailse
force-pushed
the
add-anthropic-claude-provider
branch
from
August 4, 2026 00:40
a24713e to
35bbbe9
Compare
Adds two ways to use Claude for scoring/tailoring, alongside the existing Gemini/OpenAI/local auto-detection in llm.py: - ANTHROPIC_API_KEY: native Anthropic Messages API integration. Needed its own code path rather than reusing the OpenAI-compatible one, since Anthropic takes `system` as a top-level field (not a message role) and uses x-api-key/anthropic-version headers with a different response shape. Defaults to claude-haiku-4-5, matching the existing cost-conscious defaults for the other providers. - USE_CLAUDE_CLI: shells out to the `claude` CLI in print mode instead of hitting the API directly, so scoring/tailoring rides an existing Claude subscription rather than metered per-token billing. `claude -p` takes a single prompt string, not a chat history, so multi-turn messages are flattened (this app's LLM calls are already single-turn); --disallowedTools "*" keeps it a pure text completion with no file/bash access. Both paths tested against the live app's llm.py: - ANTHROPIC_API_KEY: request reached Anthropic and was accepted as well-formed (rejected only for zero account credit balance, not a bad request) -- confirms the request/response wiring is correct. - USE_CLAUDE_CLI: full round trip succeeded end-to-end through get_client().chat(), including system-prompt splitting, using the existing `claude` CLI login. .env.example documents both new options. ruff-checked and ruff-formatted (line-length=120 per pyproject.toml) -- clean on the added code; two pre-existing findings elsewhere in the file (an unused `exc` binding and some formatting drift) predate this change and are left alone to keep the diff scoped to this feature. Also wires the new providers into tier detection: get_tier()/check_tier() in config.py and the `doctor` command in cli.py previously only recognized GEMINI_API_KEY, OPENAI_API_KEY, and LLM_URL, so setting ANTHROPIC_API_KEY or USE_CLAUDE_CLI alone left the CLI reporting Tier 1 and blocking scoring/tailoring/apply even though llm.py fully supported those providers. .env.example | 6 ++- src/applypilot/cli.py | 13 ++++- src/applypilot/config.py | 9 +- src/applypilot/llm.py | 118 +++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 141 insertions(+), 5 deletions(-)
msohailse
force-pushed
the
add-anthropic-claude-provider
branch
from
August 4, 2026 14:47
35bbbe9 to
9defa44
Compare
4 tasks
Author
|
Closing in favor of #98, which includes this same Claude-provider work plus follow-up usage-safety fixes (call budget cap, garbage-URL filtering), organized as separate reviewable commits. |
Author
|
Reopening — splitting the follow-up usage-safety work into its own PR (#98 will be replaced) instead of bundling it here. |
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
ANTHROPIC_API_KEYas a fourth auto-detected LLM provider inllm.py(alongside Gemini/OpenAI/local), since Anthropic's Messages API isn't OpenAI-compatible (separatesystemfield,x-api-key/anthropic-versionheaders, different response shape). Defaults toclaude-haiku-4-5to match the existing cost-conscious defaults for the other providers.USE_CLAUDE_CLIas a second, alternative way to use Claude: shells out to theclaudeCLI in print mode instead of hitting the API directly, so scoring/tailoring rides an existing Claude subscription rather than metered per-token billing.Test plan
ANTHROPIC_API_KEYpath: live request viaget_client().ask(...)reachedapi.anthropic.com, authenticated correctly (no 401), and was accepted as well-formed by the server — rejected only for zero account credit balance, not a bad request. Confirms the request/response wiring is correct.USE_CLAUDE_CLIpath: full round trip throughget_client().chat()succeeded end-to-end, including system-prompt splitting into--system-prompt, using the existingclaudeCLI login (no API key needed in the environment).python -m py_compile src/applypilot/llm.py— syntax check..env.exampleupdated to document both new options.