Skip to content

feat: native Anthropic provider adapter (C2)#13

Merged
MANVENDRA-github merged 1 commit into
mainfrom
feat/anthropic-adapter
Jun 30, 2026
Merged

feat: native Anthropic provider adapter (C2)#13
MANVENDRA-github merged 1 commit into
mainfrom
feat/anthropic-adapter

Conversation

@MANVENDRA-github

Copy link
Copy Markdown
Owner

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.

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.
@MANVENDRA-github
MANVENDRA-github merged commit 79e5e32 into main Jun 30, 2026
2 checks passed
@MANVENDRA-github
MANVENDRA-github deleted the feat/anthropic-adapter branch June 30, 2026 16:55
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