@ai-sdk/google-vertex 5.0.0-beta.63 → 5.0.0-beta.64
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/CHANGELOG.md +8 -0
- package/dist/anthropic/edge/index.js +1 -1
- package/dist/edge/index.js +1 -1
- package/dist/index.js +1 -1
- package/dist/maas/edge/index.js +1 -1
- package/dist/xai/edge/index.d.ts +92 -0
- package/dist/xai/edge/index.js +259 -0
- package/dist/xai/edge/index.js.map +1 -0
- package/dist/xai/index.d.ts +76 -0
- package/dist/xai/index.js +164 -0
- package/dist/xai/index.js.map +1 -0
- package/docs/16-google-vertex.mdx +182 -3
- package/package.json +15 -3
- package/src/xai/edge/google-vertex-xai-provider-edge.ts +61 -0
- package/src/xai/edge/index.ts +9 -0
- package/src/xai/google-vertex-xai-options.ts +7 -0
- package/src/xai/google-vertex-xai-provider-node.ts +60 -0
- package/src/xai/google-vertex-xai-provider.ts +212 -0
- package/src/xai/index.ts +9 -0
- package/xai/edge.d.ts +1 -0
- package/xai/index.d.ts +1 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// src/xai/google-vertex-xai-provider-node.ts
|
|
2
|
+
import { resolve } from "@ai-sdk/provider-utils";
|
|
3
|
+
|
|
4
|
+
// src/google-vertex-auth-google-auth-library.ts
|
|
5
|
+
import { GoogleAuth } from "google-auth-library";
|
|
6
|
+
var authInstance = null;
|
|
7
|
+
var authOptions = null;
|
|
8
|
+
function getAuth(options) {
|
|
9
|
+
if (!authInstance || options !== authOptions) {
|
|
10
|
+
authInstance = new GoogleAuth({
|
|
11
|
+
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
|
|
12
|
+
...options
|
|
13
|
+
});
|
|
14
|
+
authOptions = options;
|
|
15
|
+
}
|
|
16
|
+
return authInstance;
|
|
17
|
+
}
|
|
18
|
+
async function generateAuthToken(options) {
|
|
19
|
+
const auth = getAuth(options || {});
|
|
20
|
+
const client = await auth.getClient();
|
|
21
|
+
const token = await client.getAccessToken();
|
|
22
|
+
return (token == null ? void 0 : token.token) || null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// src/xai/google-vertex-xai-provider.ts
|
|
26
|
+
import {
|
|
27
|
+
NoSuchModelError
|
|
28
|
+
} from "@ai-sdk/provider";
|
|
29
|
+
import {
|
|
30
|
+
createOpenAICompatible
|
|
31
|
+
} from "@ai-sdk/openai-compatible";
|
|
32
|
+
import {
|
|
33
|
+
loadOptionalSetting,
|
|
34
|
+
loadSetting,
|
|
35
|
+
withoutTrailingSlash
|
|
36
|
+
} from "@ai-sdk/provider-utils";
|
|
37
|
+
function convertGoogleVertexXaiUsage(usage) {
|
|
38
|
+
var _a, _b, _c, _d, _e, _f;
|
|
39
|
+
if (usage == null) {
|
|
40
|
+
return {
|
|
41
|
+
inputTokens: {
|
|
42
|
+
total: void 0,
|
|
43
|
+
noCache: void 0,
|
|
44
|
+
cacheRead: void 0,
|
|
45
|
+
cacheWrite: void 0
|
|
46
|
+
},
|
|
47
|
+
outputTokens: {
|
|
48
|
+
total: void 0,
|
|
49
|
+
text: void 0,
|
|
50
|
+
reasoning: void 0
|
|
51
|
+
},
|
|
52
|
+
raw: void 0
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const promptTokens = (_a = usage.prompt_tokens) != null ? _a : 0;
|
|
56
|
+
const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
|
|
57
|
+
const cacheReadTokens = (_d = (_c = usage.prompt_tokens_details) == null ? void 0 : _c.cached_tokens) != null ? _d : 0;
|
|
58
|
+
const reasoningTokens = (_f = (_e = usage.completion_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : 0;
|
|
59
|
+
return {
|
|
60
|
+
inputTokens: {
|
|
61
|
+
total: promptTokens,
|
|
62
|
+
noCache: promptTokens - cacheReadTokens,
|
|
63
|
+
cacheRead: cacheReadTokens,
|
|
64
|
+
cacheWrite: void 0
|
|
65
|
+
},
|
|
66
|
+
outputTokens: {
|
|
67
|
+
total: completionTokens + reasoningTokens,
|
|
68
|
+
text: completionTokens,
|
|
69
|
+
reasoning: reasoningTokens
|
|
70
|
+
},
|
|
71
|
+
raw: usage
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function transformGoogleVertexXaiRequestBody(args) {
|
|
75
|
+
const { reasoning_effort: _reasoningEffort, ...rest } = args;
|
|
76
|
+
return rest;
|
|
77
|
+
}
|
|
78
|
+
function createGoogleVertexXai(options = {}) {
|
|
79
|
+
const loadLocation = () => loadOptionalSetting({
|
|
80
|
+
settingValue: options.location,
|
|
81
|
+
environmentVariableName: "GOOGLE_VERTEX_LOCATION"
|
|
82
|
+
});
|
|
83
|
+
const loadProject = () => loadSetting({
|
|
84
|
+
settingValue: options.project,
|
|
85
|
+
settingName: "project",
|
|
86
|
+
environmentVariableName: "GOOGLE_VERTEX_PROJECT",
|
|
87
|
+
description: "Google Vertex project"
|
|
88
|
+
});
|
|
89
|
+
const constructBaseURL = () => {
|
|
90
|
+
var _a;
|
|
91
|
+
const projectId = loadProject();
|
|
92
|
+
const location = (_a = loadLocation()) != null ? _a : "global";
|
|
93
|
+
return `https://aiplatform.googleapis.com/v1/projects/${projectId}/locations/${location}/endpoints/openapi`;
|
|
94
|
+
};
|
|
95
|
+
const loadBaseURL = () => {
|
|
96
|
+
var _a;
|
|
97
|
+
return withoutTrailingSlash((_a = options.baseURL) != null ? _a : "") || constructBaseURL();
|
|
98
|
+
};
|
|
99
|
+
let cachedProvider;
|
|
100
|
+
const getProvider = () => cachedProvider != null ? cachedProvider : cachedProvider = createOpenAICompatible({
|
|
101
|
+
name: "googleVertex.xai",
|
|
102
|
+
baseURL: loadBaseURL(),
|
|
103
|
+
fetch: options.fetch,
|
|
104
|
+
includeUsage: true,
|
|
105
|
+
supportsStructuredOutputs: true,
|
|
106
|
+
supportedUrls: () => ({
|
|
107
|
+
"image/*": [/^https?:\/\/.*$/]
|
|
108
|
+
}),
|
|
109
|
+
transformRequestBody: transformGoogleVertexXaiRequestBody,
|
|
110
|
+
convertUsage: convertGoogleVertexXaiUsage
|
|
111
|
+
});
|
|
112
|
+
const createChatModel = (modelId) => getProvider().languageModel(modelId);
|
|
113
|
+
const provider = function(modelId) {
|
|
114
|
+
if (new.target) {
|
|
115
|
+
throw new Error(
|
|
116
|
+
"The Google Vertex xAI model function cannot be called with the new keyword."
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
return createChatModel(modelId);
|
|
120
|
+
};
|
|
121
|
+
provider.specificationVersion = "v4";
|
|
122
|
+
provider.languageModel = createChatModel;
|
|
123
|
+
provider.chatModel = (modelId) => getProvider().chatModel(modelId);
|
|
124
|
+
provider.embeddingModel = (modelId) => {
|
|
125
|
+
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
126
|
+
};
|
|
127
|
+
provider.textEmbeddingModel = provider.embeddingModel;
|
|
128
|
+
provider.imageModel = (modelId) => {
|
|
129
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
130
|
+
};
|
|
131
|
+
return provider;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/xai/google-vertex-xai-provider-node.ts
|
|
135
|
+
function createGoogleVertexXai2(options = {}) {
|
|
136
|
+
const customFetch = async (url, init) => {
|
|
137
|
+
var _a;
|
|
138
|
+
const token = await generateAuthToken(options.googleAuthOptions);
|
|
139
|
+
const resolvedHeaders = await resolve(options.headers);
|
|
140
|
+
const authHeaders = {
|
|
141
|
+
...resolvedHeaders,
|
|
142
|
+
Authorization: `Bearer ${token}`
|
|
143
|
+
};
|
|
144
|
+
const fetchInit = {
|
|
145
|
+
...init,
|
|
146
|
+
headers: {
|
|
147
|
+
...init == null ? void 0 : init.headers,
|
|
148
|
+
...authHeaders
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
return ((_a = options.fetch) != null ? _a : fetch)(url, fetchInit);
|
|
152
|
+
};
|
|
153
|
+
return createGoogleVertexXai({
|
|
154
|
+
...options,
|
|
155
|
+
fetch: customFetch,
|
|
156
|
+
headers: void 0
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
var googleVertexXai = createGoogleVertexXai2();
|
|
160
|
+
export {
|
|
161
|
+
createGoogleVertexXai2 as createGoogleVertexXai,
|
|
162
|
+
googleVertexXai
|
|
163
|
+
};
|
|
164
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/xai/google-vertex-xai-provider-node.ts","../../src/google-vertex-auth-google-auth-library.ts","../../src/xai/google-vertex-xai-provider.ts"],"sourcesContent":["import { resolve, type FetchFunction } from '@ai-sdk/provider-utils';\nimport type { GoogleAuthOptions } from 'google-auth-library';\nimport { generateAuthToken } from '../google-vertex-auth-google-auth-library';\nimport {\n createGoogleVertexXai as createGoogleVertexXaiOriginal,\n type GoogleVertexXaiProvider,\n type GoogleVertexXaiProviderSettings as GoogleVertexXaiProviderSettingsOriginal,\n} from './google-vertex-xai-provider';\nexport type { GoogleVertexXaiProvider };\n\nexport interface GoogleVertexXaiProviderSettings extends GoogleVertexXaiProviderSettingsOriginal {\n /**\n * Optional. The Authentication options provided by google-auth-library.\n * Complete list of authentication options is documented in the\n * GoogleAuthOptions interface:\n * https://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/googleauth.ts.\n */\n googleAuthOptions?: GoogleAuthOptions;\n}\n\n/**\n * Create a Google Vertex AI xAI provider instance for Node.js.\n * Uses the OpenAI-compatible Chat Completions API for Grok partner models.\n * Automatically handles Google Cloud authentication.\n *\n * @see https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/grok\n */\nexport function createGoogleVertexXai(\n options: GoogleVertexXaiProviderSettings = {},\n): GoogleVertexXaiProvider {\n const customFetch: FetchFunction = async (url, init) => {\n const token = await generateAuthToken(options.googleAuthOptions);\n const resolvedHeaders = await resolve(options.headers);\n const authHeaders = {\n ...resolvedHeaders,\n Authorization: `Bearer ${token}`,\n };\n\n const fetchInit = {\n ...init,\n headers: {\n ...init?.headers,\n ...authHeaders,\n },\n };\n\n return (options.fetch ?? fetch)(url, fetchInit);\n };\n\n return createGoogleVertexXaiOriginal({\n ...options,\n fetch: customFetch,\n headers: undefined,\n });\n}\n\n/**\n * Default Google Vertex AI xAI provider instance for Node.js.\n */\nexport const googleVertexXai = createGoogleVertexXai();\n","import { GoogleAuth, type GoogleAuthOptions } from 'google-auth-library';\nlet authInstance: GoogleAuth | null = null;\nlet authOptions: GoogleAuthOptions | null = null;\n\nfunction getAuth(options: GoogleAuthOptions) {\n if (!authInstance || options !== authOptions) {\n authInstance = new GoogleAuth({\n scopes: ['https://www.googleapis.com/auth/cloud-platform'],\n ...options,\n });\n authOptions = options;\n }\n return authInstance;\n}\n\nexport async function generateAuthToken(options?: GoogleAuthOptions) {\n const auth = getAuth(options || {});\n const client = await auth.getClient();\n const token = await client.getAccessToken();\n return token?.token || null;\n}\n\n// For testing purposes only\nexport function _resetAuthInstance() {\n authInstance = null;\n}\n","import {\n NoSuchModelError,\n type LanguageModelV4,\n type LanguageModelV4Usage,\n type ProviderV4,\n} from '@ai-sdk/provider';\nimport {\n createOpenAICompatible,\n type OpenAICompatibleProvider,\n} from '@ai-sdk/openai-compatible';\nimport {\n loadOptionalSetting,\n loadSetting,\n withoutTrailingSlash,\n type FetchFunction,\n type Resolvable,\n} from '@ai-sdk/provider-utils';\nimport type { GoogleVertexXaiModelId } from './google-vertex-xai-options';\n\nexport interface GoogleVertexXaiProvider extends ProviderV4 {\n /**\n * Creates a model for text generation.\n */\n (modelId: GoogleVertexXaiModelId): LanguageModelV4;\n\n /**\n * Creates a model for text generation.\n */\n languageModel(modelId: GoogleVertexXaiModelId): LanguageModelV4;\n\n /**\n * Creates a chat model for text generation.\n */\n chatModel(modelId: GoogleVertexXaiModelId): LanguageModelV4;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nexport interface GoogleVertexXaiProviderSettings {\n /**\n * Google Cloud project ID. Defaults to the value of the `GOOGLE_VERTEX_PROJECT` environment variable.\n */\n project?: string;\n\n /**\n * Google Cloud location/region. Defaults to the value of the `GOOGLE_VERTEX_LOCATION` environment variable.\n * Use 'global' for the global endpoint.\n */\n location?: string;\n\n /**\n * Base URL for the API calls. If not provided, will be constructed from project and location.\n */\n baseURL?: string;\n\n /**\n * Headers to use for requests. Can be:\n * - A headers object\n * - A Promise that resolves to a headers object\n * - A function that returns a headers object\n * - A function that returns a Promise of a headers object\n */\n headers?: Resolvable<Record<string, string | undefined>>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\ntype GoogleVertexXaiUsage =\n | {\n prompt_tokens?: number | null;\n completion_tokens?: number | null;\n prompt_tokens_details?: {\n cached_tokens?: number | null;\n } | null;\n completion_tokens_details?: {\n reasoning_tokens?: number | null;\n } | null;\n }\n | undefined\n | null;\n\nfunction convertGoogleVertexXaiUsage(\n usage: GoogleVertexXaiUsage,\n): LanguageModelV4Usage {\n if (usage == null) {\n return {\n inputTokens: {\n total: undefined,\n noCache: undefined,\n cacheRead: undefined,\n cacheWrite: undefined,\n },\n outputTokens: {\n total: undefined,\n text: undefined,\n reasoning: undefined,\n },\n raw: undefined,\n };\n }\n\n const promptTokens = usage.prompt_tokens ?? 0;\n const completionTokens = usage.completion_tokens ?? 0;\n const cacheReadTokens = usage.prompt_tokens_details?.cached_tokens ?? 0;\n const reasoningTokens =\n usage.completion_tokens_details?.reasoning_tokens ?? 0;\n\n return {\n inputTokens: {\n total: promptTokens,\n noCache: promptTokens - cacheReadTokens,\n cacheRead: cacheReadTokens,\n cacheWrite: undefined,\n },\n outputTokens: {\n total: completionTokens + reasoningTokens,\n text: completionTokens,\n reasoning: reasoningTokens,\n },\n raw: usage,\n };\n}\n\nfunction transformGoogleVertexXaiRequestBody(args: Record<string, any>) {\n const { reasoning_effort: _reasoningEffort, ...rest } = args;\n return rest;\n}\n\n/**\n * Create a Google Vertex AI xAI provider instance.\n * Uses the OpenAI-compatible Chat Completions API for Grok partner models.\n *\n * @see https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/grok\n */\nexport function createGoogleVertexXai(\n options: GoogleVertexXaiProviderSettings = {},\n): GoogleVertexXaiProvider {\n const loadLocation = () =>\n loadOptionalSetting({\n settingValue: options.location,\n environmentVariableName: 'GOOGLE_VERTEX_LOCATION',\n });\n\n const loadProject = () =>\n loadSetting({\n settingValue: options.project,\n settingName: 'project',\n environmentVariableName: 'GOOGLE_VERTEX_PROJECT',\n description: 'Google Vertex project',\n });\n\n const constructBaseURL = () => {\n const projectId = loadProject();\n const location = loadLocation() ?? 'global';\n\n return `https://aiplatform.googleapis.com/v1/projects/${projectId}/locations/${location}/endpoints/openapi`;\n };\n\n const loadBaseURL = () =>\n withoutTrailingSlash(options.baseURL ?? '') || constructBaseURL();\n\n let cachedProvider:\n | OpenAICompatibleProvider<GoogleVertexXaiModelId, string, string, string>\n | undefined;\n const getProvider = () =>\n (cachedProvider ??= createOpenAICompatible({\n name: 'googleVertex.xai',\n baseURL: loadBaseURL(),\n fetch: options.fetch,\n includeUsage: true,\n supportsStructuredOutputs: true,\n supportedUrls: () => ({\n 'image/*': [/^https?:\\/\\/.*$/],\n }),\n transformRequestBody: transformGoogleVertexXaiRequestBody,\n convertUsage: convertGoogleVertexXaiUsage,\n }));\n\n const createChatModel = (modelId: GoogleVertexXaiModelId) =>\n getProvider().languageModel(modelId);\n\n const provider = function (modelId: GoogleVertexXaiModelId) {\n if (new.target) {\n throw new Error(\n 'The Google Vertex xAI model function cannot be called with the new keyword.',\n );\n }\n\n return createChatModel(modelId);\n };\n\n provider.specificationVersion = 'v4' as const;\n provider.languageModel = createChatModel;\n provider.chatModel = (modelId: GoogleVertexXaiModelId) =>\n getProvider().chatModel(modelId);\n provider.embeddingModel = (modelId: string): never => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n };\n provider.textEmbeddingModel = provider.embeddingModel;\n provider.imageModel = (modelId: string): never => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n return provider;\n}\n"],"mappings":"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","names":["createGoogleVertexXai"]}
|
|
@@ -5,7 +5,7 @@ description: Learn how to use the Google Vertex AI provider.
|
|
|
5
5
|
|
|
6
6
|
# Google Vertex Provider
|
|
7
7
|
|
|
8
|
-
The Google Vertex provider for the [AI SDK](/docs) contains language model support for the [Google Vertex AI](https://cloud.google.com/vertex-ai) APIs. This includes support for [Google's Gemini models](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models), [Anthropic's Claude partner models](https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude), and [MaaS (Model as a Service) open models](https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models).
|
|
8
|
+
The Google Vertex provider for the [AI SDK](/docs) contains language model support for the [Google Vertex AI](https://cloud.google.com/vertex-ai) APIs. This includes support for [Google's Gemini models](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models), [Anthropic's Claude partner models](https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude), [xAI's Grok partner models](https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/grok), and [MaaS (Model as a Service) open models](https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models).
|
|
9
9
|
|
|
10
10
|
<Note>
|
|
11
11
|
The Google Vertex provider is compatible with both Node.js and Edge runtimes.
|
|
@@ -18,7 +18,7 @@ The Google Vertex provider for the [AI SDK](/docs) contains language model suppo
|
|
|
18
18
|
|
|
19
19
|
## Setup
|
|
20
20
|
|
|
21
|
-
The Google Vertex and Google Vertex
|
|
21
|
+
The Google Vertex, Google Vertex Anthropic, Google Vertex xAI, and Google Vertex MaaS providers are available in the `@ai-sdk/google-vertex` module. You can install it with
|
|
22
22
|
|
|
23
23
|
<Tabs items={['pnpm', 'npm', 'yarn', 'bun']}>
|
|
24
24
|
<Tab>
|
|
@@ -1579,7 +1579,7 @@ console.log(
|
|
|
1579
1579
|
|
|
1580
1580
|
You can also use cache control on system messages by providing multiple system messages at the head of your messages array:
|
|
1581
1581
|
|
|
1582
|
-
```ts highlight="3,9
|
|
1582
|
+
```ts highlight="3,7-9"
|
|
1583
1583
|
const result = await generateText({
|
|
1584
1584
|
model: vertexAnthropic('claude-3-5-sonnet-20240620'),
|
|
1585
1585
|
messages: [
|
|
@@ -1782,6 +1782,185 @@ See also [Anthropic Model Comparison](https://docs.anthropic.com/en/docs/about-c
|
|
|
1782
1782
|
model ID as a string if needed.
|
|
1783
1783
|
</Note>
|
|
1784
1784
|
|
|
1785
|
+
## Google Vertex xAI Provider Usage
|
|
1786
|
+
|
|
1787
|
+
The Google Vertex xAI provider offers support for xAI's Grok partner models through the Google Vertex AI OpenAI-compatible Chat Completions API.
|
|
1788
|
+
|
|
1789
|
+
For more information, see the [Vertex AI Grok documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/grok).
|
|
1790
|
+
|
|
1791
|
+
### Provider Instance
|
|
1792
|
+
|
|
1793
|
+
You can import the default provider instance `googleVertexXai` from `@ai-sdk/google-vertex/xai`:
|
|
1794
|
+
|
|
1795
|
+
```typescript
|
|
1796
|
+
import { googleVertexXai } from '@ai-sdk/google-vertex/xai';
|
|
1797
|
+
```
|
|
1798
|
+
|
|
1799
|
+
If you need a customized setup, you can import `createGoogleVertexXai` from `@ai-sdk/google-vertex/xai` and create a provider instance with your settings:
|
|
1800
|
+
|
|
1801
|
+
```typescript
|
|
1802
|
+
import { createGoogleVertexXai } from '@ai-sdk/google-vertex/xai';
|
|
1803
|
+
|
|
1804
|
+
const googleVertexXai = createGoogleVertexXai({
|
|
1805
|
+
project: 'my-project', // optional
|
|
1806
|
+
location: 'global', // optional, defaults to 'global'
|
|
1807
|
+
});
|
|
1808
|
+
```
|
|
1809
|
+
|
|
1810
|
+
#### Node.js Runtime
|
|
1811
|
+
|
|
1812
|
+
For Node.js environments, the Google Vertex xAI provider supports all standard Google Cloud authentication options through the `google-auth-library`:
|
|
1813
|
+
|
|
1814
|
+
```typescript
|
|
1815
|
+
import { createGoogleVertexXai } from '@ai-sdk/google-vertex/xai';
|
|
1816
|
+
|
|
1817
|
+
const googleVertexXai = createGoogleVertexXai({
|
|
1818
|
+
googleAuthOptions: {
|
|
1819
|
+
credentials: {
|
|
1820
|
+
client_email: 'my-email',
|
|
1821
|
+
private_key: 'my-private-key',
|
|
1822
|
+
},
|
|
1823
|
+
},
|
|
1824
|
+
});
|
|
1825
|
+
```
|
|
1826
|
+
|
|
1827
|
+
##### Optional Provider Settings
|
|
1828
|
+
|
|
1829
|
+
- **project** _string_
|
|
1830
|
+
|
|
1831
|
+
The Google Cloud project ID. Defaults to the `GOOGLE_VERTEX_PROJECT` environment variable.
|
|
1832
|
+
|
|
1833
|
+
- **location** _string_
|
|
1834
|
+
|
|
1835
|
+
The Google Cloud location. Grok models are available on the global endpoint. Defaults to the `GOOGLE_VERTEX_LOCATION` environment variable. If not set, defaults to `global`.
|
|
1836
|
+
|
|
1837
|
+
- **googleAuthOptions** _object_
|
|
1838
|
+
|
|
1839
|
+
Optional. The Authentication options used by the [Google Auth Library](https://github.com/googleapis/google-auth-library-nodejs/).
|
|
1840
|
+
|
|
1841
|
+
- **headers** _Resolvable<Record<string, string | undefined>>_
|
|
1842
|
+
|
|
1843
|
+
Headers to include in requests.
|
|
1844
|
+
|
|
1845
|
+
- **fetch** _(input: RequestInfo, init?: RequestInit) => Promise<Response>_
|
|
1846
|
+
|
|
1847
|
+
Custom [fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch) implementation.
|
|
1848
|
+
|
|
1849
|
+
<a id="google-vertex-xai-edge-runtime"></a>
|
|
1850
|
+
|
|
1851
|
+
#### Edge Runtime
|
|
1852
|
+
|
|
1853
|
+
For Edge runtimes, import from `@ai-sdk/google-vertex/xai/edge`:
|
|
1854
|
+
|
|
1855
|
+
```typescript
|
|
1856
|
+
import { googleVertexXai } from '@ai-sdk/google-vertex/xai/edge';
|
|
1857
|
+
```
|
|
1858
|
+
|
|
1859
|
+
```typescript
|
|
1860
|
+
import { createGoogleVertexXai } from '@ai-sdk/google-vertex/xai/edge';
|
|
1861
|
+
|
|
1862
|
+
const googleVertexXai = createGoogleVertexXai({
|
|
1863
|
+
project: 'my-project',
|
|
1864
|
+
location: 'global',
|
|
1865
|
+
});
|
|
1866
|
+
```
|
|
1867
|
+
|
|
1868
|
+
For Edge runtime authentication, set these environment variables:
|
|
1869
|
+
|
|
1870
|
+
- `GOOGLE_CLIENT_EMAIL`
|
|
1871
|
+
- `GOOGLE_PRIVATE_KEY`
|
|
1872
|
+
- `GOOGLE_PRIVATE_KEY_ID` (optional)
|
|
1873
|
+
|
|
1874
|
+
### Language Models
|
|
1875
|
+
|
|
1876
|
+
You can create models using the provider instance. The first argument is the model ID:
|
|
1877
|
+
|
|
1878
|
+
```ts
|
|
1879
|
+
import { googleVertexXai } from '@ai-sdk/google-vertex/xai';
|
|
1880
|
+
import { generateText } from 'ai';
|
|
1881
|
+
|
|
1882
|
+
const { text } = await generateText({
|
|
1883
|
+
model: googleVertexXai('xai/grok-4.1-fast-reasoning'),
|
|
1884
|
+
prompt: 'Invent a new holiday and describe its traditions.',
|
|
1885
|
+
});
|
|
1886
|
+
```
|
|
1887
|
+
|
|
1888
|
+
Streaming is also supported:
|
|
1889
|
+
|
|
1890
|
+
```ts
|
|
1891
|
+
import { googleVertexXai } from '@ai-sdk/google-vertex/xai';
|
|
1892
|
+
import { streamText } from 'ai';
|
|
1893
|
+
|
|
1894
|
+
const result = streamText({
|
|
1895
|
+
model: googleVertexXai('xai/grok-4.1-fast-reasoning'),
|
|
1896
|
+
prompt: 'Invent a new holiday and describe its traditions.',
|
|
1897
|
+
});
|
|
1898
|
+
|
|
1899
|
+
for await (const textPart of result.textStream) {
|
|
1900
|
+
process.stdout.write(textPart);
|
|
1901
|
+
}
|
|
1902
|
+
```
|
|
1903
|
+
|
|
1904
|
+
### Function Calling
|
|
1905
|
+
|
|
1906
|
+
Grok models on Vertex support OpenAI-compatible function calling. You can use AI SDK tools as usual:
|
|
1907
|
+
|
|
1908
|
+
```ts
|
|
1909
|
+
import { googleVertexXai } from '@ai-sdk/google-vertex/xai';
|
|
1910
|
+
import { generateText, tool } from 'ai';
|
|
1911
|
+
import { z } from 'zod';
|
|
1912
|
+
|
|
1913
|
+
const result = await generateText({
|
|
1914
|
+
model: googleVertexXai('xai/grok-4.1-fast-reasoning'),
|
|
1915
|
+
tools: {
|
|
1916
|
+
weather: tool({
|
|
1917
|
+
description: 'Get the weather in a city',
|
|
1918
|
+
inputSchema: z.object({ city: z.string() }),
|
|
1919
|
+
execute: async ({ city }) => `The weather in ${city} is sunny.`,
|
|
1920
|
+
}),
|
|
1921
|
+
},
|
|
1922
|
+
prompt: 'What is the weather in San Francisco?',
|
|
1923
|
+
});
|
|
1924
|
+
```
|
|
1925
|
+
|
|
1926
|
+
### Structured Outputs
|
|
1927
|
+
|
|
1928
|
+
Grok models on Vertex support JSON mode and schema-backed structured outputs:
|
|
1929
|
+
|
|
1930
|
+
```ts
|
|
1931
|
+
import { googleVertexXai } from '@ai-sdk/google-vertex/xai';
|
|
1932
|
+
import { generateText, Output } from 'ai';
|
|
1933
|
+
import { z } from 'zod';
|
|
1934
|
+
|
|
1935
|
+
const result = await generateText({
|
|
1936
|
+
model: googleVertexXai('xai/grok-4.1-fast-reasoning'),
|
|
1937
|
+
output: Output.object({
|
|
1938
|
+
schema: z.object({
|
|
1939
|
+
name: z.string(),
|
|
1940
|
+
date: z.string(),
|
|
1941
|
+
participants: z.array(z.string()),
|
|
1942
|
+
}),
|
|
1943
|
+
}),
|
|
1944
|
+
prompt: 'Alice and Bob are going to a science fair on Friday.',
|
|
1945
|
+
});
|
|
1946
|
+
```
|
|
1947
|
+
|
|
1948
|
+
### Available Models
|
|
1949
|
+
|
|
1950
|
+
The following models are available through the Google Vertex xAI provider. You can also pass any valid model ID as a string.
|
|
1951
|
+
|
|
1952
|
+
| Model ID | Reasoning |
|
|
1953
|
+
| ----------------------------------- | --------- |
|
|
1954
|
+
| `xai/grok-4.20-reasoning` | Yes |
|
|
1955
|
+
| `xai/grok-4.20-non-reasoning` | No |
|
|
1956
|
+
| `xai/grok-4.1-fast-reasoning` | Yes |
|
|
1957
|
+
| `xai/grok-4.1-fast-non-reasoning` | No |
|
|
1958
|
+
|
|
1959
|
+
<Note>
|
|
1960
|
+
Grok reasoning models on Vertex report reasoning token counts in usage
|
|
1961
|
+
metadata. They do not support the `reasoning_effort` request parameter.
|
|
1962
|
+
</Note>
|
|
1963
|
+
|
|
1785
1964
|
## Google Vertex MaaS Provider Usage
|
|
1786
1965
|
|
|
1787
1966
|
The Google Vertex MaaS (Model as a Service) provider offers access to partner and open models hosted on Vertex AI through an OpenAI-compatible Chat Completions API. This includes models from DeepSeek, Qwen, Meta, MiniMax, Moonshot, and OpenAI.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/google-vertex",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.64",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -20,7 +20,9 @@
|
|
|
20
20
|
"anthropic/edge.d.ts",
|
|
21
21
|
"anthropic/index.d.ts",
|
|
22
22
|
"maas/edge.d.ts",
|
|
23
|
-
"maas/index.d.ts"
|
|
23
|
+
"maas/index.d.ts",
|
|
24
|
+
"xai/edge.d.ts",
|
|
25
|
+
"xai/index.d.ts"
|
|
24
26
|
],
|
|
25
27
|
"directories": {
|
|
26
28
|
"doc": "./docs"
|
|
@@ -56,13 +58,23 @@
|
|
|
56
58
|
"types": "./dist/maas/edge/index.d.ts",
|
|
57
59
|
"import": "./dist/maas/edge/index.js",
|
|
58
60
|
"default": "./dist/maas/edge/index.js"
|
|
61
|
+
},
|
|
62
|
+
"./xai": {
|
|
63
|
+
"types": "./dist/xai/index.d.ts",
|
|
64
|
+
"import": "./dist/xai/index.js",
|
|
65
|
+
"default": "./dist/xai/index.js"
|
|
66
|
+
},
|
|
67
|
+
"./xai/edge": {
|
|
68
|
+
"types": "./dist/xai/edge/index.d.ts",
|
|
69
|
+
"import": "./dist/xai/edge/index.js",
|
|
70
|
+
"default": "./dist/xai/edge/index.js"
|
|
59
71
|
}
|
|
60
72
|
},
|
|
61
73
|
"dependencies": {
|
|
62
74
|
"google-auth-library": "^10.5.0",
|
|
63
75
|
"@ai-sdk/anthropic": "4.0.0-beta.42",
|
|
64
76
|
"@ai-sdk/google": "4.0.0-beta.49",
|
|
65
|
-
"@ai-sdk/openai-compatible": "3.0.0-beta.
|
|
77
|
+
"@ai-sdk/openai-compatible": "3.0.0-beta.36",
|
|
66
78
|
"@ai-sdk/provider": "4.0.0-beta.14",
|
|
67
79
|
"@ai-sdk/provider-utils": "5.0.0-beta.30"
|
|
68
80
|
},
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { resolve, type FetchFunction } from '@ai-sdk/provider-utils';
|
|
2
|
+
import {
|
|
3
|
+
generateAuthToken,
|
|
4
|
+
type GoogleCredentials,
|
|
5
|
+
} from '../../edge/google-vertex-auth-edge';
|
|
6
|
+
import {
|
|
7
|
+
createGoogleVertexXai as createGoogleVertexXaiOriginal,
|
|
8
|
+
type GoogleVertexXaiProvider,
|
|
9
|
+
type GoogleVertexXaiProviderSettings as GoogleVertexXaiProviderSettingsOriginal,
|
|
10
|
+
} from '../google-vertex-xai-provider';
|
|
11
|
+
export type { GoogleVertexXaiProvider };
|
|
12
|
+
|
|
13
|
+
export interface GoogleVertexXaiProviderSettings extends GoogleVertexXaiProviderSettingsOriginal {
|
|
14
|
+
/**
|
|
15
|
+
* Optional. The Google credentials for the Google Cloud service account. If
|
|
16
|
+
* not provided, the Google Vertex provider will use environment variables to
|
|
17
|
+
* load the credentials.
|
|
18
|
+
*/
|
|
19
|
+
googleCredentials?: GoogleCredentials;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Create a Google Vertex AI xAI provider instance for Edge runtimes.
|
|
24
|
+
* Uses the OpenAI-compatible Chat Completions API for Grok partner models.
|
|
25
|
+
* Automatically handles Google Cloud authentication.
|
|
26
|
+
*
|
|
27
|
+
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/grok
|
|
28
|
+
*/
|
|
29
|
+
export function createGoogleVertexXai(
|
|
30
|
+
options: GoogleVertexXaiProviderSettings = {},
|
|
31
|
+
): GoogleVertexXaiProvider {
|
|
32
|
+
const customFetch: FetchFunction = async (url, init) => {
|
|
33
|
+
const token = await generateAuthToken(options.googleCredentials);
|
|
34
|
+
const resolvedHeaders = await resolve(options.headers);
|
|
35
|
+
const authHeaders = {
|
|
36
|
+
...resolvedHeaders,
|
|
37
|
+
Authorization: `Bearer ${token}`,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const fetchInit = {
|
|
41
|
+
...init,
|
|
42
|
+
headers: {
|
|
43
|
+
...init?.headers,
|
|
44
|
+
...authHeaders,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
return (options.fetch ?? fetch)(url, fetchInit);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return createGoogleVertexXaiOriginal({
|
|
52
|
+
...options,
|
|
53
|
+
fetch: customFetch,
|
|
54
|
+
headers: undefined,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Default Google Vertex AI xAI provider instance for Edge runtimes.
|
|
60
|
+
*/
|
|
61
|
+
export const googleVertexXai = createGoogleVertexXai();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export {
|
|
2
|
+
createGoogleVertexXai,
|
|
3
|
+
googleVertexXai,
|
|
4
|
+
} from './google-vertex-xai-provider-edge';
|
|
5
|
+
export type {
|
|
6
|
+
GoogleVertexXaiProvider,
|
|
7
|
+
GoogleVertexXaiProviderSettings,
|
|
8
|
+
} from './google-vertex-xai-provider-edge';
|
|
9
|
+
export type { GoogleVertexXaiModelId } from '../google-vertex-xai-options';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/grok
|
|
2
|
+
export type GoogleVertexXaiModelId =
|
|
3
|
+
| 'xai/grok-4.20-reasoning'
|
|
4
|
+
| 'xai/grok-4.20-non-reasoning'
|
|
5
|
+
| 'xai/grok-4.1-fast-reasoning'
|
|
6
|
+
| 'xai/grok-4.1-fast-non-reasoning'
|
|
7
|
+
| (string & {});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { resolve, type FetchFunction } from '@ai-sdk/provider-utils';
|
|
2
|
+
import type { GoogleAuthOptions } from 'google-auth-library';
|
|
3
|
+
import { generateAuthToken } from '../google-vertex-auth-google-auth-library';
|
|
4
|
+
import {
|
|
5
|
+
createGoogleVertexXai as createGoogleVertexXaiOriginal,
|
|
6
|
+
type GoogleVertexXaiProvider,
|
|
7
|
+
type GoogleVertexXaiProviderSettings as GoogleVertexXaiProviderSettingsOriginal,
|
|
8
|
+
} from './google-vertex-xai-provider';
|
|
9
|
+
export type { GoogleVertexXaiProvider };
|
|
10
|
+
|
|
11
|
+
export interface GoogleVertexXaiProviderSettings extends GoogleVertexXaiProviderSettingsOriginal {
|
|
12
|
+
/**
|
|
13
|
+
* Optional. The Authentication options provided by google-auth-library.
|
|
14
|
+
* Complete list of authentication options is documented in the
|
|
15
|
+
* GoogleAuthOptions interface:
|
|
16
|
+
* https://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/googleauth.ts.
|
|
17
|
+
*/
|
|
18
|
+
googleAuthOptions?: GoogleAuthOptions;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Create a Google Vertex AI xAI provider instance for Node.js.
|
|
23
|
+
* Uses the OpenAI-compatible Chat Completions API for Grok partner models.
|
|
24
|
+
* Automatically handles Google Cloud authentication.
|
|
25
|
+
*
|
|
26
|
+
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/grok
|
|
27
|
+
*/
|
|
28
|
+
export function createGoogleVertexXai(
|
|
29
|
+
options: GoogleVertexXaiProviderSettings = {},
|
|
30
|
+
): GoogleVertexXaiProvider {
|
|
31
|
+
const customFetch: FetchFunction = async (url, init) => {
|
|
32
|
+
const token = await generateAuthToken(options.googleAuthOptions);
|
|
33
|
+
const resolvedHeaders = await resolve(options.headers);
|
|
34
|
+
const authHeaders = {
|
|
35
|
+
...resolvedHeaders,
|
|
36
|
+
Authorization: `Bearer ${token}`,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const fetchInit = {
|
|
40
|
+
...init,
|
|
41
|
+
headers: {
|
|
42
|
+
...init?.headers,
|
|
43
|
+
...authHeaders,
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return (options.fetch ?? fetch)(url, fetchInit);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return createGoogleVertexXaiOriginal({
|
|
51
|
+
...options,
|
|
52
|
+
fetch: customFetch,
|
|
53
|
+
headers: undefined,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Default Google Vertex AI xAI provider instance for Node.js.
|
|
59
|
+
*/
|
|
60
|
+
export const googleVertexXai = createGoogleVertexXai();
|