Skip to content

feat(ai-anthropic): support GCP Vertex for the antrophic adapter#989

Open
flxwu wants to merge 1 commit into
TanStack:mainfrom
flxwu:codex/anthropic-client-injection
Open

feat(ai-anthropic): support GCP Vertex for the antrophic adapter#989
flxwu wants to merge 1 commit into
TanStack:mainfrom
flxwu:codex/anthropic-client-injection

Conversation

@flxwu

@flxwu flxwu commented Jul 23, 2026

Copy link
Copy Markdown

🎯 Changes

  • Add a narrow, version-tolerant AnthropicMessagesClient contract around beta.messages.create.
  • Add createAnthropicChatWithClient for preconfigured authentication and transport while preserving the existing API-key factories.
  • Verify compatibility with the official Vertex client and a newer Anthropic SDK declaration set.
  • Route the existing Anthropic E2E matrix through the injected-client path.
  • Document custom clients and include a minor changeset.

The adapter's request mapping, streaming, tools, media, usage, and structured-output behavior are unchanged. Authentication and endpoint-specific feature support remain the injected client's responsibility.

🧪 Verification

  • pnpm test:pr (281/281 affected targets succeeded; declaration scan clean)
  • pnpm --filter @tanstack/ai-e2e test:e2e (389 passed, 1 skipped; run on an isolated local port because 3010 was occupied)
  • Anthropic package unit, type, build, lint, and publint checks

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • New Features
    • Added support for creating Anthropic chat adapters with custom, pre-configured clients.
    • Enables custom authentication, endpoints, headers, and compatible Anthropic transports.
    • Expanded documented Anthropic capabilities, including Claude chat, thinking, tools, and structured outputs.
  • Documentation
    • Added API reference and usage guidance for custom Anthropic clients.
  • Tests
    • Added coverage verifying injected clients are used correctly and support compatible client implementations.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The Anthropic adapter now supports injected Anthropic-compatible Messages clients through createAnthropicChatWithClient, with updated exports, tests, e2e wiring, dependencies, documentation, and release metadata.

Changes

Anthropic client injection

Layer / File(s) Summary
Client contract and adapter configuration
packages/ai-anthropic/src/utils/client.ts, packages/ai-anthropic/src/adapters/text.ts, packages/ai-anthropic/tests/client-injection-type-safety.test.ts, packages/ai-anthropic/package.json
Defines AnthropicMessagesClient, supports injected-client adapter configuration, and validates compatibility with Anthropic SDK client shapes.
Injected client adapter factory
packages/ai-anthropic/src/adapters/text.ts, packages/ai-anthropic/src/index.ts
Routes requests through an injected client when provided, adds createAnthropicChatWithClient, and re-exports the new factory and configuration type.
Consumer wiring and documented usage
packages/ai-anthropic/tests/anthropic-adapter.test.ts, testing/e2e/..., docs/adapters/anthropic.md, README.md, .changeset/..., docs/config.json
Tests injected request routing, updates the e2e Anthropic provider, documents the factory, and records provider and release metadata changes.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Provider
  participant createAnthropicChatWithClient
  participant AnthropicTextAdapter
  participant InjectedAnthropicClient
  Provider->>createAnthropicChatWithClient: provide model and client
  createAnthropicChatWithClient->>AnthropicTextAdapter: construct adapter
  AnthropicTextAdapter->>InjectedAnthropicClient: call beta.messages.create
  InjectedAnthropicClient-->>AnthropicTextAdapter: return message stream
Loading

Suggested reviewers: alemtuzlak, tombeckenham

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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 relevant and captures the Anthropic adapter’s Vertex/client-injection focus, even if it is a bit narrower than the full change set.
Description check ✅ Passed The description matches the template with Changes, Checklist, and Release Impact sections, and it includes useful verification details.
✨ 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.

@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednpm/​@​anthropic-ai/​sdk@​0.112.46610091100100
Addednpm/​@​anthropic-ai/​vertex-sdk@​0.19.010010010099100

View full report

@flxwu flxwu changed the title feat(ai-anthropic): accept preconfigured Messages clients feat(ai-anthropic): support GCP Vertex for the antrophic adapter Jul 23, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/ai-anthropic/tests/client-injection-type-safety.test.ts (1)

1-18: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Place this unit test alongside its source.

This test covers packages/ai-anthropic/src/utils/client.ts but is located under packages/ai-anthropic/tests/. Move it to a colocated *.test.ts file beside the source.

As per coding guidelines, unit tests must be placed in *.test.ts files alongside the source they cover.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/ai-anthropic/tests/client-injection-type-safety.test.ts` around
lines 1 - 18, Move the type-safety tests from the package-level tests directory
into a colocated *.test.ts file beside the client utility source, preserving
both expectTypeOf cases and their existing assertions.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/ai-anthropic/tests/client-injection-type-safety.test.ts`:
- Around line 1-18: Move the type-safety tests from the package-level tests
directory into a colocated *.test.ts file beside the client utility source,
preserving both expectTypeOf cases and their existing assertions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 13203040-11ca-436c-b87b-49b2da387ca3

📥 Commits

Reviewing files that changed from the base of the PR and between 347b61b and 61b574a.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (12)
  • .changeset/anthropic-client-injection.md
  • README.md
  • docs/adapters/anthropic.md
  • docs/config.json
  • packages/ai-anthropic/package.json
  • packages/ai-anthropic/src/adapters/text.ts
  • packages/ai-anthropic/src/index.ts
  • packages/ai-anthropic/src/utils/client.ts
  • packages/ai-anthropic/tests/anthropic-adapter.test.ts
  • packages/ai-anthropic/tests/client-injection-type-safety.test.ts
  • testing/e2e/package.json
  • testing/e2e/src/lib/providers.ts

@luap2703

Copy link
Copy Markdown

Great!

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.

2 participants