Skip to content

✨ Add native Anthropic API provider (ChatAnthropic) - #1470

Open
fabianvf wants to merge 1 commit into
konveyor:mainfrom
fabianvf:feat/native-anthropic-provider
Open

✨ Add native Anthropic API provider (ChatAnthropic)#1470
fabianvf wants to merge 1 commit into
konveyor:mainfrom
fabianvf:feat/native-anthropic-provider

Conversation

@fabianvf

@fabianvf fabianvf commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds first-class support for calling the Anthropic Messages API directly via LangChain's ChatAnthropic, alongside the existing providers.

Previously, ChatAnthropic was not a supported provider — getModelProviderFromConfig rejects any provider string not in the ModelCreators registry with "Unsupported model provider". Claude models were only reachable indirectly:

  • via AWS Bedrock (ChatBedrockConverse, through Bedrock's Converse API), or
  • via ChatOpenAI pointed at an OpenAI-compatible proxy baseURL.

This PR wires up the native path so users can drop Anthropic settings straight into provider-settings.yaml.

Changes

  • modelCreator.ts — register a ChatAnthropic creator in the ModelCreators registry, routed through the same unified TLS / custom-fetch setup as the other providers. The custom fetch (for CA bundles / insecure mode) is injected via the Anthropic SDK's clientOptions.fetch.
  • types.ts (client + modelProvider) — add "ChatAnthropic" to the SupportedModelProviders union.
  • sample-provider-settings.yaml — document an Anthropic block.
  • package.json — add @langchain/anthropic.

Sample config

  Anthropic:
    environment:
      ANTHROPIC_API_KEY: "" # Required
    provider: ChatAnthropic
    args:
      model: claude-sonnet-5 # Required
      # anthropicApiUrl: <string> # override the API base URL
      # clientOptions: <object>   # passed through to the Anthropic SDK client

Dependency note

@langchain/anthropic is pinned to ~1.1.3 to match the repo's pinned @langchain/core (1.1.x, enforced repo-wide via the overrides field). Newer @langchain/anthropic lines (1.3+) require @langchain/core ≥ 1.1.45 / 1.2.x and fail to bundle against the current core (missing ContextOverflowError / language_models/structured_output exports). Bumping core would ripple across all providers, so pinning Anthropic to the compatible line is the surgical choice; a follow-up can bump both together. The lockfile change adds only @langchain/anthropic@1.1.3 and @anthropic-ai/sdk@0.71.2 — no other provider's resolved version shifts.

Testing

  • tsc --noEmit passes.
  • webpack --mode production (core) builds cleanly with the new dependency bundled.
  • eslint/prettier clean.

Runtime model calls require a live ANTHROPIC_API_KEY and were not exercised in CI; the wiring mirrors the existing providers exactly.

🤖 Generated with Claude Code

@fabianvf
fabianvf requested a review from a team as a code owner July 8, 2026 15:06
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@fabianvf, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 45 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4fcfa6ee-8cf3-4c17-9396-a9e1ca2085d9

📥 Commits

Reviewing files that changed from the base of the PR and between 675f9c7 and 57de22f.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (8)
  • changes/unreleased/1470-native-anthropic-provider.yaml
  • package.json
  • vscode/core/resources/sample-provider-settings.yaml
  • vscode/core/src/client/types.ts
  • vscode/core/src/modelProvider/__tests__/modelProvider.test.ts
  • vscode/core/src/modelProvider/__tests__/scripts/fakeLLMServer.js
  • vscode/core/src/modelProvider/modelCreator.ts
  • vscode/core/src/modelProvider/types.ts
📝 Walkthrough

Walkthrough

This change adds support for the Anthropic chat provider. A new dependency on @langchain/anthropic is added to package.json. SupportedModelProviders union types in two files are extended with "ChatAnthropic". A new ChatAnthropicCreator class is implemented and registered in the ModelCreators map, providing TLS-aware client creation, default arguments (model, streaming, temperature, retries), and validation of the model argument and ANTHROPIC_API_KEY environment variable. A sample Anthropic configuration block is added to the provider settings YAML.

Estimated code review effort: 2 (Simple) | ~12 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise, specific, and accurately summarizes the new native Anthropic provider support.
Description check ✅ Passed The description is detailed, matches the change set, and includes summary, changes, sample config, dependency notes, and testing.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@fabianvf
fabianvf force-pushed the feat/native-anthropic-provider branch 2 times, most recently from dd2e2fb to a72956d Compare July 8, 2026 15:16
Adds first-class support for calling the Anthropic Messages API directly,
alongside the existing OpenAI-compatible and Bedrock paths. Previously Claude
models were only reachable indirectly via AWS Bedrock or an OpenAI-compatible
proxy base URL.

- Register a `ChatAnthropic` creator in the ModelCreators registry, wired
  through the same unified TLS/custom-fetch setup as the other providers
  (custom fetch is injected via the Anthropic SDK `clientOptions.fetch`).
- Add `ChatAnthropic` to the `SupportedModelProviders` union in both
  client and modelProvider types.
- Document an `Anthropic` block in the sample provider settings.
- Pin `@langchain/anthropic` to ~1.1.3 to match the repo's pinned
  `@langchain/core` (1.1.x); newer lines require a core bump.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Fabian von Feilitzsch <fabian@fabianism.us>
@fabianvf
fabianvf force-pushed the feat/native-anthropic-provider branch from a72956d to 57de22f Compare July 8, 2026 15:21
@fabianvf fabianvf added this to Planning Jul 8, 2026
@github-project-automation github-project-automation Bot moved this to 🆕 New in Planning Jul 8, 2026
@fabianvf fabianvf moved this from 🆕 New to 🏗 In progress in Planning Jul 8, 2026

@ibolton336 ibolton336 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

Overall: Clean, well-structured PR that follows established project conventions precisely. No correctness bugs found.

Strengths

  • Consistent with existing patterns. ChatAnthropicCreator follows the exact same ModelCreator interface, TLS setup, and validation logic as every other provider.
  • Correct TLS/fetch injection. The Anthropic SDK uses clientOptions.fetch (not configuration.fetch like OpenAI) — the PR correctly targets that path.
  • Good test coverage. Three TLS tests (self-signed cert success, no-cert failure, insecure bypass) mirror the OpenAI and Google GenAI test triplets. Mock server endpoint at /v1/messages returns a valid Anthropic Messages API response shape.
  • Thoughtful defaultArgs. No temperature default since current Claude models reject sampling params with a 400 — the comment explains why.
  • Dependency pinning rationale. ~1.1.3 is well-justified to avoid a @langchain/core version cascade.

Minor Suggestions

  1. apiKey can be silently overridden by args spread — In create(), ...args comes after apiKey: env.ANTHROPIC_API_KEY, so a user who accidentally puts apiKey in their YAML args would shadow the env variable. This matches the existing providers (OpenAI, Azure, DeepSeek all do the same), so it's consistent — just worth being aware of.

  2. Sample config model IDsample-provider-settings.yaml uses model: claude-sonnet-5. Worth verifying this matches the current canonical model ID (e.g., claude-sonnet-5-20250514 vs short alias) so users copy-pasting the sample don't hit errors.

  3. No streaming mock — The mock endpoint only handles non-streaming, and the test config sets streaming: false. Since the tests are TLS-focused this is fine, but a streaming mock could be a useful follow-up.

  4. Lockfile churn — The large lockfile diff is just npm reclassifying peer: true annotations. Actual new packages are only @langchain/anthropic@1.1.3, @anthropic-ai/sdk@0.71.2, json-schema-to-ts@3.1.1, and ts-algebra@2.0.0. No version changes to existing deps — looks safe.

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🏗 In progress

Development

Successfully merging this pull request may close these issues.

2 participants