@ai-sdk/google 4.0.95 → 4.0.96

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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # @ai-sdk/google
2
2
 
3
+ ## 4.0.96
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [2e89fa4]
8
+ - @ai-sdk/provider-utils@5.0.60
9
+
3
10
  ## 4.0.95
4
11
 
5
12
  ### Patch Changes
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import { Experimental_DecisionLanguageModel } from "@ai-sdk/provider-utils/exper
3
3
  import { AISDKError, InvalidArgumentError, InvalidResponseDataError, TooManyEmbeddingValuesForCallError, UnsupportedFunctionalityError } from "@ai-sdk/provider";
4
4
  import { z } from "zod/v4";
5
5
  //#region src/version.ts
6
- const VERSION = "4.0.95";
6
+ const VERSION = "4.0.96";
7
7
  //#endregion
8
8
  //#region src/google-error.ts
9
9
  const googleErrorDataSchema = lazySchema(() => zodSchema(z.object({ error: z.object({
@@ -1,18 +1,67 @@
1
1
  ---
2
2
  title: Google
3
- description: Learn how to use Google Provider.
3
+ description: Learn how to use Google models through AI Gateway or the direct Google provider.
4
4
  ---
5
5
 
6
6
  # Google Provider
7
7
 
8
- The [Google](https://ai.google.dev) provider contains language and embedding model support for
9
- the [Google](https://ai.google.dev/api/rest) APIs.
8
+ You can use [Google](https://ai.google.dev) models through [AI Gateway](/providers/ai-sdk-providers/ai-gateway) (recommended)
9
+ or connect directly to the [Google APIs](https://ai.google.dev/api/rest) with `@ai-sdk/google`.
10
10
 
11
- ## Setup
11
+ ```ts provider="google" model="google/gemini-4-argon" highlight="5"
12
+ import { generateText } from 'ai';
13
+ __PROVIDER_IMPORT__;
14
+
15
+ const { text } = await generateText({
16
+ model: __MODEL__,
17
+ prompt: 'Write a vegetarian lasagna recipe for 4 people.',
18
+ });
19
+
20
+ console.log(text);
21
+ ```
22
+
23
+ ## Using AI Gateway
24
+
25
+ The AI SDK uses AI Gateway by default for model strings.
26
+ AI Gateway provides access to Google and other providers through a single API key, with usage and cost tracking.
27
+ Install the `ai` package:
28
+
29
+ <InstallPackages packages="ai" />
30
+
31
+ Set an [AI Gateway API key](https://vercel.com/docs/ai-gateway/getting-started) in your environment:
12
32
 
13
- The Google provider is available in the `@ai-sdk/google` module. You can install it with
33
+ ```bash
34
+ export AI_GATEWAY_API_KEY=your_api_key_here
35
+ ```
36
+
37
+ Vercel deployments can also use [OIDC authentication](/providers/ai-sdk-providers/ai-gateway#oidc-authentication-vercel-deployments).
38
+ See the [AI Gateway provider documentation](/providers/ai-sdk-providers/ai-gateway) for configuration
39
+ and the [model catalog](https://vercel.com/ai-gateway/models?search=google) for available Google models.
40
+
41
+ Google model options can be passed through `providerOptions.google` when using AI Gateway.
42
+ Support depends on the model and the provider serving the request; see [Gateway provider options](https://vercel.com/docs/ai-gateway/models-and-providers/provider-options).
43
+
44
+ ## Using `@ai-sdk/google`
45
+
46
+ For direct access to the Google APIs, install `ai` and `@ai-sdk/google`:
47
+
48
+ <InstallPackages packages="ai @ai-sdk/google" />
14
49
 
15
- <InstallPackages packages="@ai-sdk/google" />
50
+ Set your [Google API key](https://aistudio.google.com/apikey) in the `GOOGLE_GENERATIVE_AI_API_KEY` environment variable:
51
+
52
+ ```bash
53
+ export GOOGLE_GENERATIVE_AI_API_KEY=your_api_key_here
54
+ ```
55
+
56
+ AI Gateway does not expose every API in `@ai-sdk/google`.
57
+ Use the direct provider for Google-specific APIs such as [`google.interactions(...)`](#interactions-api),
58
+ or when you need to customize the Google connection with [`createGoogle`](#provider-instance).
59
+
60
+ <Note>
61
+ The following sections document the direct `@ai-sdk/google` provider,
62
+ including its model factories, tools, and settings. Gateway model and feature
63
+ availability can differ from the direct provider.
64
+ </Note>
16
65
 
17
66
  ## Provider Instance
18
67
 
@@ -77,11 +126,11 @@ You can use the following optional settings to customize the Google provider ins
77
126
  ## Language Models
78
127
 
79
128
  You can create models that call the [Google Generative AI API](https://ai.google.dev/api/rest) using the provider instance.
80
- The first argument is the model id, e.g. `gemini-3.8-flash`.
129
+ The first argument is the model id, e.g. `gemini-4-argon`.
81
130
  The models support tool calls and some have multi-modal capabilities.
82
131
 
83
132
  ```ts
84
- const model = google('gemini-3.8-flash');
133
+ const model = google('gemini-4-argon');
85
134
  ```
86
135
 
87
136
  You can use Google language models to generate text with the `generateText` function:
@@ -91,7 +140,7 @@ import { google } from '@ai-sdk/google';
91
140
  import { generateText } from 'ai';
92
141
 
93
142
  const { text } = await generateText({
94
- model: google('gemini-3.8-flash'),
143
+ model: google('gemini-4-argon'),
95
144
  prompt: 'Write a vegetarian lasagna recipe for 4 people.',
96
145
  });
97
146
  ```
@@ -116,7 +165,7 @@ You can pass them as an options argument:
116
165
  ```ts
117
166
  import { google, type GoogleLanguageModelOptions } from '@ai-sdk/google';
118
167
 
119
- const model = google('gemini-3.8-flash');
168
+ const model = google('gemini-4-argon');
120
169
 
121
170
  await generateText({
122
171
  model,
@@ -276,7 +325,7 @@ For Gemini 3 and later models, use the `thinkingLevel` parameter to control the
276
325
  import { google, GoogleLanguageModelOptions } from '@ai-sdk/google';
277
326
  import { generateText } from 'ai';
278
327
 
279
- const model = google('gemini-3.8-flash');
328
+ const model = google('gemini-4-argon');
280
329
 
281
330
  const { text, reasoning } = await generateText({
282
331
  model: model,
@@ -463,7 +512,7 @@ import { google } from '@ai-sdk/google';
463
512
  import { generateText } from 'ai';
464
513
 
465
514
  const result = await generateText({
466
- model: google('gemini-3.8-flash'),
515
+ model: google('gemini-4-argon'),
467
516
  messages: [
468
517
  {
469
518
  role: 'user',
@@ -490,7 +539,7 @@ import { google } from '@ai-sdk/google';
490
539
  import { generateText } from 'ai';
491
540
 
492
541
  const result = await generateText({
493
- model: google('gemini-3.8-flash'),
542
+ model: google('gemini-4-argon'),
494
543
  messages: [
495
544
  {
496
545
  role: 'user',
@@ -526,7 +575,7 @@ Google supports both explicit and implicit caching to help reduce costs on repet
526
575
 
527
576
  #### Implicit Caching
528
577
 
529
- 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.
578
+ 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 can receive discounted pricing on cached input tokens.
530
579
 
531
580
  To maximize cache hits with implicit caching:
532
581
 
@@ -545,13 +594,13 @@ const baseContext =
545
594
  'You are a cooking assistant with expertise in Italian cuisine. Here are 1000 lasagna recipes for reference...';
546
595
 
547
596
  const { text: veggieLasagna } = await generateText({
548
- model: google('gemini-3.8-flash'),
597
+ model: google('gemini-4-argon'),
549
598
  prompt: `${baseContext}\n\nWrite a vegetarian lasagna recipe for 4 people.`,
550
599
  });
551
600
 
552
601
  // Second request with same prefix - eligible for cache hit
553
602
  const { text: meatLasagna, providerMetadata } = await generateText({
554
- model: google('gemini-3.8-flash'),
603
+ model: google('gemini-4-argon'),
555
604
  prompt: `${baseContext}\n\nWrite a meat lasagna recipe for 12 people.`,
556
605
  });
557
606
 
@@ -579,7 +628,7 @@ console.log('Cached tokens:', providerMetadata.google);
579
628
 
580
629
  #### Explicit Caching
581
630
 
582
- 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:
631
+ For guaranteed cost savings, you can still use explicit caching with Gemini 2.5 and 3 series models. Gemini 4 Argon supports implicit caching only, so this example uses `gemini-3.8-flash`. See the [models page](https://ai.google.dev/gemini-api/docs/models) to check if caching is supported for the used model:
583
632
 
584
633
  ```ts
585
634
  import { google, type GoogleLanguageModelOptions } from '@ai-sdk/google';
@@ -639,7 +688,7 @@ import { googleTools } from '@ai-sdk/google/internal';
639
688
  import { generateText } from 'ai';
640
689
 
641
690
  const { text, toolCalls, toolResults } = await generateText({
642
- model: google('gemini-3.8-flash'),
691
+ model: google('gemini-4-argon'),
643
692
  tools: { code_execution: google.tools.codeExecution({}) },
644
693
  prompt: 'Use python to calculate the 20th fibonacci number.',
645
694
  });
@@ -658,7 +707,7 @@ import { GoogleProviderMetadata } from '@ai-sdk/google';
658
707
  import { generateText } from 'ai';
659
708
 
660
709
  const { text, sources, providerMetadata } = await generateText({
661
- model: google('gemini-3.8-flash'),
710
+ model: google('gemini-4-argon'),
662
711
  tools: {
663
712
  google_search: google.tools.googleSearch({}),
664
713
  },
@@ -766,7 +815,7 @@ const vertex = createGoogleVertex({
766
815
  });
767
816
 
768
817
  const { text, sources, providerMetadata } = await generateText({
769
- model: vertex('gemini-3.8-flash'),
818
+ model: vertex('gemini-4-argon'),
770
819
  tools: {
771
820
  enterprise_web_search: vertex.tools.enterpriseWebSearch({}),
772
821
  },
@@ -789,7 +838,7 @@ import { google } from '@ai-sdk/google';
789
838
  import { generateText } from 'ai';
790
839
 
791
840
  const { text, sources, providerMetadata } = await generateText({
792
- model: google('gemini-3.8-flash'),
841
+ model: google('gemini-4-argon'),
793
842
  tools: {
794
843
  file_search: google.tools.fileSearch({
795
844
  fileSearchStoreNames: [
@@ -819,7 +868,7 @@ import { google } from '@ai-sdk/google';
819
868
  import { generateText } from 'ai';
820
869
 
821
870
  const { text, sources, providerMetadata } = await generateText({
822
- model: google('gemini-3.8-flash'),
871
+ model: google('gemini-4-argon'),
823
872
  prompt: `Based on the document: https://ai.google.dev/gemini-api/docs/url-context.
824
873
  Answer this question: How many links we can consume in one request?`,
825
874
  tools: {
@@ -897,7 +946,7 @@ import { google } from '@ai-sdk/google';
897
946
  import { generateText } from 'ai';
898
947
 
899
948
  const { text, sources, providerMetadata } = await generateText({
900
- model: google('gemini-3.8-flash'),
949
+ model: google('gemini-4-argon'),
901
950
  prompt: `Based on this context: https://ai-sdk.dev/providers/ai-sdk-providers/google, tell me how to use Gemini with AI SDK.
902
951
  Also, provide the latest news about AI SDK V5.`,
903
952
  tools: {
@@ -922,7 +971,7 @@ import { GoogleProviderMetadata } from '@ai-sdk/google';
922
971
  import { generateText } from 'ai';
923
972
 
924
973
  const { text, sources, providerMetadata } = await generateText({
925
- model: google('gemini-3.8-flash'),
974
+ model: google('gemini-4-argon'),
926
975
  tools: {
927
976
  google_maps: google.tools.googleMaps({}),
928
977
  },
@@ -986,7 +1035,7 @@ const vertex = createGoogleVertex({
986
1035
  });
987
1036
 
988
1037
  const { text, sources, providerMetadata } = await generateText({
989
- model: vertex('gemini-3.8-flash'),
1038
+ model: vertex('gemini-4-argon'),
990
1039
  tools: {
991
1040
  vertex_rag_store: vertex.tools.vertexRagStore({
992
1041
  ragCorpus:
@@ -1160,7 +1209,7 @@ You can also disable provider-enforced structured outputs for object generation:
1160
1209
 
1161
1210
  ```ts highlight="3,8"
1162
1211
  const { output } = await generateText({
1163
- model: google('gemini-3.8-flash'),
1212
+ model: google('gemini-4-argon'),
1164
1213
  providerOptions: {
1165
1214
  google: {
1166
1215
  structuredOutputs: false,
@@ -1243,7 +1292,7 @@ You can pass a `webhookUrl` to receive a notification when the batch reaches a t
1243
1292
  import { google } from '@ai-sdk/google';
1244
1293
  import { experimental_startBatch as startBatch } from 'ai';
1245
1294
 
1246
- const model = 'gemini-3.8-flash';
1295
+ const model = 'gemini-4-argon';
1247
1296
 
1248
1297
  const batch = await startBatch({
1249
1298
  provider: google,
@@ -1462,13 +1511,13 @@ import { google } from '@ai-sdk/google';
1462
1511
  import { generateText } from 'ai';
1463
1512
 
1464
1513
  const { text } = await generateText({
1465
- model: google.interactions('gemini-3.8-flash'),
1514
+ model: google.interactions('gemini-4-argon'),
1466
1515
  prompt: 'Hello, how are you?',
1467
1516
  });
1468
1517
  ```
1469
1518
 
1470
1519
  `google.interactions(...)` accepts a model ID string (e.g.
1471
- `'gemini-3.8-flash'`, `'gemini-3.1-pro-preview'`), `{ agent: <name> }` to use
1520
+ `'gemini-4-argon'`, `'gemini-3.1-pro-preview'`), `{ agent: <name> }` to use
1472
1521
  a Gemini [agent preset](#agent-presets), or `{ managedAgent: <name> }` to
1473
1522
  invoke a [managed agent](#managed-agents) you created on Google's side.
1474
1523
  The returned model can be passed to `generateText` and `streamText` like
@@ -1495,7 +1544,7 @@ import {
1495
1544
  import { generateText } from 'ai';
1496
1545
 
1497
1546
  await generateText({
1498
- model: google.interactions('gemini-3.8-flash'),
1547
+ model: google.interactions('gemini-4-argon'),
1499
1548
  prompt: 'What color is the sky in one word?',
1500
1549
  providerOptions: {
1501
1550
  google: {
@@ -1673,7 +1722,7 @@ import {
1673
1722
  import { generateText } from 'ai';
1674
1723
 
1675
1724
  const turn1 = await generateText({
1676
- model: google.interactions('gemini-3.8-flash'),
1725
+ model: google.interactions('gemini-4-argon'),
1677
1726
  prompt: 'What are the three largest cities in Spain?',
1678
1727
  });
1679
1728
 
@@ -1682,7 +1731,7 @@ const interactionId = turn1.providerMetadata?.google?.interactionId as
1682
1731
  | undefined;
1683
1732
 
1684
1733
  const turn2 = await generateText({
1685
- model: google.interactions('gemini-3.8-flash'),
1734
+ model: google.interactions('gemini-4-argon'),
1686
1735
  prompt: 'What is the most famous landmark in the second one?',
1687
1736
  providerOptions: {
1688
1737
  google: {
@@ -1707,7 +1756,7 @@ const messages: Array<ModelMessage> = [
1707
1756
  ];
1708
1757
 
1709
1758
  const turn1 = await generateText({
1710
- model: google.interactions('gemini-3.8-flash'),
1759
+ model: google.interactions('gemini-4-argon'),
1711
1760
  messages,
1712
1761
  providerOptions: {
1713
1762
  google: { store: false } satisfies GoogleLanguageModelInteractionsOptions,
@@ -1721,7 +1770,7 @@ messages.push({
1721
1770
  });
1722
1771
 
1723
1772
  const turn2 = await generateText({
1724
- model: google.interactions('gemini-3.8-flash'),
1773
+ model: google.interactions('gemini-4-argon'),
1725
1774
  messages,
1726
1775
  providerOptions: {
1727
1776
  google: { store: false } satisfies GoogleLanguageModelInteractionsOptions,
@@ -1731,7 +1780,7 @@ const turn2 = await generateText({
1731
1780
 
1732
1781
  ### Agentic video understanding
1733
1782
 
1734
- Gemini 3.7 Flash, 3.6 Flash, and 3.5 Flash Lite support agentic video
1783
+ Gemini 4 Argon, 3.7 Flash, 3.6 Flash, and 3.5 Flash Lite support agentic video
1735
1784
  understanding through the Interactions API. Instead of sampling the entire
1736
1785
  video at a fixed frame rate, the model dynamically navigates the timeline and
1737
1786
  loads the transcripts, frames, or audio needed for the prompt.
@@ -1745,7 +1794,7 @@ import { google, type GoogleInteractionsVideoOptions } from '@ai-sdk/google';
1745
1794
  import { generateText } from 'ai';
1746
1795
 
1747
1796
  const result = await generateText({
1748
- model: google.interactions('gemini-3.8-flash'),
1797
+ model: google.interactions('gemini-4-argon'),
1749
1798
  messages: [
1750
1799
  {
1751
1800
  role: 'user',
@@ -1845,7 +1894,7 @@ import { google } from '@ai-sdk/google';
1845
1894
  import { generateText } from 'ai';
1846
1895
 
1847
1896
  const { text, sources } = await generateText({
1848
- model: google.interactions('gemini-3.8-flash'),
1897
+ model: google.interactions('gemini-4-argon'),
1849
1898
  tools: {
1850
1899
  google_search: google.tools.googleSearch({}),
1851
1900
  },
@@ -1869,7 +1918,7 @@ const weatherTool = tool({
1869
1918
  });
1870
1919
 
1871
1920
  const { text, toolCalls } = await generateText({
1872
- model: google.interactions('gemini-3.8-flash'),
1921
+ model: google.interactions('gemini-4-argon'),
1873
1922
  tools: { getWeather: weatherTool },
1874
1923
  stopWhen: isStepCount(5),
1875
1924
  prompt: 'What is the weather in San Francisco right now?',
@@ -2168,7 +2217,7 @@ import { google } from '@ai-sdk/google';
2168
2217
  import { streamText } from 'ai';
2169
2218
 
2170
2219
  const result = streamText({
2171
- model: google.interactions('gemini-3.8-flash'),
2220
+ model: google.interactions('gemini-4-argon'),
2172
2221
  prompt: 'Hello, how are you?',
2173
2222
  });
2174
2223
 
@@ -2548,14 +2597,14 @@ Older models continue to use labelled transcripts, such as
2548
2597
 
2549
2598
  Create an experimental decision model with `google.decisionModel(modelId)`.
2550
2599
  It uses Gemini structured output for Choice, Score, and Boolean questions. Choose a model
2551
- that supports structured output, such as `gemini-3.5-flash-lite`.
2600
+ that supports structured output, such as `gemini-4-argon`.
2552
2601
 
2553
2602
  ```ts
2554
2603
  import { google } from '@ai-sdk/google';
2555
2604
  import { experimental_decide } from 'ai';
2556
2605
 
2557
2606
  const { answers } = await experimental_decide({
2558
- model: google.decisionModel('gemini-3.5-flash-lite'),
2607
+ model: google.decisionModel('gemini-4-argon'),
2559
2608
  state: 'I was charged twice.',
2560
2609
  questions: {
2561
2610
  requestsRefund: {
@@ -2569,7 +2618,7 @@ const { answers } = await experimental_decide({
2569
2618
  },
2570
2619
  },
2571
2620
  providerOptions: {
2572
- google: { thinkingConfig: { thinkingLevel: 'minimal' } },
2621
+ google: { thinkingConfig: { thinkingLevel: 'low' } },
2573
2622
  },
2574
2623
  });
2575
2624
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/google",
3
- "version": "4.0.95",
3
+ "version": "4.0.96",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@ai-sdk/provider": "4.0.27",
39
- "@ai-sdk/provider-utils": "5.0.59"
39
+ "@ai-sdk/provider-utils": "5.0.60"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@ai-sdk/test-server": "2.0.4",