Skip to content

feat(ai,coding-agent): add Anthropic Claude support to Google Vertex AI provider - #9993

Closed
unrealandychan wants to merge 1 commit into
earendil-works:mainfrom
unrealandychan:feat/vertex-anthropic-claude-support
Closed

unrealandychan wants to merge 1 commit into
earendil-works:mainfrom
unrealandychan:feat/vertex-anthropic-claude-support

Conversation

@unrealandychan

Copy link
Copy Markdown

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-vertex catalog generator explicitly excluded all non-Gemini models with if (!modelId.startsWith("gemini-")) continue;, and the provider only exposed the google-vertex Gemini API. As a result, users with GCP credentials authorized for Claude models could only view and invoke Gemini models.

Solution

  1. Model Catalog Generation (packages/ai/scripts/generate-models.ts):

    • Updated processGoogleModels so claude-* models under google-vertex are included with api: "anthropic-messages", provider: "google-vertex", and base URL https://{location}-aiplatform.googleapis.com.
    • Claude models inherit proper tool-calling, vision modalities, reasoning options, and cost metadata.
  2. Vertex Anthropic Adapter (packages/ai/src/api/vertex-anthropic.ts, packages/ai/src/api/vertex-anthropic.lazy.ts):

    • Implemented a request adapter for Anthropic Messages on Vertex AI.
    • Obtains Google Cloud OAuth authorization headers from Application Default Credentials / service account files or Google Cloud API keys via @google/genai without adding new dependencies.
    • Rewrites messages requests to the Vertex AI publisher endpoint format:
      https://${location}-aiplatform.googleapis.com/v1/projects/${project}/locations/${location}/publishers/anthropic/models/${modelId}:${stream ? "streamRawPredict" : "rawPredict"}
    • Formats the request body for Vertex AI (removes model from JSON body, sets "anthropic_version": "vertex-2023-10-16").
    • Injects Google authorization headers (Authorization: Bearer <token> or x-goog-api-key: <key>) while stripping Anthropic-specific API key headers.
    • Connects to anthropic-messages.ts streaming machinery so tool use, extended thinking, streaming deltas, and usage calculations work identically.
  3. Tree-Shaking & Bundle Isolation:

    • The Vertex adapter is exposed as a lazy API module (vertex-anthropic.lazy.ts).
    • anthropic-messages.ts remains decoupled from @google/genai, preserving browser bundle tree-shaking for anthropicProvider().
  4. Provider Dispatch (packages/ai/src/providers/google-vertex.ts):

    • Configured googleVertexProvider with 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.
  • Existing tests in packages/ai/test/google-vertex-api-key-resolution.test.ts and packages/ai/test/providers.test.ts pass.

…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
@github-actions

Copy link
Copy Markdown
Contributor

This PR was auto-closed. Only contributors approved with lgtm can open PRs. Open an issue first and ask a maintainer for approval.

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 lgtmi, your future issues will stay open. If a maintainer replies lgtm, your future issues and PRs will stay open. The command must be at the start of the reply (optionally after one or more @username mentions) or at the end.

See CONTRIBUTING.md.

@github-actions github-actions Bot closed this Sep 24, 2026
@unrealandychan

Copy link
Copy Markdown
Author

@mitsuhiko @cv . Please review this one , this is a big one and I need that so bad.

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