Skip to main content

Overview

The Vertex AI Anthropic provider connects core-ai to Claude models hosted on Google Vertex AI through the official @anthropic-ai/vertex-sdk client. It shares its request, streaming, tool-calling, structured-output, and reasoning behavior with @core-ai/anthropic — everything documented on the Anthropic Provider page applies equally here.

Installation

npm install @core-ai/anthropic-vertex

createAnthropicVertex()

Create a Vertex AI Anthropic provider instance.
import { createAnthropicVertex } from '@core-ai/anthropic-vertex';

const anthropicVertex = createAnthropicVertex({
    projectId: process.env.GOOGLE_VERTEX_PROJECT,
    region: 'europe-west1',
});

Options

projectId
string
Your Google Cloud project id. Required unless client is provided.
region
string
The Vertex AI region hosting the Claude model, for example europe-west1 or eu. Required unless client is provided. A provider instance targets a single region — create separate providers if you need models hosted in different regions.
credentials
object
A parsed Google service account JSON key. When omitted, the provider falls back to Application Default Credentials (ADC).
client
AnthropicChatClient
Provide your own configured client (for example a custom AnthropicVertex instance).
defaultMaxTokens
number
default:"4096"
Default maximum tokens for completions. Can be overridden per request.

Returns

AnthropicVertexProvider with method chatModel().

Authentication

By default, the provider uses Application Default Credentials:
const anthropicVertex = createAnthropicVertex({
    projectId: process.env.GOOGLE_VERTEX_PROJECT,
    region: 'europe-west1',
});
To authenticate with an explicit service account instead, parse the service account JSON and pass the resulting object as credentials:
const anthropicVertex = createAnthropicVertex({
    projectId: process.env.GOOGLE_VERTEX_PROJECT,
    region: 'europe-west1',
    credentials: JSON.parse(
        process.env.GOOGLE_APPLICATION_CREDENTIALS_JSON ?? ''
    ),
});
You can also inject a preconfigured client:
import { AnthropicVertex } from '@anthropic-ai/vertex-sdk';
import { createAnthropicVertex } from '@core-ai/anthropic-vertex';

const anthropicVertex = createAnthropicVertex({
    client: new AnthropicVertex({ projectId: 'my-project', region: 'eu' }),
});

Model IDs and regions

Pass the Vertex model id (as listed in the Vertex AI Model Garden) to chatModel(). Model availability and naming vary by region — some Claude models are published to Vertex AI’s eu multi-region while others are published to region-specific endpoints such as europe-west1. Since a provider instance targets a single region, create separate providers for models hosted in different regions:
const anthropicVertexEu = createAnthropicVertex({
    projectId: process.env.GOOGLE_VERTEX_PROJECT,
    region: 'eu',
});
const anthropicVertexEuWest1 = createAnthropicVertex({
    projectId: process.env.GOOGLE_VERTEX_PROJECT,
    region: 'europe-west1',
});

const model = anthropicVertexEuWest1.chatModel('claude-sonnet-4-6');
Pass the unversioned Vertex model id (e.g. claude-sonnet-4-6) rather than a version-pinned id (e.g. claude-sonnet-4-6@20250929). Reasoning- effort and sampling-restriction capability detection (getAnthropicModelCapabilities and friends in @core-ai/anthropic) only recognizes the unversioned form today, so a version-pinned id silently falls back to standard capabilities instead of the model’s actual ones.

Capabilities

FeatureSupport
Chat CompletionYes
StreamingYes
Function CallingYes
VisionYes
ReasoningYes
Prompt CachingYes
EmbeddingsNo
Image GenerationNo
Model capability helpers such as getAnthropicModelCapabilities(modelId) are available from @core-ai/anthropic and apply to Vertex-hosted Claude models.

Examples

Basic chat

import { generate } from '@core-ai/core-ai';
import { createAnthropicVertex } from '@core-ai/anthropic-vertex';

const anthropicVertex = createAnthropicVertex({
    projectId: process.env.GOOGLE_VERTEX_PROJECT,
    region: 'europe-west1',
});

const result = await generate({
    model: anthropicVertex.chatModel('claude-sonnet-4-6'),
    messages: [{ role: 'user', content: 'Explain the theory of relativity' }],
    maxTokens: 1024,
});

console.log(result.content);

Streaming

import { stream } from '@core-ai/core-ai';

const chatStream = await stream({
    model: anthropicVertex.chatModel('claude-sonnet-4-6'),
    messages: [{ role: 'user', content: 'Write a detailed analysis of...' }],
    maxTokens: 1024,
});

for await (const event of chatStream) {
    if (event.type === 'text-delta') {
        process.stdout.write(event.text);
    }
}

Provider-specific options and reasoning

Provider options are namespaced under anthropic in providerOptions, matching @core-ai/anthropic:
const result = await generate({
    model: anthropicVertex.chatModel('claude-sonnet-4-6'),
    messages: [{ role: 'user', content: 'Hello' }],
    maxTokens: 1024,
    providerOptions: {
        anthropic: {
            stopSequences: ['\n\n'],
        },
    },
});
See the Anthropic Provider docs for the full list of available fields, reasoning restrictions, and prompt-caching behavior — they apply unchanged to Vertex-hosted Claude models.

Error handling

import { ProviderError } from '@core-ai/core-ai';

try {
    const result = await generate({
        model: anthropicVertex.chatModel('claude-sonnet-4-6'),
        messages: [{ role: 'user', content: 'Hello!' }],
        maxTokens: 1024,
    });
} catch (error) {
    if (error instanceof ProviderError) {
        console.error('Vertex Anthropic API error:', error.message);
        console.error('Status:', error.statusCode);
    }
}
Errors are attributed to provider id anthropic-vertex, distinguishing them from direct @core-ai/anthropic errors (anthropic).

Anthropic Provider

Claude models via the direct Anthropic API

Google GenAI Provider

Gemini models with multimodal support

Chat Completion Guide

Learn how to use chat completion