@core-ai/anthropic-vertex

中文文档
0.38.0发布于 2026/11/06MITTypeScriptESM + CJS构建来源已验证近 30 天下载 4509

Vertex AI Anthropic (Claude) provider package for @core-ai/core-ai

原始使用文档
文档目录5 节
  1. Installation
  2. Usage
  3. Authentication
  4. Model IDs and regions
  5. Provider options and model capabilities

@core-ai/anthropic-vertex

npm

Vertex AI Anthropic (Claude) provider package for @core-ai/core-ai. It uses the @anthropic-ai/vertex-sdk client and shares its request, streaming, tool-calling, structured-output, and reasoning behavior with @core-ai/anthropic.

Installation

npm install @core-ai/core-ai @core-ai/anthropic-vertex zod

Usage

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 model = anthropicVertex.chatModel('claude-sonnet-4-6');

const result = await generate({
    model,
    messages: [{ role: 'user', content: 'Hello!' }],
});

console.log(result.content);

Authentication

By default, the provider uses Google Application Default Credentials (ADC):

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

To authenticate with an explicit service account instead, parse its JSON key and pass it as credentials:

const rawCredentials = process.env.GOOGLE_APPLICATION_CREDENTIALS_JSON;
const credentialsJson = rawCredentials?.trim().startsWith('{')
    ? rawCredentials
    : Buffer.from(rawCredentials ?? '', 'base64').toString('utf8');

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

You can also inject a preconfigured client (for example a custom AnthropicVertex instance, or one wired up for testing):

import { AnthropicVertex } from '@anthropic-ai/vertex-sdk';

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 — for example, some Claude models are only published to Vertex AI's eu multi-region while others are published to region-specific endpoints like europe-west1. Since a provider instance targets a single region, create separate providers if you need to reach 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',
});

This package supports chat models only.

Caveat: 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.

Provider options and model capabilities

This provider shares its request, streaming, and reasoning behavior with @core-ai/anthropic. Provider-options schemas (anthropicGenerateProviderOptionsSchema), reasoning metadata types (AnthropicReasoningMetadata), and model capability helpers (getAnthropicModelCapabilities) are available from @core-ai/anthropic and apply equally to Vertex-hosted Claude models.

版本与发布记录

@core-ai/anthropic-vertex 共发布 30 个版本,首次发布于 2026/07/14;过去 12 个月发布了 30 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.38.0latest2026/11/064 天前
0.37.02026/11/055 天前
0.36.22026/10/2912 天前
0.36.12026/10/2813 天前
0.36.02026/10/2219 天前
0.35.02026/10/1427 天前

关于 @core-ai/anthropic-vertex 的常见问题

@core-ai/anthropic-vertex 是什么?

Vertex AI Anthropic (Claude) provider package for @core-ai/core-ai

如何安装 @core-ai/anthropic-vertex?

在项目目录运行 npm install @core-ai/anthropic-vertex,或使用 pnpm add / yarn add / bun add。

@core-ai/anthropic-vertex 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@core-ai/anthropic-vertex 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@core-ai/anthropic-vertex 可以商用吗?

@core-ai/anthropic-vertex 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@core-ai/anthropic-vertex 的下载量有多少?

根据 npm 官方下载统计,@core-ai/anthropic-vertex 在 2026/10/11 – 2026/11/09 这 30 天内被下载 4,509 次,日均约 150 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@core-ai/anthropic-vertex 还在维护吗?

最新版本 0.38.0 发布于 2026/11/06(4 天前);至今共发布 30 个版本,其中过去 12 个月发布了 30 个;首次发布于 2026/07/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。