@core-ai/人类顶点
Vertex AI Anthropic(克洛德)供应商软件包 @core-ai/core-ai它使用 @anthropic-ai/vertex-sdk 客户端并分享其请求、流线、工具调用、结构化输出和推理行为 @core-ai/anthropic。 。 。 .
安装
npm install @core-ai/core-ai @core-ai/anthropic-vertex zod
使用量
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);
认证
默认情况下,提供者使用 Google 应用程序默认证书( ADC)数字 :
const anthropicVertex = createAnthropicVertex({
projectId: process.env.GOOGLE_VERTEX_PROJECT,
region: 'europe-west1',
});
使用明确的服务账户进行认证,将其 JSON 密钥解析后作为 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),
});
您也可以插入预配置客户端( 例如自定义) AnthropicVertex 例如,或用窃听器进行测试:
import { AnthropicVertex } from '@anthropic-ai/vertex-sdk';
const anthropicVertex = createAnthropicVertex({
client: new AnthropicVertex({ projectId: 'my-project', region: 'eu' }),
});
示范身份证和区域
通过 Vertex 型号 ID (如 Vertex AI 模拟花园改为: chatModel(). 模型的可用性和命名因地区而异——例如,一些克洛德模型只发布到Vertex AI的 eu 多区域,而其他的则发布到特定区域的终点,例如: europe-west1。由于一个供应商实例针对一个单一区域,如果需要访问不同区域托管的模型,则创建单独的供应商:
const anthropicVertexEu = createAnthropicVertex({
projectId: process.env.GOOGLE_VERTEX_PROJECT,
region: 'eu',
});
const anthropicVertexEuWest1 = createAnthropicVertex({
projectId: process.env.GOOGLE_VERTEX_PROJECT,
region: 'europe-west1',
});
此软件包仅支持聊天模式 .
洞穴: 通过未转换的Vertex模型id(例如.
claude-sonnet-4-6)而不是一个版本被固定的id(例如.claude-sonnet-4-6@20250929合理努力和限制采样能力检测(getAnthropicModelCapabilities还有朋友@core-ai/anthropic)只识别出今天未被转录的形式,因此一个版本被固定的id默默地倒回了标准的能力而不是模型的实际能力.
供应商选项和模型能力
此提供者分享其请求、流线和推理行为 @core-ai/anthropic. 供求办法anthropicGenerateProviderOptionsSchema),推理元数据类型(AnthropicReasoningMetadata)和示范能力帮助者(getAnthropicModelCapabilities可从下列网址获取: @core-ai/anthropic 并同样适用于由Vertex公司托管的克洛德模型.