@anthropic-ai/google-cloud-sdk

中文文档
1.1.3发布于 2026/11/05Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 4195

The official TypeScript library for Claude Models on Google Cloud (Anthropic managed)

原始使用文档
文档目录8 节
  1. Installation
  2. Usage
  3. Configuration
  4. Authentication
  5. Application Default Credentials
  6. Custom Google credentials
  7. Bearer token provider
  8. Pre-authenticated proxy

Anthropic SDK for Claude Models on Google Cloud (Anthropic managed)

NPM version

This library provides convenient access to Claude Models on Google Cloud (Anthropic managed) — the first-party Claude API served through Google Cloud. It exposes the full Anthropic API surface and authenticates with a Google bearer token.

For the direct Claude API at api.anthropic.com, see @anthropic-ai/sdk. For the :rawPredict publisher-model API, see @anthropic-ai/vertex-sdk.

Installation

npm install @anthropic-ai/google-cloud-sdk

Usage

import { AnthropicGoogleCloud } from '@anthropic-ai/google-cloud-sdk';

const client = new AnthropicGoogleCloud({
  project: 'my-gcp-project', // or ANTHROPIC_GOOGLE_CLOUD_PROJECT
  workspaceId: 'wrkspc_...', // or ANTHROPIC_GOOGLE_CLOUD_WORKSPACE_ID
});

const message = await client.messages.create({
  model: 'claude-haiku-5-5',
  max_tokens: 1024,
  messages: [{ role: 'user', content: 'Hello, Claude!' }],
});

console.log(message.content);

See examples/ for runnable basic and streaming examples.

Configuration

OptionEnvironment variableNotes
projectANTHROPIC_GOOGLE_CLOUD_PROJECTGCP project id, used to derive the base URL. When neither is set (and no baseURL is given), it is resolved lazily from your Google credentials at or before the first request.
locationANTHROPIC_GOOGLE_CLOUD_LOCATIONGCP location. Optional — defaults to global.
workspaceIdANTHROPIC_GOOGLE_CLOUD_WORKSPACE_IDRequired when the base URL is derived, except for organization-level routes (/v1/organizations/* and the /v1/user_profiles routes), which need none.
baseURLANTHROPIC_GOOGLE_CLOUD_BASE_URLOverrides the base URL derived from project + location + workspaceId.
skipAuth—Skips the bearer token, for gateways that authenticate upstream.

When the project is resolved lazily, await client.ready to fail fast on misconfiguration instead of waiting for the first request.

Authentication

Authentication uses a Google bearer token, resolved by precedence — an explicit bearerTokenProvider, then a google-auth-library googleAuth / authClient, then Application Default Credentials.

This client never uses the base SDK's Anthropic credential sources: ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN, and profile config files are all ignored, and the only Authorization header it sends is the Google bearer token.

Application Default Credentials

Set up ADC (e.g. gcloud auth application-default login) and the client fetches and refreshes a bearer token for you, no auth options needed.

Custom Google credentials

Pass a GoogleAuth or AuthClient to override the default credential chain (for example to use impersonated credentials):

import { AnthropicGoogleCloud } from '@anthropic-ai/google-cloud-sdk';
import { GoogleAuth } from 'google-auth-library';

const client = new AnthropicGoogleCloud({
  project: 'my-gcp-project',
  workspaceId: 'wrkspc_...',
  googleAuth: new GoogleAuth({ scopes: 'https://www.googleapis.com/auth/cloud-platform' }),
});

Bearer token provider

If you already mint Google access tokens yourself, supply a bearerTokenProvider. It is invoked on every request and takes precedence over googleAuth / authClient and ADC:

const client = new AnthropicGoogleCloud({
  project: 'my-gcp-project',
  workspaceId: 'wrkspc_...',
  bearerTokenProvider: async () => myTokenSource.getAccessToken(),
});

Pre-authenticated proxy

If a gateway or proxy authenticates upstream on your behalf, set skipAuth to skip the bearer token (with an explicit baseURL, no workspaceId is needed):

const client = new AnthropicGoogleCloud({
  baseURL: 'https://my-proxy.example.com',
  skipAuth: true,
});

版本与发布记录

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

版本发布日期距今
1.1.3latest2026/11/051 天前
1.1.22026/11/033 天前
1.1.12026/10/2413 天前
1.1.02026/10/2313 天前
1.0.02026/10/2115 天前
0.2.02026/10/2116 天前

关于 @anthropic-ai/google-cloud-sdk 的常见问题

@anthropic-ai/google-cloud-sdk 是什么?

The official TypeScript library for Claude Models on Google Cloud (Anthropic managed)

如何安装 @anthropic-ai/google-cloud-sdk?

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

@anthropic-ai/google-cloud-sdk 支持 TypeScript 吗?

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

@anthropic-ai/google-cloud-sdk 支持 ESM 还是 CommonJS?

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

@anthropic-ai/google-cloud-sdk 可以商用吗?

@anthropic-ai/google-cloud-sdk 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@anthropic-ai/google-cloud-sdk 的下载量有多少?

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

@anthropic-ai/google-cloud-sdk 还在维护吗?

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