@ai-sdk/google-vertex 5.0.0-beta.62 → 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 +26 -0
- package/dist/anthropic/edge/index.d.ts +10 -5
- package/dist/anthropic/edge/index.js +15 -13
- package/dist/anthropic/edge/index.js.map +1 -1
- package/dist/anthropic/index.d.ts +10 -5
- package/dist/anthropic/index.js +14 -12
- package/dist/anthropic/index.js.map +1 -1
- package/dist/edge/index.d.ts +3 -3
- package/dist/edge/index.js +190 -153
- package/dist/edge/index.js.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.js +192 -155
- package/dist/index.js.map +1 -1
- package/dist/maas/edge/index.d.ts +3 -3
- package/dist/maas/edge/index.js +9 -7
- package/dist/maas/edge/index.js.map +1 -1
- package/dist/maas/index.d.ts +3 -3
- package/dist/maas/index.js +8 -6
- package/dist/maas/index.js.map +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 +257 -78
- package/package.json +18 -6
- package/src/anthropic/edge/google-vertex-anthropic-provider-edge.ts +13 -7
- package/src/anthropic/edge/index.ts +6 -2
- package/src/anthropic/google-vertex-anthropic-provider-node.ts +13 -7
- package/src/anthropic/google-vertex-anthropic-provider.ts +5 -5
- package/src/anthropic/index.ts +6 -2
- package/src/edge/google-vertex-provider-edge.ts +6 -6
- package/src/edge/index.ts +8 -1
- package/src/google-vertex-embedding-model.ts +10 -2
- package/src/google-vertex-image-model-options.ts +74 -0
- package/src/google-vertex-image-model.ts +42 -102
- package/src/google-vertex-provider-base.ts +245 -0
- package/src/google-vertex-provider.ts +35 -233
- package/src/google-vertex-video-model-options.ts +49 -0
- package/src/google-vertex-video-model.ts +30 -66
- package/src/index.ts +12 -5
- package/src/maas/edge/google-vertex-maas-provider-edge.ts +3 -3
- package/src/maas/edge/index.ts +6 -2
- package/src/maas/google-vertex-maas-provider-node.ts +3 -3
- package/src/maas/google-vertex-maas-provider.ts +1 -1
- package/src/maas/index.ts +6 -2
- 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
- package/src/google-vertex-provider-node.ts +0 -47
- /package/src/{google-vertex-embedding-options.ts → google-vertex-embedding-model-options.ts} +0 -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
|
|
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>
|
|
@@ -45,18 +45,18 @@ The Google Vertex provider instance is used to create model instances that call
|
|
|
45
45
|
|
|
46
46
|
### Provider Instance
|
|
47
47
|
|
|
48
|
-
You can import the default provider instance `
|
|
48
|
+
You can import the default provider instance `googleVertex` from `@ai-sdk/google-vertex`:
|
|
49
49
|
|
|
50
50
|
```ts
|
|
51
|
-
import {
|
|
51
|
+
import { googleVertex } from '@ai-sdk/google-vertex';
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
If you need a customized setup, you can import `
|
|
54
|
+
If you need a customized setup, you can import `createGoogleVertex` from `@ai-sdk/google-vertex` and create a provider instance with your settings:
|
|
55
55
|
|
|
56
56
|
```ts
|
|
57
|
-
import {
|
|
57
|
+
import { createGoogleVertex } from '@ai-sdk/google-vertex';
|
|
58
58
|
|
|
59
|
-
const
|
|
59
|
+
const googleVertex = createGoogleVertex({
|
|
60
60
|
project: 'my-project', // optional
|
|
61
61
|
location: 'us-central1', // optional
|
|
62
62
|
});
|
|
@@ -68,12 +68,12 @@ Google Vertex supports multiple authentication methods depending on your runtime
|
|
|
68
68
|
|
|
69
69
|
The Node.js runtime is the default runtime supported by the AI SDK. It supports all standard Google Cloud authentication options through the [`google-auth-library`](https://github.com/googleapis/google-auth-library-nodejs?tab=readme-ov-file#ways-to-authenticate). Typical use involves setting a path to a json credentials file in the `GOOGLE_APPLICATION_CREDENTIALS` environment variable. The credentials file can be obtained from the [Google Cloud Console](https://console.cloud.google.com/apis/credentials).
|
|
70
70
|
|
|
71
|
-
If you want to customize the Google authentication options you can pass them as options to the `
|
|
71
|
+
If you want to customize the Google authentication options you can pass them as options to the `createGoogleVertex` function, for example:
|
|
72
72
|
|
|
73
73
|
```ts
|
|
74
|
-
import {
|
|
74
|
+
import { createGoogleVertex } from '@ai-sdk/google-vertex';
|
|
75
75
|
|
|
76
|
-
const
|
|
76
|
+
const googleVertex = createGoogleVertex({
|
|
77
77
|
googleAuthOptions: {
|
|
78
78
|
credentials: {
|
|
79
79
|
client_email: 'my-email',
|
|
@@ -156,10 +156,10 @@ For example, direct file system access is not available, and many Node.js-specif
|
|
|
156
156
|
|
|
157
157
|
The Edge runtime version of the Google Vertex provider supports Google's [Application Default Credentials](https://github.com/googleapis/google-auth-library-nodejs?tab=readme-ov-file#application-default-credentials) through environment variables. The values can be obtained from a json credentials file from the [Google Cloud Console](https://console.cloud.google.com/apis/credentials).
|
|
158
158
|
|
|
159
|
-
You can import the default provider instance `
|
|
159
|
+
You can import the default provider instance `googleVertex` from `@ai-sdk/google-vertex/edge`:
|
|
160
160
|
|
|
161
161
|
```ts
|
|
162
|
-
import {
|
|
162
|
+
import { googleVertex } from '@ai-sdk/google-vertex/edge';
|
|
163
163
|
```
|
|
164
164
|
|
|
165
165
|
<Note>
|
|
@@ -168,12 +168,12 @@ import { vertex } from '@ai-sdk/google-vertex/edge';
|
|
|
168
168
|
`@ai-sdk/google-vertex/edge` to differentiate it from the Node.js provider.
|
|
169
169
|
</Note>
|
|
170
170
|
|
|
171
|
-
If you need a customized setup, you can import `
|
|
171
|
+
If you need a customized setup, you can import `createGoogleVertex` from `@ai-sdk/google-vertex/edge` and create a provider instance with your settings:
|
|
172
172
|
|
|
173
173
|
```ts
|
|
174
|
-
import {
|
|
174
|
+
import { createGoogleVertex } from '@ai-sdk/google-vertex/edge';
|
|
175
175
|
|
|
176
|
-
const
|
|
176
|
+
const googleVertex = createGoogleVertex({
|
|
177
177
|
project: 'my-project', // optional
|
|
178
178
|
location: 'us-central1', // optional
|
|
179
179
|
});
|
|
@@ -235,9 +235,9 @@ You can use the following optional settings to customize the provider instance:
|
|
|
235
235
|
Express mode provides a simplified authentication method using an API key instead of OAuth or service account credentials. When using express mode, the `project` and `location` settings are not required.
|
|
236
236
|
|
|
237
237
|
```ts
|
|
238
|
-
import {
|
|
238
|
+
import { createGoogleVertex } from '@ai-sdk/google-vertex';
|
|
239
239
|
|
|
240
|
-
const
|
|
240
|
+
const googleVertex = createGoogleVertex({
|
|
241
241
|
apiKey: process.env.GOOGLE_VERTEX_API_KEY,
|
|
242
242
|
});
|
|
243
243
|
```
|
|
@@ -255,7 +255,7 @@ You can create models that call the Vertex API using the provider instance.
|
|
|
255
255
|
The first argument is the model id, e.g. `gemini-2.5-pro`.
|
|
256
256
|
|
|
257
257
|
```ts
|
|
258
|
-
const model =
|
|
258
|
+
const model = googleVertex('gemini-2.5-pro');
|
|
259
259
|
```
|
|
260
260
|
|
|
261
261
|
<Note>
|
|
@@ -269,10 +269,10 @@ of the [standard call settings](/docs/ai-sdk-core/settings). You can pass them a
|
|
|
269
269
|
an options argument:
|
|
270
270
|
|
|
271
271
|
```ts
|
|
272
|
-
import {
|
|
272
|
+
import { googleVertex } from '@ai-sdk/google-vertex';
|
|
273
273
|
import { type GoogleLanguageModelOptions } from '@ai-sdk/google';
|
|
274
274
|
|
|
275
|
-
const model =
|
|
275
|
+
const model = googleVertex('gemini-2.5-pro');
|
|
276
276
|
|
|
277
277
|
await generateText({
|
|
278
278
|
model,
|
|
@@ -357,11 +357,11 @@ The following optional provider options are available for Google Vertex models:
|
|
|
357
357
|
You can use Google Vertex language models to generate text with the `generateText` function:
|
|
358
358
|
|
|
359
359
|
```ts highlight="1,4"
|
|
360
|
-
import {
|
|
360
|
+
import { googleVertex } from '@ai-sdk/google-vertex';
|
|
361
361
|
import { generateText } from 'ai';
|
|
362
362
|
|
|
363
363
|
const { text } = await generateText({
|
|
364
|
-
model:
|
|
364
|
+
model: googleVertex('gemini-2.5-pro'),
|
|
365
365
|
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
|
|
366
366
|
});
|
|
367
367
|
```
|
|
@@ -376,12 +376,12 @@ With [Code Execution](https://cloud.google.com/vertex-ai/generative-ai/docs/mult
|
|
|
376
376
|
You can enable code execution by adding the `code_execution` tool to your request.
|
|
377
377
|
|
|
378
378
|
```ts
|
|
379
|
-
import {
|
|
379
|
+
import { googleVertex } from '@ai-sdk/google-vertex';
|
|
380
380
|
import { generateText } from 'ai';
|
|
381
381
|
|
|
382
382
|
const result = await generateText({
|
|
383
|
-
model:
|
|
384
|
-
tools: { code_execution:
|
|
383
|
+
model: googleVertex('gemini-2.5-pro'),
|
|
384
|
+
tools: { code_execution: googleVertex.tools.codeExecution({}) },
|
|
385
385
|
prompt:
|
|
386
386
|
'Use python to calculate 20th fibonacci number. Then find the nearest palindrome to it.',
|
|
387
387
|
});
|
|
@@ -394,12 +394,12 @@ The response will contain `tool-call` and `tool-result` parts for the executed c
|
|
|
394
394
|
URL Context allows Gemini models to retrieve and analyze content from URLs. Supported models: Gemini 2.5 Flash-Lite, 2.5 Pro, 2.5 Flash, 2.0 Flash.
|
|
395
395
|
|
|
396
396
|
```ts
|
|
397
|
-
import {
|
|
397
|
+
import { googleVertex } from '@ai-sdk/google-vertex';
|
|
398
398
|
import { generateText } from 'ai';
|
|
399
399
|
|
|
400
400
|
const result = await generateText({
|
|
401
|
-
model:
|
|
402
|
-
tools: { url_context:
|
|
401
|
+
model: googleVertex('gemini-2.5-pro'),
|
|
402
|
+
tools: { url_context: googleVertex.tools.urlContext({}) },
|
|
403
403
|
prompt: 'What are the key points from https://example.com/article?',
|
|
404
404
|
});
|
|
405
405
|
```
|
|
@@ -409,12 +409,12 @@ const result = await generateText({
|
|
|
409
409
|
Google Search enables Gemini models to access real-time web information. Supported models: Gemini 2.5 Flash-Lite, 2.5 Flash, 2.0 Flash, 2.5 Pro.
|
|
410
410
|
|
|
411
411
|
```ts
|
|
412
|
-
import {
|
|
412
|
+
import { googleVertex } from '@ai-sdk/google-vertex';
|
|
413
413
|
import { generateText } from 'ai';
|
|
414
414
|
|
|
415
415
|
const result = await generateText({
|
|
416
|
-
model:
|
|
417
|
-
tools: { google_search:
|
|
416
|
+
model: googleVertex('gemini-2.5-pro'),
|
|
417
|
+
tools: { google_search: googleVertex.tools.googleSearch({}) },
|
|
418
418
|
prompt: 'What are the latest developments in AI?',
|
|
419
419
|
});
|
|
420
420
|
```
|
|
@@ -424,13 +424,13 @@ const result = await generateText({
|
|
|
424
424
|
[Enterprise Web Search](https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/web-grounding-enterprise) provides grounding using a compliance-focused web index designed for highly-regulated industries such as finance, healthcare, and the public sector. Unlike standard Google Search grounding, Enterprise Web Search does not log customer data and supports VPC service controls. Supported models: Gemini 2.0 and newer.
|
|
425
425
|
|
|
426
426
|
```ts
|
|
427
|
-
import {
|
|
427
|
+
import { googleVertex } from '@ai-sdk/google-vertex';
|
|
428
428
|
import { generateText } from 'ai';
|
|
429
429
|
|
|
430
430
|
const result = await generateText({
|
|
431
|
-
model:
|
|
431
|
+
model: googleVertex('gemini-2.5-flash'),
|
|
432
432
|
tools: {
|
|
433
|
-
enterprise_web_search:
|
|
433
|
+
enterprise_web_search: googleVertex.tools.enterpriseWebSearch({}),
|
|
434
434
|
},
|
|
435
435
|
prompt: 'What are the latest FDA regulations for clinical trials?',
|
|
436
436
|
});
|
|
@@ -441,14 +441,14 @@ const result = await generateText({
|
|
|
441
441
|
Google Maps grounding enables Gemini models to access Google Maps data for location-aware responses. Supported models: Gemini 2.5 Flash-Lite, 2.5 Flash, 2.0 Flash, 2.5 Pro, 3.0 Pro.
|
|
442
442
|
|
|
443
443
|
```ts
|
|
444
|
-
import {
|
|
444
|
+
import { googleVertex } from '@ai-sdk/google-vertex';
|
|
445
445
|
import { type GoogleLanguageModelOptions } from '@ai-sdk/google';
|
|
446
446
|
import { generateText } from 'ai';
|
|
447
447
|
|
|
448
448
|
const result = await generateText({
|
|
449
|
-
model:
|
|
449
|
+
model: googleVertex('gemini-2.5-flash'),
|
|
450
450
|
tools: {
|
|
451
|
-
google_maps:
|
|
451
|
+
google_maps: googleVertex.tools.googleMaps({}),
|
|
452
452
|
},
|
|
453
453
|
providerOptions: {
|
|
454
454
|
vertex: {
|
|
@@ -472,13 +472,13 @@ arguments as they are generated by setting `streamFunctionCallArguments` to
|
|
|
472
472
|
complete arguments. This option defaults to `false`.
|
|
473
473
|
|
|
474
474
|
```ts
|
|
475
|
-
import {
|
|
475
|
+
import { googleVertex } from '@ai-sdk/google-vertex';
|
|
476
476
|
import { type GoogleLanguageModelOptions } from '@ai-sdk/google';
|
|
477
477
|
import { streamText } from 'ai';
|
|
478
478
|
import { z } from 'zod';
|
|
479
479
|
|
|
480
480
|
const result = streamText({
|
|
481
|
-
model:
|
|
481
|
+
model: googleVertex('gemini-3.1-pro-preview'),
|
|
482
482
|
prompt: 'What is the weather in Boston and San Francisco?',
|
|
483
483
|
tools: {
|
|
484
484
|
getWeather: {
|
|
@@ -523,13 +523,13 @@ Google Vertex AI, through its support for Gemini models, can also emit "thinking
|
|
|
523
523
|
To enable thinking tokens for compatible Gemini models via Vertex, set `includeThoughts: true` in the `thinkingConfig` provider option. These options are passed through `providerOptions.vertex`:
|
|
524
524
|
|
|
525
525
|
```ts
|
|
526
|
-
import {
|
|
526
|
+
import { googleVertex } from '@ai-sdk/google-vertex';
|
|
527
527
|
import { type GoogleLanguageModelOptions } from '@ai-sdk/google';
|
|
528
528
|
import { generateText, streamText } from 'ai';
|
|
529
529
|
|
|
530
530
|
// For generateText:
|
|
531
531
|
const { text, reasoningText, reasoning } = await generateText({
|
|
532
|
-
model:
|
|
532
|
+
model: googleVertex('gemini-2.0-flash-001'), // Or other supported model via Vertex
|
|
533
533
|
providerOptions: {
|
|
534
534
|
vertex: {
|
|
535
535
|
thinkingConfig: {
|
|
@@ -547,7 +547,7 @@ console.log('Final Text:', text);
|
|
|
547
547
|
|
|
548
548
|
// For streamText:
|
|
549
549
|
const result = streamText({
|
|
550
|
-
model:
|
|
550
|
+
model: googleVertex('gemini-2.0-flash-001'), // Or other supported model via Vertex
|
|
551
551
|
providerOptions: {
|
|
552
552
|
vertex: {
|
|
553
553
|
thinkingConfig: {
|
|
@@ -584,11 +584,11 @@ When `includeThoughts` is true, parts of the API response marked with `thought:
|
|
|
584
584
|
The Google Vertex provider supports file inputs, e.g. PDF files.
|
|
585
585
|
|
|
586
586
|
```ts
|
|
587
|
-
import {
|
|
587
|
+
import { googleVertex } from '@ai-sdk/google-vertex';
|
|
588
588
|
import { generateText } from 'ai';
|
|
589
589
|
|
|
590
590
|
const { text } = await generateText({
|
|
591
|
-
model:
|
|
591
|
+
model: googleVertex('gemini-2.5-pro'),
|
|
592
592
|
messages: [
|
|
593
593
|
{
|
|
594
594
|
role: 'user',
|
|
@@ -623,7 +623,7 @@ Google Vertex AI supports both explicit and implicit caching to help reduce cost
|
|
|
623
623
|
#### Implicit Caching
|
|
624
624
|
|
|
625
625
|
```ts
|
|
626
|
-
import {
|
|
626
|
+
import { googleVertex } from '@ai-sdk/google-vertex';
|
|
627
627
|
import { generateText } from 'ai';
|
|
628
628
|
|
|
629
629
|
// Structure prompts with consistent content at the beginning
|
|
@@ -631,13 +631,13 @@ const baseContext =
|
|
|
631
631
|
'You are a cooking assistant with expertise in Italian cuisine. Here are 1000 lasagna recipes for reference...';
|
|
632
632
|
|
|
633
633
|
const { text: veggieLasagna } = await generateText({
|
|
634
|
-
model:
|
|
634
|
+
model: googleVertex('gemini-2.5-pro'),
|
|
635
635
|
prompt: `${baseContext}\n\nWrite a vegetarian lasagna recipe for 4 people.`,
|
|
636
636
|
});
|
|
637
637
|
|
|
638
638
|
// Second request with same prefix - eligible for cache hit
|
|
639
639
|
const { text: meatLasagna, providerMetadata } = await generateText({
|
|
640
|
-
model:
|
|
640
|
+
model: googleVertex('gemini-2.5-pro'),
|
|
641
641
|
prompt: `${baseContext}\n\nWrite a meat lasagna recipe for 12 people.`,
|
|
642
642
|
});
|
|
643
643
|
|
|
@@ -695,12 +695,12 @@ console.log('Cache created:', cache.name);
|
|
|
695
695
|
Then use the cache with the AI SDK:
|
|
696
696
|
|
|
697
697
|
```ts
|
|
698
|
-
import {
|
|
698
|
+
import { googleVertex } from '@ai-sdk/google-vertex';
|
|
699
699
|
import { type GoogleLanguageModelOptions } from '@ai-sdk/google';
|
|
700
700
|
import { generateText } from 'ai';
|
|
701
701
|
|
|
702
702
|
const { text: veggieLasagnaRecipe } = await generateText({
|
|
703
|
-
model:
|
|
703
|
+
model: googleVertex('gemini-2.5-pro'),
|
|
704
704
|
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
|
|
705
705
|
providerOptions: {
|
|
706
706
|
vertex: {
|
|
@@ -710,7 +710,7 @@ const { text: veggieLasagnaRecipe } = await generateText({
|
|
|
710
710
|
});
|
|
711
711
|
|
|
712
712
|
const { text: meatLasagnaRecipe } = await generateText({
|
|
713
|
-
model:
|
|
713
|
+
model: googleVertex('gemini-2.5-pro'),
|
|
714
714
|
prompt: 'Write a meat lasagna recipe for 12 people.',
|
|
715
715
|
providerOptions: {
|
|
716
716
|
vertex: {
|
|
@@ -779,12 +779,12 @@ By default, structured outputs are enabled (and for tool calling they are requir
|
|
|
779
779
|
You can disable structured outputs for object generation as a workaround:
|
|
780
780
|
|
|
781
781
|
```ts highlight="7,12"
|
|
782
|
-
import {
|
|
782
|
+
import { googleVertex } from '@ai-sdk/google-vertex';
|
|
783
783
|
import { type GoogleLanguageModelOptions } from '@ai-sdk/google';
|
|
784
784
|
import { generateText, Output } from 'ai';
|
|
785
785
|
|
|
786
786
|
const result = await generateText({
|
|
787
|
-
model:
|
|
787
|
+
model: googleVertex('gemini-2.5-pro'),
|
|
788
788
|
providerOptions: {
|
|
789
789
|
vertex: {
|
|
790
790
|
structuredOutputs: false,
|
|
@@ -836,19 +836,19 @@ The following Zod features are known to not work with Google Vertex:
|
|
|
836
836
|
You can create models that call the Google Vertex AI embeddings API using the `.embeddingModel()` factory method:
|
|
837
837
|
|
|
838
838
|
```ts
|
|
839
|
-
const model =
|
|
839
|
+
const model = googleVertex.embeddingModel('text-embedding-005');
|
|
840
840
|
```
|
|
841
841
|
|
|
842
842
|
Google Vertex AI embedding models support additional settings. You can pass them as an options argument:
|
|
843
843
|
|
|
844
844
|
```ts
|
|
845
845
|
import {
|
|
846
|
-
|
|
846
|
+
googleVertex,
|
|
847
847
|
type GoogleVertexEmbeddingModelOptions,
|
|
848
848
|
} from '@ai-sdk/google-vertex';
|
|
849
849
|
import { embed } from 'ai';
|
|
850
850
|
|
|
851
|
-
const model =
|
|
851
|
+
const model = googleVertex.embeddingModel('text-embedding-005');
|
|
852
852
|
|
|
853
853
|
const { embedding } = await embed({
|
|
854
854
|
model,
|
|
@@ -911,11 +911,11 @@ You can create image models using the `.image()` factory method. The Google Vert
|
|
|
911
911
|
[Imagen models](https://cloud.google.com/vertex-ai/generative-ai/docs/image/generate-images) generate images using the Imagen on Vertex AI API.
|
|
912
912
|
|
|
913
913
|
```ts
|
|
914
|
-
import {
|
|
914
|
+
import { googleVertex } from '@ai-sdk/google-vertex';
|
|
915
915
|
import { generateImage } from 'ai';
|
|
916
916
|
|
|
917
917
|
const { image } = await generateImage({
|
|
918
|
-
model:
|
|
918
|
+
model: googleVertex.image('imagen-4.0-generate-001'),
|
|
919
919
|
prompt: 'A futuristic cityscape at sunset',
|
|
920
920
|
aspectRatio: '16:9',
|
|
921
921
|
});
|
|
@@ -924,12 +924,12 @@ const { image } = await generateImage({
|
|
|
924
924
|
Further configuration can be done using Google Vertex provider options. You can validate the provider options using the `GoogleVertexImageModelOptions` type.
|
|
925
925
|
|
|
926
926
|
```ts
|
|
927
|
-
import {
|
|
927
|
+
import { googleVertex } from '@ai-sdk/google-vertex';
|
|
928
928
|
import { GoogleVertexImageModelOptions } from '@ai-sdk/google-vertex';
|
|
929
929
|
import { generateImage } from 'ai';
|
|
930
930
|
|
|
931
931
|
const { image } = await generateImage({
|
|
932
|
-
model:
|
|
932
|
+
model: googleVertex.image('imagen-4.0-generate-001'),
|
|
933
933
|
providerOptions: {
|
|
934
934
|
vertex: {
|
|
935
935
|
negativePrompt: 'pixelated, blurry, low-quality',
|
|
@@ -964,12 +964,12 @@ The following provider options are available:
|
|
|
964
964
|
Additional information about the images can be retrieved using Google Vertex meta data.
|
|
965
965
|
|
|
966
966
|
```ts
|
|
967
|
-
import {
|
|
967
|
+
import { googleVertex } from '@ai-sdk/google-vertex';
|
|
968
968
|
import { GoogleVertexImageModelOptions } from '@ai-sdk/google-vertex';
|
|
969
969
|
import { generateImage } from 'ai';
|
|
970
970
|
|
|
971
971
|
const { image, providerMetadata } = await generateImage({
|
|
972
|
-
model:
|
|
972
|
+
model: googleVertex.image('imagen-4.0-generate-001'),
|
|
973
973
|
prompt: 'A futuristic cityscape at sunset',
|
|
974
974
|
aspectRatio: '16:9',
|
|
975
975
|
});
|
|
@@ -993,7 +993,7 @@ Google Vertex Imagen models support image editing through inpainting, outpaintin
|
|
|
993
993
|
Insert or replace objects in specific areas using a mask:
|
|
994
994
|
|
|
995
995
|
```ts
|
|
996
|
-
import {
|
|
996
|
+
import { googleVertex, GoogleVertexImageModelOptions } from '@ai-sdk/google-vertex';
|
|
997
997
|
import { generateImage } from 'ai';
|
|
998
998
|
import fs from 'fs';
|
|
999
999
|
|
|
@@ -1001,7 +1001,7 @@ const image = fs.readFileSync('./input-image.png');
|
|
|
1001
1001
|
const mask = fs.readFileSync('./mask.png'); // White = edit area
|
|
1002
1002
|
|
|
1003
1003
|
const { images } = await generateImage({
|
|
1004
|
-
model:
|
|
1004
|
+
model: googleVertex.image('imagen-3.0-capability-001'),
|
|
1005
1005
|
prompt: {
|
|
1006
1006
|
text: 'A sunlit indoor lounge area with a pool containing a flamingo',
|
|
1007
1007
|
images: [image],
|
|
@@ -1025,7 +1025,7 @@ const { images } = await generateImage({
|
|
|
1025
1025
|
Extend an image beyond its original boundaries:
|
|
1026
1026
|
|
|
1027
1027
|
```ts
|
|
1028
|
-
import {
|
|
1028
|
+
import { googleVertex, GoogleVertexImageModelOptions } from '@ai-sdk/google-vertex';
|
|
1029
1029
|
import { generateImage } from 'ai';
|
|
1030
1030
|
import fs from 'fs';
|
|
1031
1031
|
|
|
@@ -1033,7 +1033,7 @@ const image = fs.readFileSync('./input-image.png');
|
|
|
1033
1033
|
const mask = fs.readFileSync('./outpaint-mask.png'); // White = extend area
|
|
1034
1034
|
|
|
1035
1035
|
const { images } = await generateImage({
|
|
1036
|
-
model:
|
|
1036
|
+
model: googleVertex.image('imagen-3.0-capability-001'),
|
|
1037
1037
|
prompt: {
|
|
1038
1038
|
text: 'Extend the scene with more of the forest background',
|
|
1039
1039
|
images: [image],
|
|
@@ -1098,11 +1098,11 @@ The following options are available under `providerOptions.vertex.edit`:
|
|
|
1098
1098
|
[Gemini image models](https://cloud.google.com/vertex-ai/generative-ai/docs/models/gemini/2-5-flash-image) (e.g. `gemini-2.5-flash-image`) are multimodal output language models that can be used with `generateImage()` for a simpler image generation experience. Internally, the provider calls the language model API with `responseModalities: ['IMAGE']`.
|
|
1099
1099
|
|
|
1100
1100
|
```ts
|
|
1101
|
-
import {
|
|
1101
|
+
import { googleVertex } from '@ai-sdk/google-vertex';
|
|
1102
1102
|
import { generateImage } from 'ai';
|
|
1103
1103
|
|
|
1104
1104
|
const { image } = await generateImage({
|
|
1105
|
-
model:
|
|
1105
|
+
model: googleVertex.image('gemini-2.5-flash-image'),
|
|
1106
1106
|
prompt: 'A photorealistic image of a cat wearing a wizard hat',
|
|
1107
1107
|
aspectRatio: '1:1',
|
|
1108
1108
|
});
|
|
@@ -1111,14 +1111,14 @@ const { image } = await generateImage({
|
|
|
1111
1111
|
Gemini image models also support image editing by providing input images:
|
|
1112
1112
|
|
|
1113
1113
|
```ts
|
|
1114
|
-
import {
|
|
1114
|
+
import { googleVertex } from '@ai-sdk/google-vertex';
|
|
1115
1115
|
import { generateImage } from 'ai';
|
|
1116
1116
|
import fs from 'node:fs';
|
|
1117
1117
|
|
|
1118
1118
|
const sourceImage = fs.readFileSync('./cat.png');
|
|
1119
1119
|
|
|
1120
1120
|
const { image } = await generateImage({
|
|
1121
|
-
model:
|
|
1121
|
+
model: googleVertex.image('gemini-2.5-flash-image'),
|
|
1122
1122
|
prompt: {
|
|
1123
1123
|
text: 'Add a small wizard hat to this cat',
|
|
1124
1124
|
images: [sourceImage],
|
|
@@ -1129,11 +1129,11 @@ const { image } = await generateImage({
|
|
|
1129
1129
|
You can also use URLs (including `gs://` Cloud Storage URIs) for input images:
|
|
1130
1130
|
|
|
1131
1131
|
```ts
|
|
1132
|
-
import {
|
|
1132
|
+
import { googleVertex } from '@ai-sdk/google-vertex';
|
|
1133
1133
|
import { generateImage } from 'ai';
|
|
1134
1134
|
|
|
1135
1135
|
const { image } = await generateImage({
|
|
1136
|
-
model:
|
|
1136
|
+
model: googleVertex.image('gemini-2.5-flash-image'),
|
|
1137
1137
|
prompt: {
|
|
1138
1138
|
text: 'Add a small wizard hat to this cat',
|
|
1139
1139
|
images: ['https://example.com/cat.png'],
|
|
@@ -1174,11 +1174,11 @@ You can create [Veo](https://cloud.google.com/vertex-ai/generative-ai/docs/video
|
|
|
1174
1174
|
using the `.video()` factory method. For more on video generation with the AI SDK see [generateVideo()](/docs/reference/ai-sdk-core/generate-video).
|
|
1175
1175
|
|
|
1176
1176
|
```ts
|
|
1177
|
-
import {
|
|
1177
|
+
import { googleVertex } from '@ai-sdk/google-vertex';
|
|
1178
1178
|
import { experimental_generateVideo as generateVideo } from 'ai';
|
|
1179
1179
|
|
|
1180
1180
|
const { video } = await generateVideo({
|
|
1181
|
-
model:
|
|
1181
|
+
model: googleVertex.video('veo-3.1-generate-001'),
|
|
1182
1182
|
prompt:
|
|
1183
1183
|
'A pangolin curled on a mossy stone in a glowing bioluminescent forest',
|
|
1184
1184
|
aspectRatio: '16:9',
|
|
@@ -1188,11 +1188,11 @@ const { video } = await generateVideo({
|
|
|
1188
1188
|
You can configure resolution and duration:
|
|
1189
1189
|
|
|
1190
1190
|
```ts
|
|
1191
|
-
import {
|
|
1191
|
+
import { googleVertex } from '@ai-sdk/google-vertex';
|
|
1192
1192
|
import { experimental_generateVideo as generateVideo } from 'ai';
|
|
1193
1193
|
|
|
1194
1194
|
const { video } = await generateVideo({
|
|
1195
|
-
model:
|
|
1195
|
+
model: googleVertex.video('veo-3.1-generate-001'),
|
|
1196
1196
|
prompt: 'A serene mountain landscape at sunset',
|
|
1197
1197
|
aspectRatio: '16:9',
|
|
1198
1198
|
resolution: '1920x1080',
|
|
@@ -1205,12 +1205,12 @@ const { video } = await generateVideo({
|
|
|
1205
1205
|
Further configuration can be done using Google Vertex provider options. You can validate the provider options using the `GoogleVertexVideoModelOptions` type.
|
|
1206
1206
|
|
|
1207
1207
|
```ts
|
|
1208
|
-
import {
|
|
1208
|
+
import { googleVertex } from '@ai-sdk/google-vertex';
|
|
1209
1209
|
import { GoogleVertexVideoModelOptions } from '@ai-sdk/google-vertex';
|
|
1210
1210
|
import { experimental_generateVideo as generateVideo } from 'ai';
|
|
1211
1211
|
|
|
1212
1212
|
const { video } = await generateVideo({
|
|
1213
|
-
model:
|
|
1213
|
+
model: googleVertex.video('veo-3.1-generate-001'),
|
|
1214
1214
|
prompt: 'A serene mountain landscape at sunset',
|
|
1215
1215
|
aspectRatio: '16:9',
|
|
1216
1216
|
providerOptions: {
|
|
@@ -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.
|