@ai-sdk/google-vertex 4.0.28 → 4.0.29

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,14 @@
1
1
  # @ai-sdk/google-vertex
2
2
 
3
+ ## 4.0.29
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [462ad00]
8
+ - @ai-sdk/provider-utils@4.0.10
9
+ - @ai-sdk/anthropic@3.0.24
10
+ - @ai-sdk/google@3.0.14
11
+
3
12
  ## 4.0.28
4
13
 
5
14
  ### Patch Changes
@@ -32,7 +32,7 @@ var import_provider_utils3 = require("@ai-sdk/provider-utils");
32
32
  var import_provider_utils = require("@ai-sdk/provider-utils");
33
33
 
34
34
  // src/version.ts
35
- var VERSION = true ? "4.0.28" : "0.0.0-test";
35
+ var VERSION = true ? "4.0.29" : "0.0.0-test";
36
36
 
37
37
  // src/edge/google-vertex-auth-edge.ts
38
38
  var loadCredentials = async () => {
@@ -10,7 +10,7 @@ import {
10
10
  } from "@ai-sdk/provider-utils";
11
11
 
12
12
  // src/version.ts
13
- var VERSION = true ? "4.0.28" : "0.0.0-test";
13
+ var VERSION = true ? "4.0.29" : "0.0.0-test";
14
14
 
15
15
  // src/edge/google-vertex-auth-edge.ts
16
16
  var loadCredentials = async () => {
@@ -33,7 +33,7 @@ var import_internal2 = require("@ai-sdk/google/internal");
33
33
  var import_provider_utils4 = require("@ai-sdk/provider-utils");
34
34
 
35
35
  // src/version.ts
36
- var VERSION = true ? "4.0.28" : "0.0.0-test";
36
+ var VERSION = true ? "4.0.29" : "0.0.0-test";
37
37
 
38
38
  // src/google-vertex-embedding-model.ts
39
39
  var import_provider = require("@ai-sdk/provider");
@@ -14,7 +14,7 @@ import {
14
14
  } from "@ai-sdk/provider-utils";
15
15
 
16
16
  // src/version.ts
17
- var VERSION = true ? "4.0.28" : "0.0.0-test";
17
+ var VERSION = true ? "4.0.29" : "0.0.0-test";
18
18
 
19
19
  // src/google-vertex-embedding-model.ts
20
20
  import {
package/dist/index.js CHANGED
@@ -55,7 +55,7 @@ var import_internal2 = require("@ai-sdk/google/internal");
55
55
  var import_provider_utils4 = require("@ai-sdk/provider-utils");
56
56
 
57
57
  // src/version.ts
58
- var VERSION = true ? "4.0.28" : "0.0.0-test";
58
+ var VERSION = true ? "4.0.29" : "0.0.0-test";
59
59
 
60
60
  // src/google-vertex-embedding-model.ts
61
61
  var import_provider = require("@ai-sdk/provider");
package/dist/index.mjs CHANGED
@@ -35,7 +35,7 @@ import {
35
35
  } from "@ai-sdk/provider-utils";
36
36
 
37
37
  // src/version.ts
38
- var VERSION = true ? "4.0.28" : "0.0.0-test";
38
+ var VERSION = true ? "4.0.29" : "0.0.0-test";
39
39
 
40
40
  // src/google-vertex-embedding-model.ts
41
41
  import {
@@ -287,6 +287,11 @@ await generateText({
287
287
 
288
288
  The following optional provider options are available for Google Vertex models:
289
289
 
290
+ - **cachedContent** _string_
291
+
292
+ Optional. The name of the cached content used as context to serve the prediction.
293
+ Format: projects/\{project\}/locations/\{location\}/cachedContents/\{cachedContent\}
294
+
290
295
  - **structuredOutputs** _boolean_
291
296
 
292
297
  Optional. Enable structured output. Default is true.
@@ -546,6 +551,109 @@ const { text } = await generateText({
546
551
 
547
552
  See [File Parts](/docs/foundations/prompts#file-parts) for details on how to use files in prompts.
548
553
 
554
+ ### Cached Content
555
+
556
+ Google Vertex AI supports both explicit and implicit caching to help reduce costs on repetitive content.
557
+
558
+ #### Implicit Caching
559
+
560
+ ```ts
561
+ import { vertex } from '@ai-sdk/google-vertex';
562
+ import { generateText } from 'ai';
563
+
564
+ // Structure prompts with consistent content at the beginning
565
+ const baseContext =
566
+ 'You are a cooking assistant with expertise in Italian cuisine. Here are 1000 lasagna recipes for reference...';
567
+
568
+ const { text: veggieLasagna } = await generateText({
569
+ model: vertex('gemini-2.5-pro'),
570
+ prompt: `${baseContext}\n\nWrite a vegetarian lasagna recipe for 4 people.`,
571
+ });
572
+
573
+ // Second request with same prefix - eligible for cache hit
574
+ const { text: meatLasagna, providerMetadata } = await generateText({
575
+ model: vertex('gemini-2.5-pro'),
576
+ prompt: `${baseContext}\n\nWrite a meat lasagna recipe for 12 people.`,
577
+ });
578
+
579
+ // Check cached token count in usage metadata
580
+ console.log('Cached tokens:', providerMetadata.google);
581
+ // e.g.
582
+ // {
583
+ // groundingMetadata: null,
584
+ // safetyRatings: null,
585
+ // usageMetadata: {
586
+ // cachedContentTokenCount: 2027,
587
+ // thoughtsTokenCount: 702,
588
+ // promptTokenCount: 2152,
589
+ // candidatesTokenCount: 710,
590
+ // totalTokenCount: 3564
591
+ // }
592
+ // }
593
+ ```
594
+
595
+ #### Explicit Caching
596
+
597
+ You can use explicit caching with Gemini models. See the [Vertex AI context caching documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/context-cache/context-cache-overview) to check if caching is supported for your model.
598
+
599
+ First, create a cache using the Google GenAI SDK with Vertex mode enabled:
600
+
601
+ ```ts
602
+ import { GoogleGenAI } from '@google/genai';
603
+
604
+ const ai = new GoogleGenAI({
605
+ vertexai: true,
606
+ project: process.env.GOOGLE_VERTEX_PROJECT,
607
+ location: process.env.GOOGLE_VERTEX_LOCATION,
608
+ });
609
+
610
+ const model = 'gemini-2.5-pro';
611
+
612
+ // Create a cache with the content you want to reuse
613
+ const cache = await ai.caches.create({
614
+ model,
615
+ config: {
616
+ contents: [
617
+ {
618
+ role: 'user',
619
+ parts: [{ text: '1000 Lasagna Recipes...' }],
620
+ },
621
+ ],
622
+ ttl: '300s', // Cache expires after 5 minutes
623
+ },
624
+ });
625
+
626
+ console.log('Cache created:', cache.name);
627
+ // e.g. projects/my-project/locations/us-central1/cachedContents/abc123
628
+ ```
629
+
630
+ Then use the cache with the AI SDK:
631
+
632
+ ```ts
633
+ import { vertex } from '@ai-sdk/google-vertex';
634
+ import { generateText } from 'ai';
635
+
636
+ const { text: veggieLasagnaRecipe } = await generateText({
637
+ model: vertex('gemini-2.5-pro'),
638
+ prompt: 'Write a vegetarian lasagna recipe for 4 people.',
639
+ providerOptions: {
640
+ google: {
641
+ cachedContent: cache.name,
642
+ },
643
+ },
644
+ });
645
+
646
+ const { text: meatLasagnaRecipe } = await generateText({
647
+ model: vertex('gemini-2.5-pro'),
648
+ prompt: 'Write a meat lasagna recipe for 12 people.',
649
+ providerOptions: {
650
+ google: {
651
+ cachedContent: cache.name,
652
+ },
653
+ },
654
+ });
655
+ ```
656
+
549
657
  ### Safety Ratings
550
658
 
551
659
  The safety ratings provide insight into the safety of the model's response.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/google-vertex",
3
- "version": "4.0.28",
3
+ "version": "4.0.29",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -48,10 +48,10 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "google-auth-library": "^10.5.0",
51
- "@ai-sdk/anthropic": "3.0.23",
52
- "@ai-sdk/google": "3.0.13",
51
+ "@ai-sdk/anthropic": "3.0.24",
53
52
  "@ai-sdk/provider": "3.0.5",
54
- "@ai-sdk/provider-utils": "4.0.9"
53
+ "@ai-sdk/provider-utils": "4.0.10",
54
+ "@ai-sdk/google": "3.0.14"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@types/node": "20.17.24",