@ai-sdk/google 4.0.43 → 4.0.45
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 +12 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +2 -2
- package/dist/internal/index.js +5 -3
- package/dist/internal/index.js.map +1 -1
- package/docs/15-google.mdx +37 -36
- package/package.json +1 -1
- package/src/google-language-model-options.ts +1 -0
- package/src/google-language-model.ts +9 -3
- package/src/interactions/google-interactions-language-model-options.ts +1 -0
package/docs/15-google.mdx
CHANGED
|
@@ -68,11 +68,11 @@ You can use the following optional settings to customize the Google provider ins
|
|
|
68
68
|
## Language Models
|
|
69
69
|
|
|
70
70
|
You can create models that call the [Google Generative AI API](https://ai.google.dev/api/rest) using the provider instance.
|
|
71
|
-
The first argument is the model id, e.g. `gemini-
|
|
71
|
+
The first argument is the model id, e.g. `gemini-3.7-flash`.
|
|
72
72
|
The models support tool calls and some have multi-modal capabilities.
|
|
73
73
|
|
|
74
74
|
```ts
|
|
75
|
-
const model = google('gemini-
|
|
75
|
+
const model = google('gemini-3.7-flash');
|
|
76
76
|
```
|
|
77
77
|
|
|
78
78
|
You can use Google language models to generate text with the `generateText` function:
|
|
@@ -82,7 +82,7 @@ import { google } from '@ai-sdk/google';
|
|
|
82
82
|
import { generateText } from 'ai';
|
|
83
83
|
|
|
84
84
|
const { text } = await generateText({
|
|
85
|
-
model: google('gemini-
|
|
85
|
+
model: google('gemini-3.7-flash'),
|
|
86
86
|
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
|
|
87
87
|
});
|
|
88
88
|
```
|
|
@@ -107,7 +107,7 @@ You can pass them as an options argument:
|
|
|
107
107
|
```ts
|
|
108
108
|
import { google, type GoogleLanguageModelOptions } from '@ai-sdk/google';
|
|
109
109
|
|
|
110
|
-
const model = google('gemini-
|
|
110
|
+
const model = google('gemini-3.7-flash');
|
|
111
111
|
|
|
112
112
|
await generateText({
|
|
113
113
|
model,
|
|
@@ -262,7 +262,7 @@ For Gemini 3 and later models, use the `thinkingLevel` parameter to control the
|
|
|
262
262
|
import { google, GoogleLanguageModelOptions } from '@ai-sdk/google';
|
|
263
263
|
import { generateText } from 'ai';
|
|
264
264
|
|
|
265
|
-
const model = google('gemini-3.
|
|
265
|
+
const model = google('gemini-3.7-flash');
|
|
266
266
|
|
|
267
267
|
const { text, reasoning } = await generateText({
|
|
268
268
|
model: model,
|
|
@@ -319,7 +319,7 @@ import { google } from '@ai-sdk/google';
|
|
|
319
319
|
import { generateText } from 'ai';
|
|
320
320
|
|
|
321
321
|
const result = await generateText({
|
|
322
|
-
model: google('gemini-
|
|
322
|
+
model: google('gemini-3.7-flash'),
|
|
323
323
|
messages: [
|
|
324
324
|
{
|
|
325
325
|
role: 'user',
|
|
@@ -346,7 +346,7 @@ import { google } from '@ai-sdk/google';
|
|
|
346
346
|
import { generateText } from 'ai';
|
|
347
347
|
|
|
348
348
|
const result = await generateText({
|
|
349
|
-
model: google('gemini-
|
|
349
|
+
model: google('gemini-3.7-flash'),
|
|
350
350
|
messages: [
|
|
351
351
|
{
|
|
352
352
|
role: 'user',
|
|
@@ -382,15 +382,15 @@ Google supports both explicit and implicit caching to help reduce costs on repet
|
|
|
382
382
|
|
|
383
383
|
#### Implicit Caching
|
|
384
384
|
|
|
385
|
-
Gemini
|
|
385
|
+
Gemini models automatically provide cache cost savings without needing to create an explicit cache. When you send requests that share common prefixes with previous requests, you'll receive a 75% token discount on cached content.
|
|
386
386
|
|
|
387
387
|
To maximize cache hits with implicit caching:
|
|
388
388
|
|
|
389
389
|
- Keep content at the beginning of requests consistent
|
|
390
390
|
- Add variable content (like user questions) at the end of prompts
|
|
391
391
|
- Ensure requests meet minimum token requirements:
|
|
392
|
-
- Gemini
|
|
393
|
-
- Gemini 2.5
|
|
392
|
+
- Gemini 3 series: 4096 tokens minimum
|
|
393
|
+
- Gemini 2.5 series: 2048 tokens minimum
|
|
394
394
|
|
|
395
395
|
```ts
|
|
396
396
|
import { google } from '@ai-sdk/google';
|
|
@@ -401,13 +401,13 @@ const baseContext =
|
|
|
401
401
|
'You are a cooking assistant with expertise in Italian cuisine. Here are 1000 lasagna recipes for reference...';
|
|
402
402
|
|
|
403
403
|
const { text: veggieLasagna } = await generateText({
|
|
404
|
-
model: google('gemini-
|
|
404
|
+
model: google('gemini-3.7-flash'),
|
|
405
405
|
prompt: `${baseContext}\n\nWrite a vegetarian lasagna recipe for 4 people.`,
|
|
406
406
|
});
|
|
407
407
|
|
|
408
408
|
// Second request with same prefix - eligible for cache hit
|
|
409
409
|
const { text: meatLasagna, providerMetadata } = await generateText({
|
|
410
|
-
model: google('gemini-
|
|
410
|
+
model: google('gemini-3.7-flash'),
|
|
411
411
|
prompt: `${baseContext}\n\nWrite a meat lasagna recipe for 12 people.`,
|
|
412
412
|
});
|
|
413
413
|
|
|
@@ -418,11 +418,11 @@ console.log('Cached tokens:', providerMetadata.google);
|
|
|
418
418
|
// groundingMetadata: null,
|
|
419
419
|
// safetyRatings: null,
|
|
420
420
|
// usageMetadata: {
|
|
421
|
-
// cachedContentTokenCount:
|
|
421
|
+
// cachedContentTokenCount: 5027,
|
|
422
422
|
// thoughtsTokenCount: 702,
|
|
423
|
-
// promptTokenCount:
|
|
423
|
+
// promptTokenCount: 5152,
|
|
424
424
|
// candidatesTokenCount: 710,
|
|
425
|
-
// totalTokenCount:
|
|
425
|
+
// totalTokenCount: 6564
|
|
426
426
|
// }
|
|
427
427
|
// }
|
|
428
428
|
```
|
|
@@ -435,7 +435,7 @@ console.log('Cached tokens:', providerMetadata.google);
|
|
|
435
435
|
|
|
436
436
|
#### Explicit Caching
|
|
437
437
|
|
|
438
|
-
For guaranteed cost savings, you can still use explicit caching with Gemini 2.5 and
|
|
438
|
+
For guaranteed cost savings, you can still use explicit caching with Gemini 2.5 and 3 series models. See the [models page](https://ai.google.dev/gemini-api/docs/models) to check if caching is supported for the used model:
|
|
439
439
|
|
|
440
440
|
```ts
|
|
441
441
|
import { google, type GoogleLanguageModelOptions } from '@ai-sdk/google';
|
|
@@ -446,7 +446,7 @@ const ai = new GoogleGenAI({
|
|
|
446
446
|
apiKey: process.env.GOOGLE_GENERATIVE_AI_API_KEY,
|
|
447
447
|
});
|
|
448
448
|
|
|
449
|
-
const model = 'gemini-
|
|
449
|
+
const model = 'gemini-3.7-flash';
|
|
450
450
|
|
|
451
451
|
// Create a cache with the content you want to reuse
|
|
452
452
|
const cache = await ai.caches.create({
|
|
@@ -495,7 +495,7 @@ import { googleTools } from '@ai-sdk/google/internal';
|
|
|
495
495
|
import { generateText } from 'ai';
|
|
496
496
|
|
|
497
497
|
const { text, toolCalls, toolResults } = await generateText({
|
|
498
|
-
model: google('gemini-
|
|
498
|
+
model: google('gemini-3.7-flash'),
|
|
499
499
|
tools: { code_execution: google.tools.codeExecution({}) },
|
|
500
500
|
prompt: 'Use python to calculate the 20th fibonacci number.',
|
|
501
501
|
});
|
|
@@ -514,7 +514,7 @@ import { GoogleProviderMetadata } from '@ai-sdk/google';
|
|
|
514
514
|
import { generateText } from 'ai';
|
|
515
515
|
|
|
516
516
|
const { text, sources, providerMetadata } = await generateText({
|
|
517
|
-
model: google('gemini-
|
|
517
|
+
model: google('gemini-3.7-flash'),
|
|
518
518
|
tools: {
|
|
519
519
|
google_search: google.tools.googleSearch({}),
|
|
520
520
|
},
|
|
@@ -622,7 +622,7 @@ const vertex = createGoogleVertex({
|
|
|
622
622
|
});
|
|
623
623
|
|
|
624
624
|
const { text, sources, providerMetadata } = await generateText({
|
|
625
|
-
model: vertex('gemini-
|
|
625
|
+
model: vertex('gemini-3.7-flash'),
|
|
626
626
|
tools: {
|
|
627
627
|
enterprise_web_search: vertex.tools.enterpriseWebSearch({}),
|
|
628
628
|
},
|
|
@@ -645,7 +645,7 @@ import { google } from '@ai-sdk/google';
|
|
|
645
645
|
import { generateText } from 'ai';
|
|
646
646
|
|
|
647
647
|
const { text, sources } = await generateText({
|
|
648
|
-
model: google('gemini-
|
|
648
|
+
model: google('gemini-3.7-flash'),
|
|
649
649
|
tools: {
|
|
650
650
|
file_search: google.tools.fileSearch({
|
|
651
651
|
fileSearchStoreNames: [
|
|
@@ -672,7 +672,7 @@ import { google } from '@ai-sdk/google';
|
|
|
672
672
|
import { generateText } from 'ai';
|
|
673
673
|
|
|
674
674
|
const { text, sources, providerMetadata } = await generateText({
|
|
675
|
-
model: google('gemini-
|
|
675
|
+
model: google('gemini-3.7-flash'),
|
|
676
676
|
prompt: `Based on the document: https://ai.google.dev/gemini-api/docs/url-context.
|
|
677
677
|
Answer this question: How many links we can consume in one request?`,
|
|
678
678
|
tools: {
|
|
@@ -750,7 +750,7 @@ import { google } from '@ai-sdk/google';
|
|
|
750
750
|
import { generateText } from 'ai';
|
|
751
751
|
|
|
752
752
|
const { text, sources, providerMetadata } = await generateText({
|
|
753
|
-
model: google('gemini-
|
|
753
|
+
model: google('gemini-3.7-flash'),
|
|
754
754
|
prompt: `Based on this context: https://ai-sdk.dev/providers/ai-sdk-providers/google, tell me how to use Gemini with AI SDK.
|
|
755
755
|
Also, provide the latest news about AI SDK V5.`,
|
|
756
756
|
tools: {
|
|
@@ -775,7 +775,7 @@ import { GoogleProviderMetadata } from '@ai-sdk/google';
|
|
|
775
775
|
import { generateText } from 'ai';
|
|
776
776
|
|
|
777
777
|
const { text, sources, providerMetadata } = await generateText({
|
|
778
|
-
model: google('gemini-
|
|
778
|
+
model: google('gemini-3.7-flash'),
|
|
779
779
|
tools: {
|
|
780
780
|
google_maps: google.tools.googleMaps({}),
|
|
781
781
|
},
|
|
@@ -839,7 +839,7 @@ const vertex = createGoogleVertex({
|
|
|
839
839
|
});
|
|
840
840
|
|
|
841
841
|
const { text, sources, providerMetadata } = await generateText({
|
|
842
|
-
model: vertex('gemini-
|
|
842
|
+
model: vertex('gemini-3.7-flash'),
|
|
843
843
|
tools: {
|
|
844
844
|
vertex_rag_store: vertex.tools.vertexRagStore({
|
|
845
845
|
ragCorpus:
|
|
@@ -1006,7 +1006,7 @@ You can disable structured outputs for object generation as a workaround:
|
|
|
1006
1006
|
|
|
1007
1007
|
```ts highlight="3,8"
|
|
1008
1008
|
const { output } = await generateText({
|
|
1009
|
-
model: google('gemini-
|
|
1009
|
+
model: google('gemini-3.7-flash'),
|
|
1010
1010
|
providerOptions: {
|
|
1011
1011
|
google: {
|
|
1012
1012
|
structuredOutputs: false,
|
|
@@ -1041,6 +1041,7 @@ The following Zod features are known to not work with Google:
|
|
|
1041
1041
|
|
|
1042
1042
|
| Model | Image Input | Object Generation | Tool Usage | Tool Streaming | Google Search | URL Context |
|
|
1043
1043
|
| ------------------------------------- | ----------- | ----------------- | ---------- | -------------- | ------------- | ----------- |
|
|
1044
|
+
| `gemini-3.7-flash` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
1044
1045
|
| `gemini-3.6-flash` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
1045
1046
|
| `gemini-3.5-flash` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
1046
1047
|
| `gemini-3.5-flash-lite` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
@@ -1198,13 +1199,13 @@ import { google } from '@ai-sdk/google';
|
|
|
1198
1199
|
import { generateText } from 'ai';
|
|
1199
1200
|
|
|
1200
1201
|
const { text } = await generateText({
|
|
1201
|
-
model: google.interactions('gemini-
|
|
1202
|
+
model: google.interactions('gemini-3.7-flash'),
|
|
1202
1203
|
prompt: 'Hello, how are you?',
|
|
1203
1204
|
});
|
|
1204
1205
|
```
|
|
1205
1206
|
|
|
1206
1207
|
`google.interactions(...)` accepts a model ID string (e.g.
|
|
1207
|
-
`'gemini-
|
|
1208
|
+
`'gemini-3.7-flash'`, `'gemini-3.1-pro-preview'`), `{ agent: <name> }` to use
|
|
1208
1209
|
a Gemini [agent preset](#agent-presets), or `{ managedAgent: <name> }` to
|
|
1209
1210
|
invoke a [managed agent](#managed-agents) you created on Google's side.
|
|
1210
1211
|
The returned model can be passed to `generateText` and `streamText` like
|
|
@@ -1231,7 +1232,7 @@ import {
|
|
|
1231
1232
|
import { generateText } from 'ai';
|
|
1232
1233
|
|
|
1233
1234
|
await generateText({
|
|
1234
|
-
model: google.interactions('gemini-
|
|
1235
|
+
model: google.interactions('gemini-3.7-flash'),
|
|
1235
1236
|
prompt: 'What color is the sky in one word?',
|
|
1236
1237
|
providerOptions: {
|
|
1237
1238
|
google: {
|
|
@@ -1371,7 +1372,7 @@ import {
|
|
|
1371
1372
|
import { generateText } from 'ai';
|
|
1372
1373
|
|
|
1373
1374
|
const turn1 = await generateText({
|
|
1374
|
-
model: google.interactions('gemini-
|
|
1375
|
+
model: google.interactions('gemini-3.7-flash'),
|
|
1375
1376
|
prompt: 'What are the three largest cities in Spain?',
|
|
1376
1377
|
});
|
|
1377
1378
|
|
|
@@ -1380,7 +1381,7 @@ const interactionId = turn1.providerMetadata?.google?.interactionId as
|
|
|
1380
1381
|
| undefined;
|
|
1381
1382
|
|
|
1382
1383
|
const turn2 = await generateText({
|
|
1383
|
-
model: google.interactions('gemini-
|
|
1384
|
+
model: google.interactions('gemini-3.7-flash'),
|
|
1384
1385
|
prompt: 'What is the most famous landmark in the second one?',
|
|
1385
1386
|
providerOptions: {
|
|
1386
1387
|
google: {
|
|
@@ -1405,7 +1406,7 @@ const messages: Array<ModelMessage> = [
|
|
|
1405
1406
|
];
|
|
1406
1407
|
|
|
1407
1408
|
const turn1 = await generateText({
|
|
1408
|
-
model: google.interactions('gemini-
|
|
1409
|
+
model: google.interactions('gemini-3.7-flash'),
|
|
1409
1410
|
messages,
|
|
1410
1411
|
providerOptions: {
|
|
1411
1412
|
google: { store: false } satisfies GoogleLanguageModelInteractionsOptions,
|
|
@@ -1419,7 +1420,7 @@ messages.push({
|
|
|
1419
1420
|
});
|
|
1420
1421
|
|
|
1421
1422
|
const turn2 = await generateText({
|
|
1422
|
-
model: google.interactions('gemini-
|
|
1423
|
+
model: google.interactions('gemini-3.7-flash'),
|
|
1423
1424
|
messages,
|
|
1424
1425
|
providerOptions: {
|
|
1425
1426
|
google: { store: false } satisfies GoogleLanguageModelInteractionsOptions,
|
|
@@ -1452,7 +1453,7 @@ import { google } from '@ai-sdk/google';
|
|
|
1452
1453
|
import { generateText } from 'ai';
|
|
1453
1454
|
|
|
1454
1455
|
const { text, sources } = await generateText({
|
|
1455
|
-
model: google.interactions('gemini-
|
|
1456
|
+
model: google.interactions('gemini-3.7-flash'),
|
|
1456
1457
|
tools: {
|
|
1457
1458
|
google_search: google.tools.googleSearch({}),
|
|
1458
1459
|
},
|
|
@@ -1476,7 +1477,7 @@ const weatherTool = tool({
|
|
|
1476
1477
|
});
|
|
1477
1478
|
|
|
1478
1479
|
const { text, toolCalls } = await generateText({
|
|
1479
|
-
model: google.interactions('gemini-
|
|
1480
|
+
model: google.interactions('gemini-3.7-flash'),
|
|
1480
1481
|
tools: { getWeather: weatherTool },
|
|
1481
1482
|
stopWhen: stepCountIs(5),
|
|
1482
1483
|
prompt: 'What is the weather in San Francisco right now?',
|
|
@@ -1775,7 +1776,7 @@ import { google } from '@ai-sdk/google';
|
|
|
1775
1776
|
import { streamText } from 'ai';
|
|
1776
1777
|
|
|
1777
1778
|
const result = streamText({
|
|
1778
|
-
model: google.interactions('gemini-
|
|
1779
|
+
model: google.interactions('gemini-3.7-flash'),
|
|
1779
1780
|
prompt: 'Hello, how are you?',
|
|
1780
1781
|
});
|
|
1781
1782
|
|
package/package.json
CHANGED
|
@@ -1170,7 +1170,7 @@ function resolveThinkingConfig({
|
|
|
1170
1170
|
getGoogleModelCapabilities(modelId).usesGemini3Features &&
|
|
1171
1171
|
!modelId.includes('gemini-3-pro-image')
|
|
1172
1172
|
) {
|
|
1173
|
-
return resolveGemini3ThinkingConfig({ reasoning, warnings });
|
|
1173
|
+
return resolveGemini3ThinkingConfig({ reasoning, modelId, warnings });
|
|
1174
1174
|
}
|
|
1175
1175
|
|
|
1176
1176
|
return resolveGemini25ThinkingConfig({ reasoning, modelId, warnings });
|
|
@@ -1178,23 +1178,29 @@ function resolveThinkingConfig({
|
|
|
1178
1178
|
|
|
1179
1179
|
function resolveGemini3ThinkingConfig({
|
|
1180
1180
|
reasoning,
|
|
1181
|
+
modelId,
|
|
1181
1182
|
warnings,
|
|
1182
1183
|
}: {
|
|
1183
1184
|
reasoning: Exclude<
|
|
1184
1185
|
LanguageModelV4CallOptions['reasoning'],
|
|
1185
1186
|
'provider-default' | undefined
|
|
1186
1187
|
>;
|
|
1188
|
+
modelId: string;
|
|
1187
1189
|
warnings: SharedV4Warning[];
|
|
1188
1190
|
}): Pick<GoogleThinkingConfig, 'thinkingLevel'> | undefined {
|
|
1191
|
+
const minimumThinkingLevel = /(^|\/)gemini-3\.7-flash$/i.test(modelId)
|
|
1192
|
+
? 'low'
|
|
1193
|
+
: 'minimal';
|
|
1194
|
+
|
|
1189
1195
|
if (reasoning === 'none') {
|
|
1190
1196
|
// It's not possible to fully disable thinking with Gemini 3.
|
|
1191
|
-
return { thinkingLevel:
|
|
1197
|
+
return { thinkingLevel: minimumThinkingLevel };
|
|
1192
1198
|
}
|
|
1193
1199
|
|
|
1194
1200
|
const thinkingLevel = mapReasoningToProviderEffort({
|
|
1195
1201
|
reasoning,
|
|
1196
1202
|
effortMap: {
|
|
1197
|
-
minimal:
|
|
1203
|
+
minimal: minimumThinkingLevel,
|
|
1198
1204
|
low: 'low',
|
|
1199
1205
|
medium: 'medium',
|
|
1200
1206
|
high: 'high',
|