@ai-sdk/google 4.0.44 → 4.0.46

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.
@@ -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-2.5-flash`.
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-2.5-flash');
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-2.5-flash'),
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-2.5-flash');
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.1-pro-preview');
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-2.5-flash'),
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-2.5-flash'),
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 2.5 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.
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 2.5 Flash: 1024 tokens minimum
393
- - Gemini 2.5 Pro: 2048 tokens minimum
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-2.5-pro'),
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-2.5-pro'),
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: 2027,
421
+ // cachedContentTokenCount: 5027,
422
422
  // thoughtsTokenCount: 702,
423
- // promptTokenCount: 2152,
423
+ // promptTokenCount: 5152,
424
424
  // candidatesTokenCount: 710,
425
- // totalTokenCount: 3564
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 2.0 models. See the [models page](https://ai.google.dev/gemini-api/docs/models) to check if caching is supported for the used model:
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-2.5-pro';
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-2.5-pro'),
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-2.5-flash'),
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-2.5-flash'),
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-2.5-pro'),
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-2.5-flash'),
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-2.5-flash'),
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-2.5-flash'),
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-2.5-flash'),
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-2.5-flash'),
1009
+ model: google('gemini-3.7-flash'),
1010
1010
  providerOptions: {
1011
1011
  google: {
1012
1012
  structuredOutputs: false,
@@ -1199,13 +1199,13 @@ import { google } from '@ai-sdk/google';
1199
1199
  import { generateText } from 'ai';
1200
1200
 
1201
1201
  const { text } = await generateText({
1202
- model: google.interactions('gemini-2.5-flash'),
1202
+ model: google.interactions('gemini-3.7-flash'),
1203
1203
  prompt: 'Hello, how are you?',
1204
1204
  });
1205
1205
  ```
1206
1206
 
1207
1207
  `google.interactions(...)` accepts a model ID string (e.g.
1208
- `'gemini-2.5-flash'`, `'gemini-3-pro-preview'`), `{ agent: <name> }` to use
1208
+ `'gemini-3.7-flash'`, `'gemini-3.1-pro-preview'`), `{ agent: <name> }` to use
1209
1209
  a Gemini [agent preset](#agent-presets), or `{ managedAgent: <name> }` to
1210
1210
  invoke a [managed agent](#managed-agents) you created on Google's side.
1211
1211
  The returned model can be passed to `generateText` and `streamText` like
@@ -1232,7 +1232,7 @@ import {
1232
1232
  import { generateText } from 'ai';
1233
1233
 
1234
1234
  await generateText({
1235
- model: google.interactions('gemini-2.5-flash'),
1235
+ model: google.interactions('gemini-3.7-flash'),
1236
1236
  prompt: 'What color is the sky in one word?',
1237
1237
  providerOptions: {
1238
1238
  google: {
@@ -1372,7 +1372,7 @@ import {
1372
1372
  import { generateText } from 'ai';
1373
1373
 
1374
1374
  const turn1 = await generateText({
1375
- model: google.interactions('gemini-2.5-flash'),
1375
+ model: google.interactions('gemini-3.7-flash'),
1376
1376
  prompt: 'What are the three largest cities in Spain?',
1377
1377
  });
1378
1378
 
@@ -1381,7 +1381,7 @@ const interactionId = turn1.providerMetadata?.google?.interactionId as
1381
1381
  | undefined;
1382
1382
 
1383
1383
  const turn2 = await generateText({
1384
- model: google.interactions('gemini-2.5-flash'),
1384
+ model: google.interactions('gemini-3.7-flash'),
1385
1385
  prompt: 'What is the most famous landmark in the second one?',
1386
1386
  providerOptions: {
1387
1387
  google: {
@@ -1406,7 +1406,7 @@ const messages: Array<ModelMessage> = [
1406
1406
  ];
1407
1407
 
1408
1408
  const turn1 = await generateText({
1409
- model: google.interactions('gemini-2.5-flash'),
1409
+ model: google.interactions('gemini-3.7-flash'),
1410
1410
  messages,
1411
1411
  providerOptions: {
1412
1412
  google: { store: false } satisfies GoogleLanguageModelInteractionsOptions,
@@ -1420,7 +1420,7 @@ messages.push({
1420
1420
  });
1421
1421
 
1422
1422
  const turn2 = await generateText({
1423
- model: google.interactions('gemini-2.5-flash'),
1423
+ model: google.interactions('gemini-3.7-flash'),
1424
1424
  messages,
1425
1425
  providerOptions: {
1426
1426
  google: { store: false } satisfies GoogleLanguageModelInteractionsOptions,
@@ -1453,7 +1453,7 @@ import { google } from '@ai-sdk/google';
1453
1453
  import { generateText } from 'ai';
1454
1454
 
1455
1455
  const { text, sources } = await generateText({
1456
- model: google.interactions('gemini-2.5-flash'),
1456
+ model: google.interactions('gemini-3.7-flash'),
1457
1457
  tools: {
1458
1458
  google_search: google.tools.googleSearch({}),
1459
1459
  },
@@ -1477,7 +1477,7 @@ const weatherTool = tool({
1477
1477
  });
1478
1478
 
1479
1479
  const { text, toolCalls } = await generateText({
1480
- model: google.interactions('gemini-2.5-flash'),
1480
+ model: google.interactions('gemini-3.7-flash'),
1481
1481
  tools: { getWeather: weatherTool },
1482
1482
  stopWhen: stepCountIs(5),
1483
1483
  prompt: 'What is the weather in San Francisco right now?',
@@ -1776,7 +1776,7 @@ import { google } from '@ai-sdk/google';
1776
1776
  import { streamText } from 'ai';
1777
1777
 
1778
1778
  const result = streamText({
1779
- model: google.interactions('gemini-2.5-flash'),
1779
+ model: google.interactions('gemini-3.7-flash'),
1780
1780
  prompt: 'Hello, how are you?',
1781
1781
  });
1782
1782
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/google",
3
- "version": "4.0.44",
3
+ "version": "4.0.46",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -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,27 @@ 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 = getMinimumThinkingLevelForGemini3Model(modelId);
1192
+
1189
1193
  if (reasoning === 'none') {
1190
1194
  // It's not possible to fully disable thinking with Gemini 3.
1191
- return { thinkingLevel: 'minimal' };
1195
+ return { thinkingLevel: minimumThinkingLevel };
1192
1196
  }
1193
1197
 
1194
1198
  const thinkingLevel = mapReasoningToProviderEffort({
1195
1199
  reasoning,
1196
1200
  effortMap: {
1197
- minimal: 'minimal',
1201
+ minimal: minimumThinkingLevel,
1198
1202
  low: 'low',
1199
1203
  medium: 'medium',
1200
1204
  high: 'high',
@@ -1210,6 +1214,31 @@ function resolveGemini3ThinkingConfig({
1210
1214
  return { thinkingLevel };
1211
1215
  }
1212
1216
 
1217
+ function getMinimumThinkingLevelForGemini3Model(
1218
+ modelId: string,
1219
+ ): 'minimal' | 'low' {
1220
+ const modelName = modelId.split('/').at(-1)?.toLowerCase();
1221
+
1222
+ if (modelName === 'gemini-flash-latest') {
1223
+ return 'low';
1224
+ }
1225
+
1226
+ const versionMatch = /^gemini-(\d+)\.(\d+)-flash(?:$|-(?!lite(?:-|$)))/.exec(
1227
+ modelName ?? '',
1228
+ );
1229
+
1230
+ if (versionMatch == null) {
1231
+ return 'minimal';
1232
+ }
1233
+
1234
+ const majorVersion = Number(versionMatch[1]);
1235
+ const minorVersion = Number(versionMatch[2]);
1236
+
1237
+ return majorVersion > 3 || (majorVersion === 3 && minorVersion >= 7)
1238
+ ? 'low'
1239
+ : 'minimal';
1240
+ }
1241
+
1213
1242
  function resolveGemini25ThinkingConfig({
1214
1243
  reasoning,
1215
1244
  modelId,