Add Anthropic via Vertex AI provider
Summary
Add a new anthropic-vertex provider that calls Anthropic Claude models through Google Vertex AI Model Garden, authenticating via ADC (service account) instead of an Anthropic API key. This enables using Claude models on the same cloud deployment and service account as the Google Vertex AI provider.
Motivation
Anthropic Claude models (Opus 4.6, Sonnet 4.6) are available on Google Cloud through the Vertex AI Model Garden. Teams already running workloads on Google Cloud can access Claude without a separate Anthropic API key — the same service account and ADC flow used for Gemini works for Claude.
This means a single Cloud Run deployment can offer both Gemini and Claude models, authenticated by the same service account, with the model selectable at setup time or per request.
Proposed changes
1. New dependency
The Vercel AI SDK provides a dedicated package for calling Anthropic models through Vertex AI. It uses ADC for authentication, just like @ai-sdk/google-vertex.
2. New provider: src/providers/anthropic-vertex.ts
A new ProviderConfig that mirrors the existing anthropic.ts provider but authenticates via Vertex AI ADC instead of an Anthropic API key:
createModel: Uses createVertex({ project, location }) from @ai-sdk/anthropic-vertex instead of createAnthropic({ apiKey }).
preparePdf: Same as the existing anthropic provider — reads PDF bytes inline. No File API, no caching (Claude doesn't support Gemini File API URIs).
apiKey parameter: Ignored — ADC handles authentication.
id: Set to "anthropic" so that provider-specific behavior (e.g., token limit error detection) is consistent.
import { createVertex } from "@ai-sdk/anthropic-vertex";
import type { ProviderConfig, PdfSource, PreparedPdf } from "./types.js";
const MODELS = [
{
id: "claude-sonnet-4-6",
displayName: "Claude Sonnet 4.6",
hint: "Fast and cost-effective",
},
{
id: "claude-opus-4-6",
displayName: "Claude Opus 4.6",
hint: "Best and most expensive",
},
];
const DEFAULT_MODEL = "claude-opus-4-6";
function getProject(): string {
const project = process.env.VERTEX_PROJECT;
if (!project) throw new Error("VERTEX_PROJECT env var is required.");
return project;
}
function getLocation(): string {
return process.env.VERTEX_LOCATION || "us-east5";
}
export const anthropicVertexProvider: ProviderConfig = {
id: "anthropic",
displayName: "Anthropic Claude (Vertex AI)",
models: MODELS,
defaultModel: DEFAULT_MODEL,
apiKeyUrl: "",
createModel: (_apiKey, modelId) => {
const vertex = createVertex({
project: getProject(),
location: getLocation(),
});
return vertex(modelId);
},
providerOptions: {},
preparePdf, // same inline-bytes implementation as anthropic.ts
isTokenLimitError, // same error detection as anthropic.ts
};
3. Wire it up
src/providers/registry.ts:
import { anthropicVertexProvider } from "./anthropic-vertex.js";
export const providers = {
google: googleProvider,
"google-vertex": vertexProvider,
anthropic: anthropicProvider,
"anthropic-vertex": anthropicVertexProvider,
openai: openaiProvider,
};
src/providers/index.ts:
export { anthropicVertexProvider } from "./anthropic-vertex.js";
4. Setup flow
When the user selects "Anthropic Claude (Vertex AI)" during --setup:
- Skip the API key prompt — Vertex AI handles auth via ADC.
- Prompt for GCP Project ID (required).
- Prompt for Region/Location (required — must be a region where Claude models are enabled).
- Prompt for SA key file path (optional — only for local development).
- Prompt for model — choose between Sonnet 4.6 and Opus 4.6.
5. Required IAM roles
| Role |
Purpose |
| Vertex AI User |
Call Claude models via Vertex AI Model Garden |
Note: unlike the Google Vertex AI provider, Storage Admin is not needed — Claude uses inline PDF bytes, not the File API.
6. Model availability
Claude models must be enabled in the GCP project's Vertex AI Model Garden before they can be called. The setup flow or documentation should note this prerequisite.
Environment variables
| Variable |
Required |
Description |
VERTEX_PROJECT |
Yes (or set during --setup) |
GCP project ID |
VERTEX_LOCATION |
Yes (or set during --setup) |
GCP region where Claude is enabled |
GOOGLE_APPLICATION_CREDENTIALS |
Local only |
Path to SA JSON key file |
Backward compatibility
- No breaking changes. The existing
anthropic provider (direct API key) is unchanged.
- This is a new, additive provider choice.
Related
- Depends on: Streamable HTTP transport (for cloud deployment)
- Complements: Google Vertex AI provider (same ADC auth pattern, different models)
- Together,
google-vertex + anthropic-vertex allow a single deployment to serve both Gemini and Claude models via the same service account.
Add Anthropic via Vertex AI provider
Summary
Add a new
anthropic-vertexprovider that calls Anthropic Claude models through Google Vertex AI Model Garden, authenticating via ADC (service account) instead of an Anthropic API key. This enables using Claude models on the same cloud deployment and service account as the Google Vertex AI provider.Motivation
Anthropic Claude models (Opus 4.6, Sonnet 4.6) are available on Google Cloud through the Vertex AI Model Garden. Teams already running workloads on Google Cloud can access Claude without a separate Anthropic API key — the same service account and ADC flow used for Gemini works for Claude.
This means a single Cloud Run deployment can offer both Gemini and Claude models, authenticated by the same service account, with the model selectable at setup time or per request.
Proposed changes
1. New dependency
The Vercel AI SDK provides a dedicated package for calling Anthropic models through Vertex AI. It uses ADC for authentication, just like
@ai-sdk/google-vertex.2. New provider:
src/providers/anthropic-vertex.tsA new
ProviderConfigthat mirrors the existinganthropic.tsprovider but authenticates via Vertex AI ADC instead of an Anthropic API key:createModel: UsescreateVertex({ project, location })from@ai-sdk/anthropic-vertexinstead ofcreateAnthropic({ apiKey }).preparePdf: Same as the existinganthropicprovider — reads PDF bytes inline. No File API, no caching (Claude doesn't support Gemini File API URIs).apiKeyparameter: Ignored — ADC handles authentication.id: Set to"anthropic"so that provider-specific behavior (e.g., token limit error detection) is consistent.3. Wire it up
src/providers/registry.ts:src/providers/index.ts:4. Setup flow
When the user selects "Anthropic Claude (Vertex AI)" during
--setup:5. Required IAM roles
Note: unlike the Google Vertex AI provider, Storage Admin is not needed — Claude uses inline PDF bytes, not the File API.
6. Model availability
Claude models must be enabled in the GCP project's Vertex AI Model Garden before they can be called. The setup flow or documentation should note this prerequisite.
Environment variables
VERTEX_PROJECT--setup)VERTEX_LOCATION--setup)GOOGLE_APPLICATION_CREDENTIALSBackward compatibility
anthropicprovider (direct API key) is unchanged.Related
google-vertex+anthropic-vertexallow a single deployment to serve both Gemini and Claude models via the same service account.