@core-ai/anthropic-vertex 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +87 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +43 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Omnifact (https://omnifact.ai)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# @core-ai/anthropic-vertex
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@core-ai/anthropic-vertex)
|
|
4
|
+
|
|
5
|
+
Vertex AI Anthropic (Claude) provider package for `@core-ai/core-ai`. It uses the [`@anthropic-ai/vertex-sdk`](https://www.npmjs.com/package/@anthropic-ai/vertex-sdk) client and shares its request, streaming, tool-calling, structured-output, and reasoning behavior with `@core-ai/anthropic`.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @core-ai/core-ai @core-ai/anthropic-vertex zod
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { generate } from '@core-ai/core-ai';
|
|
17
|
+
import { createAnthropicVertex } from '@core-ai/anthropic-vertex';
|
|
18
|
+
|
|
19
|
+
const anthropicVertex = createAnthropicVertex({
|
|
20
|
+
projectId: process.env.GOOGLE_VERTEX_PROJECT,
|
|
21
|
+
region: 'europe-west1',
|
|
22
|
+
});
|
|
23
|
+
const model = anthropicVertex.chatModel('claude-sonnet-4-6');
|
|
24
|
+
|
|
25
|
+
const result = await generate({
|
|
26
|
+
model,
|
|
27
|
+
messages: [{ role: 'user', content: 'Hello!' }],
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
console.log(result.content);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Authentication
|
|
34
|
+
|
|
35
|
+
By default, the provider uses [Google Application Default Credentials (ADC)](https://cloud.google.com/docs/authentication/application-default-credentials):
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
const anthropicVertex = createAnthropicVertex({
|
|
39
|
+
projectId: process.env.GOOGLE_VERTEX_PROJECT,
|
|
40
|
+
region: 'europe-west1',
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
To authenticate with an explicit service account instead, parse its JSON key and pass it as `credentials`:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
const anthropicVertex = createAnthropicVertex({
|
|
48
|
+
projectId: process.env.GOOGLE_VERTEX_PROJECT,
|
|
49
|
+
region: 'europe-west1',
|
|
50
|
+
credentials: JSON.parse(
|
|
51
|
+
process.env.GOOGLE_APPLICATION_CREDENTIALS_JSON ?? ''
|
|
52
|
+
),
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
You can also inject a preconfigured client (for example a custom `AnthropicVertex` instance, or one wired up for testing):
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import { AnthropicVertex } from '@anthropic-ai/vertex-sdk';
|
|
60
|
+
|
|
61
|
+
const anthropicVertex = createAnthropicVertex({
|
|
62
|
+
client: new AnthropicVertex({ projectId: 'my-project', region: 'eu' }),
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Model IDs and regions
|
|
67
|
+
|
|
68
|
+
Pass the Vertex model ID (as listed in the [Vertex AI Model Garden](https://console.cloud.google.com/vertex-ai/publishers/anthropic/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:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
const anthropicVertexEu = createAnthropicVertex({
|
|
72
|
+
projectId: process.env.GOOGLE_VERTEX_PROJECT,
|
|
73
|
+
region: 'eu',
|
|
74
|
+
});
|
|
75
|
+
const anthropicVertexEuWest1 = createAnthropicVertex({
|
|
76
|
+
projectId: process.env.GOOGLE_VERTEX_PROJECT,
|
|
77
|
+
region: 'europe-west1',
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
This package supports chat models only.
|
|
82
|
+
|
|
83
|
+
> **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.
|
|
84
|
+
|
|
85
|
+
## Provider options and model capabilities
|
|
86
|
+
|
|
87
|
+
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.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ChatModel } from '@core-ai/core-ai';
|
|
2
|
+
import { AnthropicChatClient } from '@core-ai/anthropic';
|
|
3
|
+
|
|
4
|
+
type AnthropicVertexServiceAccountCredentials = Record<string, unknown>;
|
|
5
|
+
type AnthropicVertexProviderOptions = {
|
|
6
|
+
projectId?: string;
|
|
7
|
+
region?: string;
|
|
8
|
+
credentials?: AnthropicVertexServiceAccountCredentials;
|
|
9
|
+
client?: AnthropicChatClient;
|
|
10
|
+
defaultMaxTokens?: number;
|
|
11
|
+
};
|
|
12
|
+
type AnthropicVertexProvider = {
|
|
13
|
+
chatModel(modelId: string): ChatModel;
|
|
14
|
+
};
|
|
15
|
+
declare function createAnthropicVertex(options?: AnthropicVertexProviderOptions): AnthropicVertexProvider;
|
|
16
|
+
|
|
17
|
+
export { type AnthropicVertexProvider, type AnthropicVertexProviderOptions, type AnthropicVertexServiceAccountCredentials, createAnthropicVertex };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// src/provider.ts
|
|
2
|
+
import { AnthropicVertex } from "@anthropic-ai/vertex-sdk";
|
|
3
|
+
import {
|
|
4
|
+
createAnthropicChatProvider
|
|
5
|
+
} from "@core-ai/anthropic";
|
|
6
|
+
import { GoogleAuth } from "google-auth-library";
|
|
7
|
+
var PROVIDER_ID = "anthropic-vertex";
|
|
8
|
+
var CLOUD_PLATFORM_AUTH_SCOPE = "https://www.googleapis.com/auth/cloud-platform";
|
|
9
|
+
function createAnthropicVertex(options = {}) {
|
|
10
|
+
const client = options.client ?? createAnthropicVertexClient(options);
|
|
11
|
+
return createAnthropicChatProvider(
|
|
12
|
+
{ client, defaultMaxTokens: options.defaultMaxTokens },
|
|
13
|
+
PROVIDER_ID
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
function createAnthropicVertexClient(options) {
|
|
17
|
+
if (!options.projectId) {
|
|
18
|
+
throw new Error("createAnthropicVertex: projectId is required.");
|
|
19
|
+
}
|
|
20
|
+
if (!options.region) {
|
|
21
|
+
throw new Error("createAnthropicVertex: region is required.");
|
|
22
|
+
}
|
|
23
|
+
const googleAuth = options.credentials ? new GoogleAuth({
|
|
24
|
+
credentials: options.credentials,
|
|
25
|
+
scopes: [CLOUD_PLATFORM_AUTH_SCOPE]
|
|
26
|
+
}) : void 0;
|
|
27
|
+
return new AnthropicVertex({
|
|
28
|
+
projectId: options.projectId,
|
|
29
|
+
region: options.region,
|
|
30
|
+
...googleAuth ? {
|
|
31
|
+
// `@anthropic-ai/vertex-sdk` bundles its own
|
|
32
|
+
// `google-auth-library` dependency, so the SDK's `GoogleAuth`
|
|
33
|
+
// type is nominally incompatible with the workspace copy
|
|
34
|
+
// because of private fields. At runtime, the SDK only uses
|
|
35
|
+
// the public auth methods, so we cast at the package
|
|
36
|
+
// boundary.
|
|
37
|
+
googleAuth
|
|
38
|
+
} : {}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
createAnthropicVertex
|
|
43
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@core-ai/anthropic-vertex",
|
|
3
|
+
"version": "0.14.0",
|
|
4
|
+
"description": "Vertex AI Anthropic (Claude) provider package for @core-ai/core-ai",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Omnifact (https://omnifact.ai)",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/agdevhq/core-ai.git",
|
|
10
|
+
"directory": "packages/anthropic-vertex"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"llm",
|
|
14
|
+
"ai",
|
|
15
|
+
"anthropic",
|
|
16
|
+
"claude",
|
|
17
|
+
"vertex",
|
|
18
|
+
"vertex-ai",
|
|
19
|
+
"google-cloud",
|
|
20
|
+
"provider",
|
|
21
|
+
"sdk"
|
|
22
|
+
],
|
|
23
|
+
"type": "module",
|
|
24
|
+
"main": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js",
|
|
30
|
+
"require": "./dist/index.js",
|
|
31
|
+
"default": "./dist/index.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"README.md",
|
|
37
|
+
"LICENSE"
|
|
38
|
+
],
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public",
|
|
41
|
+
"provenance": true
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsup",
|
|
45
|
+
"lint": "eslint src/ --max-warnings 0",
|
|
46
|
+
"check-types": "tsc --noEmit",
|
|
47
|
+
"test": "vitest run",
|
|
48
|
+
"test:watch": "vitest"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@anthropic-ai/vertex-sdk": "^0.19.0",
|
|
52
|
+
"@core-ai/anthropic": "^0.14.0",
|
|
53
|
+
"@core-ai/core-ai": "^0.14.0",
|
|
54
|
+
"google-auth-library": "^10.2.0"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"zod": "^4.0.0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@core-ai/eslint-config": "*",
|
|
61
|
+
"@core-ai/testing": "*",
|
|
62
|
+
"@core-ai/typescript-config": "*",
|
|
63
|
+
"typescript": "^5.7.3",
|
|
64
|
+
"vitest": "^3.2.4"
|
|
65
|
+
}
|
|
66
|
+
}
|