✨ Add native Anthropic API provider (ChatAnthropic) - #1470
Conversation
|
Warning Review limit reached
Next review available in: 45 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (8)
📝 WalkthroughWalkthroughThis change adds support for the Anthropic chat provider. A new dependency on Estimated code review effort: 2 (Simple) | ~12 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
dd2e2fb to
a72956d
Compare
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>
a72956d to
57de22f
Compare
ibolton336
left a comment
There was a problem hiding this comment.
Code Review
Overall: Clean, well-structured PR that follows established project conventions precisely. No correctness bugs found.
Strengths
- Consistent with existing patterns.
ChatAnthropicCreatorfollows the exact sameModelCreatorinterface, TLS setup, and validation logic as every other provider. - Correct TLS/fetch injection. The Anthropic SDK uses
clientOptions.fetch(notconfiguration.fetchlike 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/messagesreturns a valid Anthropic Messages API response shape. - Thoughtful
defaultArgs. Notemperaturedefault since current Claude models reject sampling params with a 400 — the comment explains why. - Dependency pinning rationale.
~1.1.3is well-justified to avoid a@langchain/coreversion cascade.
Minor Suggestions
-
apiKeycan be silently overridden byargsspread — Increate(),...argscomes afterapiKey: env.ANTHROPIC_API_KEY, so a user who accidentally putsapiKeyin 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. -
Sample config model ID —
sample-provider-settings.yamlusesmodel: claude-sonnet-5. Worth verifying this matches the current canonical model ID (e.g.,claude-sonnet-5-20250514vs short alias) so users copy-pasting the sample don't hit errors. -
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. -
Lockfile churn — The large lockfile diff is just npm reclassifying
peer: trueannotations. Actual new packages are only@langchain/anthropic@1.1.3,@anthropic-ai/sdk@0.71.2,json-schema-to-ts@3.1.1, andts-algebra@2.0.0. No version changes to existing deps — looks safe.
🤖 Generated with Claude Code
Summary
Adds first-class support for calling the Anthropic Messages API directly via LangChain's
ChatAnthropic, alongside the existing providers.Previously,
ChatAnthropicwas not a supported provider —getModelProviderFromConfigrejects any provider string not in theModelCreatorsregistry with"Unsupported model provider". Claude models were only reachable indirectly:ChatBedrockConverse, through Bedrock's Converse API), orChatOpenAIpointed at an OpenAI-compatible proxybaseURL.This PR wires up the native path so users can drop Anthropic settings straight into
provider-settings.yaml.Changes
modelCreator.ts— register aChatAnthropiccreator in theModelCreatorsregistry, 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'sclientOptions.fetch.types.ts(client + modelProvider) — add"ChatAnthropic"to theSupportedModelProvidersunion.sample-provider-settings.yaml— document anAnthropicblock.package.json— add@langchain/anthropic.Sample config
Dependency note
@langchain/anthropicis pinned to~1.1.3to match the repo's pinned@langchain/core(1.1.x, enforced repo-wide via theoverridesfield). Newer@langchain/anthropiclines (1.3+) require@langchain/core≥ 1.1.45 / 1.2.x and fail to bundle against the current core (missingContextOverflowError/language_models/structured_outputexports). 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.3and@anthropic-ai/sdk@0.71.2— no other provider's resolved version shifts.Testing
tsc --noEmitpasses.webpack --mode production(core) builds cleanly with the new dependency bundled.Runtime model calls require a live
ANTHROPIC_API_KEYand were not exercised in CI; the wiring mirrors the existing providers exactly.🤖 Generated with Claude Code