wiki: add `anthropic` provider using the native `/v1/messages` endpoint
Area
gitnexus (CLI / core / indexing / MCP server)
Problem or opportunity
gitnexus wiki only talks to LLM APIs that speak the OpenAI Chat Completions protocol. The LLMProvider union in gitnexus/src/core/wiki/llm-client.ts lists openai | openrouter | azure | custom | cursor | claude | codex | opencode | grok | minimax, and callLLM() always builds POST <baseUrl>/chat/completions with Authorization: Bearer ….
There is no path to call the Anthropic Messages API directly with an ANTHROPIC_API_KEY. To use a Claude model for wiki generation today you must:
- Have the Claude Code CLI (
claude) installed and logged in, then pass--provider claude. This spawnsclaude -p …as a child process and reads stdout. It does not work on machines that do not have Claude Code installed (CI, servers, shared hosts). - Or go through OpenRouter with
provider = custom. That works, but the request path, headers, and request body all pass through OpenRouter, which is not what the user asked for when they set anANTHROPIC_API_KEY.
So a user with a plain Anthropic key, no Claude Code install, and no OpenRouter account cannot use gitnexus wiki. The local-CLI route in #1769 / #2039 covers the "already logged in to Claude Code" case but not the "I have an API key" case.
Proposed solution
Add a new provider value anthropic to LLMProvider. When selected, the wiki client should talk to the Anthropic Messages API directly:
- URL:
POST https://api.anthropic.com/v1/messages - Headers:
x-api-key: <key>,anthropic-version: 2023-06-15,Content-Type: application/json - Auth source:
--api-keyflag,ANTHROPIC_API_KEYenv var, orGITNEXUS_API_KEY - Model:
--model <id>(e.g.claude-sonnet-4-5,claude-opus-4-1) - Optional base URL override for proxies (
--base-url https://…) with the samevalidateLLMBaseUrlrules as other HTTP providers
The existing callLLM() in gitnexus/src/core/wiki/llm-client.ts should branch on config.provider === 'anthropic' and translate the OpenAI-style {role, content} messages into the Anthropic {system, messages} shape, then map the response back to LLMResponse. Streaming via SSE is already supported in readSSEStream; the Anthropic event names (message_start / content_block_delta / message_stop) need their own small parser or a translation layer.
Interactive gitnexus wiki setup in gitnexus/src/cli/wiki.ts should get a new menu entry for anthropic, mirroring the existing azure flow (prompt for API key, optional model, save to ~/.gitnexus/config.json).
Alternatives considered
provider = customwithbase-url = https://api.anthropic.com/v1andAuthorization: Bearer …. Does not work today becausecallLLM()always appends/chat/completionsand Anthropic does not serve that path. Would require either a base-URL rewrite or aprovider = anthropicbranch anyway.provider = openrouterwithmodel = anthropic/<id>. Works today at the cost of one more hop, but the user explicitly chose the Anthropic API.provider = claude(local CLI from #1769). Already supported. Useful when Claude Code is installed and logged in; not a substitute for the bare API key path.- Add
--anthropic-messages-endpointflag tocallLLMand call the Anthropic API from the existing OpenAI-compatible client. Rejected: mixes two wire formats inside one function and breaks the existingAzure/OpenRouterbranches. A separate provider value is clearer.
Acceptance criteria
gitnexus wiki --provider anthropic --api-key <key> --model claude-sonnet-4-5produces a wiki end-to-end againsthttps://api.anthropic.com/v1/messagesand writes the expected output files.ANTHROPIC_API_KEYin the environment is picked up automatically when--provider anthropicis set and no--api-keyis given.gitnexus wiki --provider anthropic --base-url https://proxy.example/v1works with the samevalidateLLMBaseUrlchecks (httpsrequired,httponly with allowlist) used for other HTTP providers.- Streaming output (
onChunkcallback incallLLM) still drives progress UI; the Anthropic SSE events are translated todelta.contentchunks. gitnexus wikiinteractive setup has a new menu entry that savesprovider: "anthropic"plus the model to~/.gitnexus/config.json.- Unit tests cover: request URL + headers, message translation (system prompt into
system, user content intomessages), response translation, and the SSE event parser.npx tsc --noEmitandnpm testpass.
Constraints
- No new npm dependency. The Anthropic API is plain HTTPS + SSE; reuse the existing
resilientFetchandreadSSEStreamplumbing. - The Anthropic API uses different finish reasons and error shapes from OpenAI. Map only what
callLLMalready consumes (choices[0].message.content); do not leak Anthropic-specific fields upward. - Do not change the existing
openai/openrouter/azure/custom/claude/codex/opencode/cursor/grok/minimaxprovider behavior. This is a strictly additive change. - The
claudelocal-CLI provider (CLI subprocess path inlocal-cli-client.ts) stays as is.claude(local CLI) andanthropic(HTTP API) are two distinct providers, similar to howcursorandcustomcoexist.
Contribution
- I am willing to open a PR for this (may need design discussion first).
Source: abhigyanpatwari/GitNexus