feat: native Anthropic provider adapter (C2)#13
Merged
Conversation
Adds a real adapter for Anthropic's Messages API (which is NOT OpenAI-compatible), so the advertised 4-provider support actually holds. Clients keep sending the OpenAI shape; Sentinel translates in and out. (Closes the provider gap from the v0.1.x audit.) What changed - New `providers/anthropic.ts`: OpenAI chat request → Anthropic Messages body (system message hoisted to top-level `system`, required `max_tokens` defaulted, `top_p`/`stop` mapped), and Anthropic response + SSE stream → the OpenAI shape. Auth via `x-api-key` + `anthropic-version`; `redirect: 'error'` preserved; the upstream response is parsed through a Zod schema (unexpected shape ⇒ 502). - Config: provider `type` widened to `'openai-compatible' | 'anthropic'` and threaded through `ResolvedProvider`; the registry builds the right adapter by type. Example config + `.env.example` carry an Anthropic entry. - Docs: README / CLAUDE / CHANGELOG now state native Anthropic support; SECURITY_REVIEW_LOG SR-007 covers the new outbound auth path, SSRF, and response-shape parsing. Tests - Adapter request/response/stream translation, `x-api-key` header + no-key case, non-OK + bad-shape errors, default max_tokens (+ stop_reason mapping), array content / multi-system join / top_p+stop, and stream event filtering. - Registry builds the Anthropic adapter for `type: 'anthropic'`; config parses it and rejects unknown types. How to verify - `pnpm verify` → green (230 tests, coverage ≥90%) - `pnpm build` → green Existing OpenAI-compatible providers are unchanged.
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.
Adds a real adapter for Anthropic's Messages API (which is NOT OpenAI-compatible),
so the advertised 4-provider support actually holds. Clients keep sending the
OpenAI shape; Sentinel translates in and out. (Closes the provider gap from the
v0.1.x audit.)
What changed
providers/anthropic.ts: OpenAI chat request → Anthropic Messages body(system message hoisted to top-level
system, requiredmax_tokensdefaulted,top_p/stopmapped), and Anthropic response + SSE stream → the OpenAI shape.Auth via
x-api-key+anthropic-version;redirect: 'error'preserved; theupstream response is parsed through a Zod schema (unexpected shape ⇒ 502).
typewidened to'openai-compatible' | 'anthropic'andthreaded through
ResolvedProvider; the registry builds the right adapter bytype. Example config +
.env.examplecarry an Anthropic entry.SECURITY_REVIEW_LOG SR-007 covers the new outbound auth path, SSRF, and
response-shape parsing.
Tests
x-api-keyheader + no-key case,non-OK + bad-shape errors, default max_tokens (+ stop_reason mapping), array
content / multi-system join / top_p+stop, and stream event filtering.
type: 'anthropic'; config parsesit and rejects unknown types.
How to verify
pnpm verify→ green (230 tests, coverage ≥90%)pnpm build→ greenExisting OpenAI-compatible providers are unchanged.