Skip to content

Add Claude as an LLM provider (API key + subscription CLI) - #96

Open
msohailse wants to merge 1 commit into
Pickle-Pixel:mainfrom
msohailse:add-anthropic-claude-provider
Open

Add Claude as an LLM provider (API key + subscription CLI)#96
msohailse wants to merge 1 commit into
Pickle-Pixel:mainfrom
msohailse:add-anthropic-claude-provider

Conversation

@msohailse

@msohailse msohailse commented Aug 4, 2026

Copy link
Copy Markdown

Summary

  • Adds ANTHROPIC_API_KEY as a fourth auto-detected LLM provider in llm.py (alongside Gemini/OpenAI/local), since Anthropic's Messages API isn't OpenAI-compatible (separate system field, x-api-key/anthropic-version headers, different response shape). Defaults to claude-haiku-4-5 to match the existing cost-conscious defaults for the other providers.
  • Adds USE_CLAUDE_CLI as a second, alternative way to use Claude: 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.

Test plan

  • ANTHROPIC_API_KEY path: live request via get_client().ask(...) reached api.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_CLI path: full round trip through get_client().chat() succeeded end-to-end, including system-prompt splitting into --system-prompt, using the existing claude CLI login (no API key needed in the environment).
  • python -m py_compile src/applypilot/llm.py — syntax check.
  • .env.example updated to document both new options.

@msohailse msohailse changed the title Add Anthropic Claude as an LLM provider option Add Claude as an LLM provider (API key + subscription CLI) Aug 4, 2026
@msohailse

Copy link
Copy Markdown
Author

@Pickle-Pixel

@msohailse
msohailse force-pushed the add-anthropic-claude-provider branch from a24713e to 35bbbe9 Compare August 4, 2026 00:40
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

Copy link
Copy Markdown
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.

@msohailse msohailse closed this Aug 10, 2026
@msohailse

Copy link
Copy Markdown
Author

Reopening — splitting the follow-up usage-safety work into its own PR (#98 will be replaced) instead of bundling it here.

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.

1 participant