@ai-sdk/google 3.0.13 → 3.0.15
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 +13 -0
- package/dist/index.d.mts +16 -16
- package/dist/index.d.ts +16 -16
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/docs/15-google-generative-ai.mdx +139 -32
- package/package.json +2 -2
- package/src/google-generative-ai-image-settings.ts +1 -1
- package/src/google-provider.ts +15 -15
|
@@ -69,6 +69,16 @@ You can use the following optional settings to customize the Google Generative A
|
|
|
69
69
|
You can use it as a middleware to intercept requests,
|
|
70
70
|
or to provide a custom fetch implementation for e.g. testing.
|
|
71
71
|
|
|
72
|
+
- **generateId** _() => string_
|
|
73
|
+
|
|
74
|
+
Optional function to generate unique IDs for each request.
|
|
75
|
+
Defaults to the SDK's built-in ID generator.
|
|
76
|
+
|
|
77
|
+
- **name** _string_
|
|
78
|
+
|
|
79
|
+
Custom provider name.
|
|
80
|
+
Defaults to `'google.generative-ai'`.
|
|
81
|
+
|
|
72
82
|
## Language Models
|
|
73
83
|
|
|
74
84
|
You can create models that call the [Google Generative AI API](https://ai.google.dev/api/rest) using the provider instance.
|
|
@@ -141,10 +151,12 @@ The following optional provider options are available for Google Generative AI m
|
|
|
141
151
|
|
|
142
152
|
The category of the safety setting. Can be one of the following:
|
|
143
153
|
|
|
154
|
+
- `HARM_CATEGORY_UNSPECIFIED`
|
|
144
155
|
- `HARM_CATEGORY_HATE_SPEECH`
|
|
145
156
|
- `HARM_CATEGORY_DANGEROUS_CONTENT`
|
|
146
157
|
- `HARM_CATEGORY_HARASSMENT`
|
|
147
158
|
- `HARM_CATEGORY_SEXUALLY_EXPLICIT`
|
|
159
|
+
- `HARM_CATEGORY_CIVIC_INTEGRITY`
|
|
148
160
|
|
|
149
161
|
- **threshold** _string_
|
|
150
162
|
|
|
@@ -155,6 +167,7 @@ The following optional provider options are available for Google Generative AI m
|
|
|
155
167
|
- `BLOCK_MEDIUM_AND_ABOVE`
|
|
156
168
|
- `BLOCK_ONLY_HIGH`
|
|
157
169
|
- `BLOCK_NONE`
|
|
170
|
+
- `OFF`
|
|
158
171
|
|
|
159
172
|
- **responseModalities** _string[]_
|
|
160
173
|
The modalities to use for the response. The following modalities are supported: `TEXT`, `IMAGE`. When not defined or empty, the model defaults to returning only text.
|
|
@@ -181,24 +194,58 @@ The following optional provider options are available for Google Generative AI m
|
|
|
181
194
|
|
|
182
195
|
Optional. If set to true, thought summaries are returned, which are synthisized versions of the model's raw thoughts and offer insights into the model's internal reasoning process.
|
|
183
196
|
|
|
184
|
-
- **imageConfig** _\{ aspectRatio
|
|
197
|
+
- **imageConfig** _\{ aspectRatio?: string, imageSize?: string \}_
|
|
185
198
|
|
|
186
199
|
Optional. Configuration for the models image generation. Only supported by specific [Google Generative AI models](https://ai.google.dev/gemini-api/docs/image-generation).
|
|
187
200
|
|
|
188
201
|
- **aspectRatio** _string_
|
|
189
202
|
|
|
190
|
-
|
|
203
|
+
Model defaults to generate 1:1 squares, or to matching the output image size to that of your input image. Can be one of the following:
|
|
204
|
+
|
|
205
|
+
- 1:1
|
|
206
|
+
- 2:3
|
|
207
|
+
- 3:2
|
|
208
|
+
- 3:4
|
|
209
|
+
- 4:3
|
|
210
|
+
- 4:5
|
|
211
|
+
- 5:4
|
|
212
|
+
- 9:16
|
|
213
|
+
- 16:9
|
|
214
|
+
- 21:9
|
|
215
|
+
|
|
216
|
+
- **imageSize** _string_
|
|
217
|
+
|
|
218
|
+
Controls the output image resolution. Defaults to 1K. Can be one of the following:
|
|
219
|
+
|
|
220
|
+
- 1K
|
|
221
|
+
- 2K
|
|
222
|
+
- 4K
|
|
223
|
+
|
|
224
|
+
- **audioTimestamp** _boolean_
|
|
225
|
+
|
|
226
|
+
Optional. Enables timestamp understanding for audio-only files.
|
|
227
|
+
See [Google Cloud audio understanding documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding).
|
|
228
|
+
|
|
229
|
+
- **mediaResolution** _string_
|
|
230
|
+
|
|
231
|
+
Optional. If specified, the media resolution specified will be used. Can be one of the following:
|
|
232
|
+
|
|
233
|
+
- `MEDIA_RESOLUTION_UNSPECIFIED`
|
|
234
|
+
- `MEDIA_RESOLUTION_LOW`
|
|
235
|
+
- `MEDIA_RESOLUTION_MEDIUM`
|
|
236
|
+
- `MEDIA_RESOLUTION_HIGH`
|
|
237
|
+
|
|
238
|
+
See [Google API MediaResolution documentation](https://ai.google.dev/api/generate-content#MediaResolution).
|
|
191
239
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
- 21:9
|
|
240
|
+
- **labels** _Record<string, string>_
|
|
241
|
+
|
|
242
|
+
Optional. Defines labels used in billing reports. Available on Vertex AI only.
|
|
243
|
+
See [Google Cloud labels documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/add-labels-to-api-calls).
|
|
244
|
+
|
|
245
|
+
- **threshold** _string_
|
|
246
|
+
|
|
247
|
+
Optional. Standalone threshold setting that can be used independently of `safetySettings`.
|
|
248
|
+
Uses the same values as the `safetySettings` threshold.
|
|
202
249
|
|
|
203
250
|
### Thinking
|
|
204
251
|
|
|
@@ -362,7 +409,7 @@ const { text: meatLasagna, providerMetadata } = await generateText({
|
|
|
362
409
|
});
|
|
363
410
|
|
|
364
411
|
// Check cached token count in usage metadata
|
|
365
|
-
console.log('Cached tokens:', providerMetadata.google
|
|
412
|
+
console.log('Cached tokens:', providerMetadata.google);
|
|
366
413
|
// e.g.
|
|
367
414
|
// {
|
|
368
415
|
// groundingMetadata: null,
|
|
@@ -389,42 +436,45 @@ For guaranteed cost savings, you can still use explicit caching with Gemini 2.5
|
|
|
389
436
|
|
|
390
437
|
```ts
|
|
391
438
|
import { google } from '@ai-sdk/google';
|
|
392
|
-
import {
|
|
439
|
+
import { GoogleGenAI } from '@google/genai';
|
|
393
440
|
import { generateText } from 'ai';
|
|
394
441
|
|
|
395
|
-
const
|
|
396
|
-
process.env.GOOGLE_GENERATIVE_AI_API_KEY,
|
|
397
|
-
);
|
|
442
|
+
const ai = new GoogleGenAI({
|
|
443
|
+
apiKey: process.env.GOOGLE_GENERATIVE_AI_API_KEY,
|
|
444
|
+
});
|
|
398
445
|
|
|
399
446
|
const model = 'gemini-2.5-pro';
|
|
400
447
|
|
|
401
|
-
|
|
448
|
+
// Create a cache with the content you want to reuse
|
|
449
|
+
const cache = await ai.caches.create({
|
|
402
450
|
model,
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
451
|
+
config: {
|
|
452
|
+
contents: [
|
|
453
|
+
{
|
|
454
|
+
role: 'user',
|
|
455
|
+
parts: [{ text: '1000 Lasagna Recipes...' }],
|
|
456
|
+
},
|
|
457
|
+
],
|
|
458
|
+
ttl: '300s', // Cache expires after 5 minutes
|
|
459
|
+
},
|
|
410
460
|
});
|
|
411
461
|
|
|
412
|
-
const { text:
|
|
462
|
+
const { text: veggieLasagnaRecipe } = await generateText({
|
|
413
463
|
model: google(model),
|
|
414
464
|
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
|
|
415
465
|
providerOptions: {
|
|
416
466
|
google: {
|
|
417
|
-
cachedContent,
|
|
467
|
+
cachedContent: cache.name,
|
|
418
468
|
},
|
|
419
469
|
},
|
|
420
470
|
});
|
|
421
471
|
|
|
422
|
-
const { text:
|
|
472
|
+
const { text: meatLasagnaRecipe } = await generateText({
|
|
423
473
|
model: google(model),
|
|
424
474
|
prompt: 'Write a meat lasagna recipe for 12 people.',
|
|
425
475
|
providerOptions: {
|
|
426
476
|
google: {
|
|
427
|
-
cachedContent,
|
|
477
|
+
cachedContent: cache.name,
|
|
428
478
|
},
|
|
429
479
|
},
|
|
430
480
|
});
|
|
@@ -480,6 +530,19 @@ const groundingMetadata = metadata?.groundingMetadata;
|
|
|
480
530
|
const safetyRatings = metadata?.safetyRatings;
|
|
481
531
|
```
|
|
482
532
|
|
|
533
|
+
The `googleSearch` tool accepts the following optional configuration options:
|
|
534
|
+
|
|
535
|
+
- **mode** _'MODE_DYNAMIC' | 'MODE_UNSPECIFIED'_
|
|
536
|
+
|
|
537
|
+
The mode of the predictor to be used in dynamic retrieval. Default is `'MODE_UNSPECIFIED'`.
|
|
538
|
+
|
|
539
|
+
- `MODE_DYNAMIC`: Run retrieval only when the system decides it is necessary
|
|
540
|
+
- `MODE_UNSPECIFIED`: Always trigger retrieval
|
|
541
|
+
|
|
542
|
+
- **dynamicThreshold** _number_
|
|
543
|
+
|
|
544
|
+
The threshold to be used in dynamic retrieval. Default is `1`. If not set, a system default value is used.
|
|
545
|
+
|
|
483
546
|
When Search Grounding is enabled, the model will include sources in the response.
|
|
484
547
|
|
|
485
548
|
Additionally, the grounding metadata includes detailed information about how search results were used to ground the model's response. Here are the available fields:
|
|
@@ -528,6 +591,42 @@ Example response:
|
|
|
528
591
|
}
|
|
529
592
|
```
|
|
530
593
|
|
|
594
|
+
### Enterprise Web Search
|
|
595
|
+
|
|
596
|
+
With [Enterprise Web Search](https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/web-grounding-enterprise),
|
|
597
|
+
the model has access to a compliance-focused web index designed for highly-regulated industries such as finance, healthcare, and public sector.
|
|
598
|
+
|
|
599
|
+
<Note>
|
|
600
|
+
Enterprise Web Search is only available on Vertex AI. You must use the Google
|
|
601
|
+
Vertex provider (`@ai-sdk/google-vertex`) instead of the standard Google
|
|
602
|
+
provider (`@ai-sdk/google`) to use this feature. Requires Gemini 2.0 or newer
|
|
603
|
+
models.
|
|
604
|
+
</Note>
|
|
605
|
+
|
|
606
|
+
```ts
|
|
607
|
+
import { createVertex } from '@ai-sdk/google-vertex';
|
|
608
|
+
import { generateText } from 'ai';
|
|
609
|
+
|
|
610
|
+
const vertex = createVertex({
|
|
611
|
+
project: 'my-project',
|
|
612
|
+
location: 'us-central1',
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
const { text, sources, providerMetadata } = await generateText({
|
|
616
|
+
model: vertex('gemini-2.5-flash'),
|
|
617
|
+
tools: {
|
|
618
|
+
enterprise_web_search: vertex.tools.enterpriseWebSearch({}),
|
|
619
|
+
},
|
|
620
|
+
prompt: 'What are the latest regulatory updates for financial services?',
|
|
621
|
+
});
|
|
622
|
+
```
|
|
623
|
+
|
|
624
|
+
Enterprise Web Search provides the following benefits:
|
|
625
|
+
|
|
626
|
+
- Does not log customer data
|
|
627
|
+
- Supports VPC service controls
|
|
628
|
+
- Compliance-focused web index for regulated industries
|
|
629
|
+
|
|
531
630
|
### File Search
|
|
532
631
|
|
|
533
632
|
The [File Search tool](https://ai.google.dev/gemini-api/docs/file-search) lets Gemini retrieve context from your own documents that you have indexed in File Search stores. Only Gemini 2.5 and Gemini 3 models support this feature.
|
|
@@ -939,6 +1038,8 @@ The following Zod features are known to not work with Google Generative AI:
|
|
|
939
1038
|
| Model | Image Input | Object Generation | Tool Usage | Tool Streaming | Google Search | URL Context |
|
|
940
1039
|
| ------------------------------------- | ------------------- | ------------------- | ------------------- | ------------------- | ------------------- | ------------------- |
|
|
941
1040
|
| `gemini-3-pro-preview` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
1041
|
+
| `gemini-3-pro-image-preview` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
1042
|
+
| `gemini-3-flash-preview` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
942
1043
|
| `gemini-2.5-pro` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
943
1044
|
| `gemini-2.5-flash` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
944
1045
|
| `gemini-2.5-flash-lite` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
@@ -961,6 +1062,10 @@ The following Zod features are known to not work with Google Generative AI:
|
|
|
961
1062
|
## Gemma Models
|
|
962
1063
|
|
|
963
1064
|
You can use [Gemma models](https://deepmind.google/models/gemma/) with the Google Generative AI API.
|
|
1065
|
+
The following Gemma models are available:
|
|
1066
|
+
|
|
1067
|
+
- `gemma-3-27b-it`
|
|
1068
|
+
- `gemma-3-12b-it`
|
|
964
1069
|
|
|
965
1070
|
Gemma models don't natively support the `systemInstruction` parameter, but the provider automatically handles system instructions by prepending them to the first user message. This allows you to use system instructions with Gemma models seamlessly:
|
|
966
1071
|
|
|
@@ -1083,6 +1188,8 @@ The following provider options are available:
|
|
|
1083
1188
|
|
|
1084
1189
|
#### Model Capabilities
|
|
1085
1190
|
|
|
1086
|
-
| Model
|
|
1087
|
-
|
|
|
1088
|
-
| `imagen-4.0-generate-001`
|
|
1191
|
+
| Model | Aspect Ratios |
|
|
1192
|
+
| ------------------------------- | ------------------------- |
|
|
1193
|
+
| `imagen-4.0-generate-001` | 1:1, 3:4, 4:3, 9:16, 16:9 |
|
|
1194
|
+
| `imagen-4.0-ultra-generate-001` | 1:1, 3:4, 4:3, 9:16, 16:9 |
|
|
1195
|
+
| `imagen-4.0-fast-generate-001` | 1:1, 3:4, 4:3, 9:16, 16:9 |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/google",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.15",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@ai-sdk/provider": "3.0.5",
|
|
40
|
-
"@ai-sdk/provider-utils": "4.0.
|
|
40
|
+
"@ai-sdk/provider-utils": "4.0.10"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/node": "20.17.24",
|
|
@@ -6,7 +6,7 @@ export type GoogleGenerativeAIImageModelId =
|
|
|
6
6
|
|
|
7
7
|
export interface GoogleGenerativeAIImageSettings {
|
|
8
8
|
/**
|
|
9
|
-
Override the maximum number of images per call (default 4)
|
|
9
|
+
* Override the maximum number of images per call (default 4)
|
|
10
10
|
*/
|
|
11
11
|
maxImagesPerCall?: number;
|
|
12
12
|
}
|
package/src/google-provider.ts
CHANGED
|
@@ -32,8 +32,8 @@ export interface GoogleGenerativeAIProvider extends ProviderV3 {
|
|
|
32
32
|
chat(modelId: GoogleGenerativeAIModelId): LanguageModelV3;
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
Creates a model for image generation.
|
|
36
|
-
|
|
35
|
+
* Creates a model for image generation.
|
|
36
|
+
*/
|
|
37
37
|
image(
|
|
38
38
|
modelId: GoogleGenerativeAIImageModelId,
|
|
39
39
|
settings?: GoogleGenerativeAIImageSettings,
|
|
@@ -71,31 +71,31 @@ Creates a model for image generation.
|
|
|
71
71
|
|
|
72
72
|
export interface GoogleGenerativeAIProviderSettings {
|
|
73
73
|
/**
|
|
74
|
-
Use a different URL prefix for API calls, e.g. to use proxy servers.
|
|
75
|
-
The default prefix is `https://generativelanguage.googleapis.com/v1beta`.
|
|
74
|
+
* Use a different URL prefix for API calls, e.g. to use proxy servers.
|
|
75
|
+
* The default prefix is `https://generativelanguage.googleapis.com/v1beta`.
|
|
76
76
|
*/
|
|
77
77
|
baseURL?: string;
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
|
-
API key that is being send using the `x-goog-api-key` header.
|
|
81
|
-
It defaults to the `GOOGLE_GENERATIVE_AI_API_KEY` environment variable.
|
|
80
|
+
* API key that is being send using the `x-goog-api-key` header.
|
|
81
|
+
* It defaults to the `GOOGLE_GENERATIVE_AI_API_KEY` environment variable.
|
|
82
82
|
*/
|
|
83
83
|
apiKey?: string;
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
|
-
Custom headers to include in the requests.
|
|
87
|
-
|
|
86
|
+
* Custom headers to include in the requests.
|
|
87
|
+
*/
|
|
88
88
|
headers?: Record<string, string | undefined>;
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
|
-
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
92
|
-
or to provide a custom fetch implementation for e.g. testing.
|
|
93
|
-
|
|
91
|
+
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
92
|
+
* or to provide a custom fetch implementation for e.g. testing.
|
|
93
|
+
*/
|
|
94
94
|
fetch?: FetchFunction;
|
|
95
95
|
|
|
96
96
|
/**
|
|
97
|
-
Optional function to generate a unique ID for each request.
|
|
98
|
-
|
|
97
|
+
* Optional function to generate a unique ID for each request.
|
|
98
|
+
*/
|
|
99
99
|
generateId?: () => string;
|
|
100
100
|
|
|
101
101
|
/**
|
|
@@ -106,7 +106,7 @@ Optional function to generate a unique ID for each request.
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
/**
|
|
109
|
-
Create a Google Generative AI provider instance.
|
|
109
|
+
* Create a Google Generative AI provider instance.
|
|
110
110
|
*/
|
|
111
111
|
export function createGoogleGenerativeAI(
|
|
112
112
|
options: GoogleGenerativeAIProviderSettings = {},
|
|
@@ -196,6 +196,6 @@ export function createGoogleGenerativeAI(
|
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
/**
|
|
199
|
-
Default Google Generative AI provider instance.
|
|
199
|
+
* Default Google Generative AI provider instance.
|
|
200
200
|
*/
|
|
201
201
|
export const google = createGoogleGenerativeAI();
|