@ai-sdk/google-vertex 4.0.116 → 4.0.118

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.
Files changed (39) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/anthropic/edge/index.js +1 -1
  3. package/dist/anthropic/edge/index.mjs +1 -1
  4. package/dist/anthropic/index.js +13 -19
  5. package/dist/anthropic/index.js.map +1 -1
  6. package/dist/anthropic/index.mjs +13 -19
  7. package/dist/anthropic/index.mjs.map +1 -1
  8. package/dist/edge/index.js +1 -1
  9. package/dist/edge/index.mjs +1 -1
  10. package/dist/index.js +14 -21
  11. package/dist/index.js.map +1 -1
  12. package/dist/index.mjs +14 -21
  13. package/dist/index.mjs.map +1 -1
  14. package/dist/maas/edge/index.js +1 -1
  15. package/dist/maas/edge/index.mjs +1 -1
  16. package/dist/maas/index.js +13 -18
  17. package/dist/maas/index.js.map +1 -1
  18. package/dist/maas/index.mjs +13 -18
  19. package/dist/maas/index.mjs.map +1 -1
  20. package/dist/xai/edge/index.d.mts +92 -0
  21. package/dist/xai/edge/index.mjs +259 -0
  22. package/dist/xai/edge/index.mjs.map +1 -0
  23. package/dist/xai/index.d.mts +76 -0
  24. package/dist/xai/index.mjs +159 -0
  25. package/dist/xai/index.mjs.map +1 -0
  26. package/docs/16-google-vertex.mdx +181 -2
  27. package/package.json +19 -7
  28. package/src/anthropic/google-vertex-anthropic-provider-node.ts +3 -2
  29. package/src/google-vertex-auth-google-auth-library.ts +11 -24
  30. package/src/google-vertex-provider-node.ts +4 -4
  31. package/src/maas/google-vertex-maas-provider-node.ts +4 -2
  32. package/src/xai/edge/google-vertex-xai-provider-edge.ts +61 -0
  33. package/src/xai/edge/index.ts +9 -0
  34. package/src/xai/google-vertex-xai-options.ts +7 -0
  35. package/src/xai/google-vertex-xai-provider-node.ts +62 -0
  36. package/src/xai/google-vertex-xai-provider.ts +212 -0
  37. package/src/xai/index.ts +9 -0
  38. package/xai/edge.d.ts +1 -0
  39. package/xai/index.d.ts +1 -0
@@ -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 Anthropic providers are both available in the `@ai-sdk/google-vertex` module. You can install it with
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>
@@ -1780,6 +1780,185 @@ See also [Anthropic Model Comparison](https://docs.anthropic.com/en/docs/about-c
1780
1780
  model ID as a string if needed.
1781
1781
  </Note>
1782
1782
 
1783
+ ## Google Vertex xAI Provider Usage
1784
+
1785
+ The Google Vertex xAI provider offers support for xAI's Grok partner models through the Google Vertex AI OpenAI-compatible Chat Completions API.
1786
+
1787
+ For more information, see the [Vertex AI Grok documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/grok).
1788
+
1789
+ ### Provider Instance
1790
+
1791
+ You can import the default provider instance `googleVertexXai` from `@ai-sdk/google-vertex/xai`:
1792
+
1793
+ ```typescript
1794
+ import { googleVertexXai } from '@ai-sdk/google-vertex/xai';
1795
+ ```
1796
+
1797
+ If you need a customized setup, you can import `createGoogleVertexXai` from `@ai-sdk/google-vertex/xai` and create a provider instance with your settings:
1798
+
1799
+ ```typescript
1800
+ import { createGoogleVertexXai } from '@ai-sdk/google-vertex/xai';
1801
+
1802
+ const googleVertexXai = createGoogleVertexXai({
1803
+ project: 'my-project', // optional
1804
+ location: 'global', // optional, defaults to 'global'
1805
+ });
1806
+ ```
1807
+
1808
+ #### Node.js Runtime
1809
+
1810
+ For Node.js environments, the Google Vertex xAI provider supports all standard Google Cloud authentication options through the `google-auth-library`:
1811
+
1812
+ ```typescript
1813
+ import { createGoogleVertexXai } from '@ai-sdk/google-vertex/xai';
1814
+
1815
+ const googleVertexXai = createGoogleVertexXai({
1816
+ googleAuthOptions: {
1817
+ credentials: {
1818
+ client_email: 'my-email',
1819
+ private_key: 'my-private-key',
1820
+ },
1821
+ },
1822
+ });
1823
+ ```
1824
+
1825
+ ##### Optional Provider Settings
1826
+
1827
+ - **project** _string_
1828
+
1829
+ The Google Cloud project ID. Defaults to the `GOOGLE_VERTEX_PROJECT` environment variable.
1830
+
1831
+ - **location** _string_
1832
+
1833
+ 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`.
1834
+
1835
+ - **googleAuthOptions** _object_
1836
+
1837
+ Optional. The Authentication options used by the [Google Auth Library](https://github.com/googleapis/google-auth-library-nodejs/).
1838
+
1839
+ - **headers** _Resolvable&lt;Record&lt;string, string | undefined&gt;&gt;_
1840
+
1841
+ Headers to include in requests.
1842
+
1843
+ - **fetch** _(input: RequestInfo, init?: RequestInit) => Promise&lt;Response&gt;_
1844
+
1845
+ Custom [fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch) implementation.
1846
+
1847
+ <a id="google-vertex-xai-edge-runtime"></a>
1848
+
1849
+ #### Edge Runtime
1850
+
1851
+ For Edge runtimes, import from `@ai-sdk/google-vertex/xai/edge`:
1852
+
1853
+ ```typescript
1854
+ import { googleVertexXai } from '@ai-sdk/google-vertex/xai/edge';
1855
+ ```
1856
+
1857
+ ```typescript
1858
+ import { createGoogleVertexXai } from '@ai-sdk/google-vertex/xai/edge';
1859
+
1860
+ const googleVertexXai = createGoogleVertexXai({
1861
+ project: 'my-project',
1862
+ location: 'global',
1863
+ });
1864
+ ```
1865
+
1866
+ For Edge runtime authentication, set these environment variables:
1867
+
1868
+ - `GOOGLE_CLIENT_EMAIL`
1869
+ - `GOOGLE_PRIVATE_KEY`
1870
+ - `GOOGLE_PRIVATE_KEY_ID` (optional)
1871
+
1872
+ ### Language Models
1873
+
1874
+ You can create models using the provider instance. The first argument is the model ID:
1875
+
1876
+ ```ts
1877
+ import { googleVertexXai } from '@ai-sdk/google-vertex/xai';
1878
+ import { generateText } from 'ai';
1879
+
1880
+ const { text } = await generateText({
1881
+ model: googleVertexXai('xai/grok-4.1-fast-reasoning'),
1882
+ prompt: 'Invent a new holiday and describe its traditions.',
1883
+ });
1884
+ ```
1885
+
1886
+ Streaming is also supported:
1887
+
1888
+ ```ts
1889
+ import { googleVertexXai } from '@ai-sdk/google-vertex/xai';
1890
+ import { streamText } from 'ai';
1891
+
1892
+ const result = streamText({
1893
+ model: googleVertexXai('xai/grok-4.1-fast-reasoning'),
1894
+ prompt: 'Invent a new holiday and describe its traditions.',
1895
+ });
1896
+
1897
+ for await (const textPart of result.textStream) {
1898
+ process.stdout.write(textPart);
1899
+ }
1900
+ ```
1901
+
1902
+ ### Function Calling
1903
+
1904
+ Grok models on Vertex support OpenAI-compatible function calling. You can use AI SDK tools as usual:
1905
+
1906
+ ```ts
1907
+ import { googleVertexXai } from '@ai-sdk/google-vertex/xai';
1908
+ import { generateText, tool } from 'ai';
1909
+ import { z } from 'zod';
1910
+
1911
+ const result = await generateText({
1912
+ model: googleVertexXai('xai/grok-4.1-fast-reasoning'),
1913
+ tools: {
1914
+ weather: tool({
1915
+ description: 'Get the weather in a city',
1916
+ inputSchema: z.object({ city: z.string() }),
1917
+ execute: async ({ city }) => `The weather in ${city} is sunny.`,
1918
+ }),
1919
+ },
1920
+ prompt: 'What is the weather in San Francisco?',
1921
+ });
1922
+ ```
1923
+
1924
+ ### Structured Outputs
1925
+
1926
+ Grok models on Vertex support JSON mode and schema-backed structured outputs:
1927
+
1928
+ ```ts
1929
+ import { googleVertexXai } from '@ai-sdk/google-vertex/xai';
1930
+ import { generateText, Output } from 'ai';
1931
+ import { z } from 'zod';
1932
+
1933
+ const result = await generateText({
1934
+ model: googleVertexXai('xai/grok-4.1-fast-reasoning'),
1935
+ output: Output.object({
1936
+ schema: z.object({
1937
+ name: z.string(),
1938
+ date: z.string(),
1939
+ participants: z.array(z.string()),
1940
+ }),
1941
+ }),
1942
+ prompt: 'Alice and Bob are going to a science fair on Friday.',
1943
+ });
1944
+ ```
1945
+
1946
+ ### Available Models
1947
+
1948
+ The following models are available through the Google Vertex xAI provider. You can also pass any valid model ID as a string.
1949
+
1950
+ | Model ID | Reasoning |
1951
+ | ----------------------------------- | --------- |
1952
+ | `xai/grok-4.20-reasoning` | Yes |
1953
+ | `xai/grok-4.20-non-reasoning` | No |
1954
+ | `xai/grok-4.1-fast-reasoning` | Yes |
1955
+ | `xai/grok-4.1-fast-non-reasoning` | No |
1956
+
1957
+ <Note>
1958
+ Grok reasoning models on Vertex report reasoning token counts in usage
1959
+ metadata. They do not support the `reasoning_effort` request parameter.
1960
+ </Note>
1961
+
1783
1962
  ## Google Vertex MaaS Provider Usage
1784
1963
 
1785
1964
  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": "4.0.116",
3
+ "version": "4.0.118",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -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"
@@ -54,16 +56,26 @@
54
56
  },
55
57
  "./maas/edge": {
56
58
  "types": "./dist/maas/edge/index.d.ts",
57
- "import": "./dist/maas/edge/index.mjs",
58
- "require": "./dist/maas/edge/index.js"
59
+ "import": "./dist/maas/edge/index.js",
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": "3.0.74",
64
76
  "@ai-sdk/google": "3.0.67",
77
+ "@ai-sdk/openai-compatible": "2.0.45",
65
78
  "@ai-sdk/provider": "3.0.10",
66
- "@ai-sdk/openai-compatible": "2.0.44",
67
79
  "@ai-sdk/provider-utils": "4.0.26"
68
80
  },
69
81
  "devDependencies": {
@@ -71,8 +83,8 @@
71
83
  "tsup": "^8",
72
84
  "typescript": "5.8.3",
73
85
  "zod": "3.25.76",
74
- "@vercel/ai-tsconfig": "0.0.0",
75
- "@ai-sdk/test-server": "1.0.5"
86
+ "@ai-sdk/test-server": "1.0.5",
87
+ "@vercel/ai-tsconfig": "0.0.0"
76
88
  },
77
89
  "peerDependencies": {
78
90
  "zod": "^3.25.76 || ^4.1.8"
@@ -1,6 +1,6 @@
1
1
  import { resolve } from '@ai-sdk/provider-utils';
2
2
  import type { GoogleAuthOptions } from 'google-auth-library';
3
- import { generateAuthToken as defaultGenerateAuthToken } from '../google-vertex-auth-google-auth-library';
3
+ import { createAuthTokenGenerator } from '../google-vertex-auth-google-auth-library';
4
4
  import {
5
5
  createVertexAnthropic as createVertexAnthropicOriginal,
6
6
  type GoogleVertexAnthropicProvider,
@@ -29,7 +29,8 @@ export function createVertexAnthropic(
29
29
  ): GoogleVertexAnthropicProvider {
30
30
  const generateAuthToken =
31
31
  options.generateAuthToken ??
32
- (() => defaultGenerateAuthToken(options.googleAuthOptions));
32
+ createAuthTokenGenerator(options.googleAuthOptions);
33
+
33
34
  return createVertexAnthropicOriginal({
34
35
  ...options,
35
36
  headers: async () => ({
@@ -1,27 +1,14 @@
1
1
  import { GoogleAuth, type GoogleAuthOptions } from 'google-auth-library';
2
2
 
3
- let authInstance: GoogleAuth | null = null;
4
- let authOptions: GoogleAuthOptions | null = null;
5
-
6
- function getAuth(options: GoogleAuthOptions) {
7
- if (!authInstance || options !== authOptions) {
8
- authInstance = new GoogleAuth({
9
- scopes: ['https://www.googleapis.com/auth/cloud-platform'],
10
- ...options,
11
- });
12
- authOptions = options;
13
- }
14
- return authInstance;
15
- }
16
-
17
- export async function generateAuthToken(options?: GoogleAuthOptions) {
18
- const auth = getAuth(options || {});
19
- const client = await auth.getClient();
20
- const token = await client.getAccessToken();
21
- return token?.token || null;
22
- }
23
-
24
- // For testing purposes only
25
- export function _resetAuthInstance() {
26
- authInstance = null;
3
+ export function createAuthTokenGenerator(options?: GoogleAuthOptions) {
4
+ const auth = new GoogleAuth({
5
+ scopes: ['https://www.googleapis.com/auth/cloud-platform'],
6
+ ...options,
7
+ });
8
+
9
+ return async function generateAuthToken() {
10
+ const client = await auth.getClient();
11
+ const token = await client.getAccessToken();
12
+ return token?.token ?? null;
13
+ };
27
14
  }
@@ -1,6 +1,6 @@
1
1
  import { loadOptionalSetting, resolve } from '@ai-sdk/provider-utils';
2
2
  import type { GoogleAuthOptions } from 'google-auth-library';
3
- import { generateAuthToken } from './google-vertex-auth-google-auth-library';
3
+ import { createAuthTokenGenerator } from './google-vertex-auth-google-auth-library';
4
4
  import {
5
5
  createVertex as createVertexOriginal,
6
6
  type GoogleVertexProvider,
@@ -31,12 +31,12 @@ export function createVertex(
31
31
  return createVertexOriginal(options);
32
32
  }
33
33
 
34
+ const generateAuthToken = createAuthTokenGenerator(options.googleAuthOptions);
35
+
34
36
  return createVertexOriginal({
35
37
  ...options,
36
38
  headers: async () => ({
37
- Authorization: `Bearer ${await generateAuthToken(
38
- options.googleAuthOptions,
39
- )}`,
39
+ Authorization: `Bearer ${await generateAuthToken()}`,
40
40
  ...(await resolve(options.headers)),
41
41
  }),
42
42
  });
@@ -1,6 +1,6 @@
1
1
  import { resolve, type FetchFunction } from '@ai-sdk/provider-utils';
2
2
  import type { GoogleAuthOptions } from 'google-auth-library';
3
- import { generateAuthToken } from '../google-vertex-auth-google-auth-library';
3
+ import { createAuthTokenGenerator } from '../google-vertex-auth-google-auth-library';
4
4
  import {
5
5
  createVertexMaas as createVertexMaasOriginal,
6
6
  type GoogleVertexMaasProvider,
@@ -29,9 +29,11 @@ export interface GoogleVertexMaasProviderSettings extends GoogleVertexMaasProvid
29
29
  export function createVertexMaas(
30
30
  options: GoogleVertexMaasProviderSettings = {},
31
31
  ): GoogleVertexMaasProvider {
32
+ const generateAuthToken = createAuthTokenGenerator(options.googleAuthOptions);
33
+
32
34
  // Create a custom fetch wrapper that adds auth headers
33
35
  const customFetch: FetchFunction = async (url, init) => {
34
- const token = await generateAuthToken(options.googleAuthOptions);
36
+ const token = await generateAuthToken();
35
37
  const resolvedHeaders = await resolve(options.headers);
36
38
  const authHeaders = {
37
39
  ...resolvedHeaders,
@@ -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,62 @@
1
+ import { resolve, type FetchFunction } from '@ai-sdk/provider-utils';
2
+ import type { GoogleAuthOptions } from 'google-auth-library';
3
+ import { createAuthTokenGenerator } 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 generateAuthToken = createAuthTokenGenerator(options.googleAuthOptions);
32
+
33
+ const customFetch: FetchFunction = async (url, init) => {
34
+ const token = await generateAuthToken();
35
+ const resolvedHeaders = await resolve(options.headers);
36
+ const authHeaders = {
37
+ ...resolvedHeaders,
38
+ Authorization: `Bearer ${token}`,
39
+ };
40
+
41
+ const fetchInit = {
42
+ ...init,
43
+ headers: {
44
+ ...init?.headers,
45
+ ...authHeaders,
46
+ },
47
+ };
48
+
49
+ return (options.fetch ?? fetch)(url, fetchInit);
50
+ };
51
+
52
+ return createGoogleVertexXaiOriginal({
53
+ ...options,
54
+ fetch: customFetch,
55
+ headers: undefined,
56
+ });
57
+ }
58
+
59
+ /**
60
+ * Default Google Vertex AI xAI provider instance for Node.js.
61
+ */
62
+ export const googleVertexXai = createGoogleVertexXai();