Repository navigation
feat(ai,coding-agent): add Anthropic Claude support to Google Vertex AI provider - #9993
Closed
unrealandychan wants to merge 1 commit into
Closed
unrealandychan wants to merge 1 commit into
unrealandychan wants to merge 1 commit into
Conversation
…AI provider Add support for Anthropic Claude models (Claude Opus, Claude Sonnet, Claude Haiku, Claude Fable) under the Google Vertex AI provider: - Update generate-models.ts to include Claude models from models.dev for google-vertex - Add vertex-anthropic adapter that maps Anthropic Messages calls to Vertex AI's publishers/anthropic/models endpoints with Google ADC / API key authentication - Update googleVertexProvider to dispatch anthropic-messages models to vertexAnthropicApi - Add comprehensive unit tests covering request rewriting and streaming
Contributor
|
This PR was auto-closed. Only contributors approved with Maintainers review auto-closed issues daily. Issues that do not meet the quality bar in CONTRIBUTING.md will not be reopened or receive a reply. If a maintainer replies See CONTRIBUTING.md. |
Author
|
@mitsuhiko @cv . Please review this one , this is a big one and I need that so bad. |
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.
Problem
In Google Cloud Vertex AI Model Garden, users can access Anthropic Claude models (such as Claude Opus, Claude Sonnet, and Claude Haiku) using their Google Cloud credentials (ADC or API key). Previously, the
google-vertexcatalog generator explicitly excluded all non-Gemini models withif (!modelId.startsWith("gemini-")) continue;, and the provider only exposed thegoogle-vertexGemini API. As a result, users with GCP credentials authorized for Claude models could only view and invoke Gemini models.Solution
Model Catalog Generation (
packages/ai/scripts/generate-models.ts):processGoogleModelssoclaude-*models undergoogle-vertexare included withapi: "anthropic-messages",provider: "google-vertex", and base URLhttps://{location}-aiplatform.googleapis.com.Vertex Anthropic Adapter (
packages/ai/src/api/vertex-anthropic.ts,packages/ai/src/api/vertex-anthropic.lazy.ts):@google/genaiwithout adding new dependencies.https://${location}-aiplatform.googleapis.com/v1/projects/${project}/locations/${location}/publishers/anthropic/models/${modelId}:${stream ? "streamRawPredict" : "rawPredict"}modelfrom JSON body, sets"anthropic_version": "vertex-2023-10-16").Authorization: Bearer <token>orx-goog-api-key: <key>) while stripping Anthropic-specific API key headers.anthropic-messages.tsstreaming machinery so tool use, extended thinking, streaming deltas, and usage calculations work identically.Tree-Shaking & Bundle Isolation:
vertex-anthropic.lazy.ts).anthropic-messages.tsremains decoupled from@google/genai, preserving browser bundle tree-shaking foranthropicProvider().Provider Dispatch (
packages/ai/src/providers/google-vertex.ts):googleVertexProviderwith an API dispatch map for"google-vertex"(Gemini) and"anthropic-messages"(Vertex Claude).Verification
npm run check: full check passed (biome formatting, linting, imports, runtime dependencies, shrinkwrap, install lock, TypeScript checks, and browser smoke check).vitest --run packages/ai/test/vertex-anthropic.test.ts: all 10 tests passed covering catalog verification, provider dispatch, request URL/header/body transformation, error handling, and streaming.packages/ai/test/google-vertex-api-key-resolution.test.tsandpackages/ai/test/providers.test.tspass.