@ai-sdk/google 4.0.0-beta.9 → 4.0.0-canary.51
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 +354 -4
- package/README.md +6 -4
- package/dist/index.d.ts +97 -54
- package/dist/index.js +1643 -575
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +62 -22
- package/dist/internal/index.js +1261 -449
- package/dist/internal/index.js.map +1 -1
- package/docs/{15-google-generative-ai.mdx → 15-google.mdx} +46 -40
- package/package.json +13 -14
- package/src/{convert-google-generative-ai-usage.ts → convert-google-usage.ts} +11 -4
- package/src/convert-json-schema-to-openapi-schema.ts +1 -1
- package/src/convert-to-google-messages.ts +585 -0
- package/src/{google-generative-ai-embedding-options.ts → google-embedding-model-options.ts} +2 -2
- package/src/{google-generative-ai-embedding-model.ts → google-embedding-model.ts} +28 -15
- package/src/google-error.ts +1 -1
- package/src/google-files.ts +225 -0
- package/src/google-image-model-options.ts +23 -0
- package/src/{google-generative-ai-image-model.ts → google-image-model.ts} +61 -49
- package/src/{google-generative-ai-image-settings.ts → google-image-settings.ts} +2 -2
- package/src/google-json-accumulator.ts +336 -0
- package/src/{google-generative-ai-options.ts → google-language-model-options.ts} +32 -5
- package/src/{google-generative-ai-language-model.ts → google-language-model.ts} +586 -191
- package/src/google-prepare-tools.ts +68 -8
- package/src/google-prompt.ts +82 -0
- package/src/google-provider.ts +56 -47
- package/src/google-video-model-options.ts +43 -0
- package/src/{google-generative-ai-video-model.ts → google-video-model.ts} +11 -50
- package/src/{google-generative-ai-video-settings.ts → google-video-settings.ts} +2 -1
- package/src/index.ts +28 -9
- package/src/internal/index.ts +2 -2
- package/src/{map-google-generative-ai-finish-reason.ts → map-google-finish-reason.ts} +2 -2
- package/src/tool/code-execution.ts +2 -2
- package/src/tool/enterprise-web-search.ts +9 -3
- package/src/tool/file-search.ts +5 -7
- package/src/tool/google-maps.ts +3 -2
- package/src/tool/google-search.ts +10 -11
- package/src/tool/url-context.ts +4 -2
- package/src/tool/vertex-rag-store.ts +9 -6
- package/dist/index.d.mts +0 -384
- package/dist/index.mjs +0 -2519
- package/dist/index.mjs.map +0 -1
- package/dist/internal/index.d.mts +0 -287
- package/dist/internal/index.mjs +0 -1708
- package/dist/internal/index.mjs.map +0 -1
- package/src/convert-to-google-generative-ai-messages.ts +0 -239
- package/src/google-generative-ai-prompt.ts +0 -47
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: Google
|
|
3
|
-
description: Learn how to use Google
|
|
2
|
+
title: Google
|
|
3
|
+
description: Learn how to use Google Provider.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# Google
|
|
6
|
+
# Google Provider
|
|
7
7
|
|
|
8
|
-
The [Google
|
|
9
|
-
the [Google
|
|
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.
|
|
10
10
|
|
|
11
11
|
## Setup
|
|
12
12
|
|
|
@@ -36,17 +36,17 @@ You can import the default provider instance `google` from `@ai-sdk/google`:
|
|
|
36
36
|
import { google } from '@ai-sdk/google';
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
If you need a customized setup, you can import `
|
|
39
|
+
If you need a customized setup, you can import `createGoogle` from `@ai-sdk/google` and create a provider instance with your settings:
|
|
40
40
|
|
|
41
41
|
```ts
|
|
42
|
-
import {
|
|
42
|
+
import { createGoogle } from '@ai-sdk/google';
|
|
43
43
|
|
|
44
|
-
const google =
|
|
44
|
+
const google = createGoogle({
|
|
45
45
|
// custom settings
|
|
46
46
|
});
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
You can use the following optional settings to customize the Google
|
|
49
|
+
You can use the following optional settings to customize the Google provider instance:
|
|
50
50
|
|
|
51
51
|
- **baseURL** _string_
|
|
52
52
|
|
|
@@ -89,7 +89,7 @@ The models support tool calls and some have multi-modal capabilities.
|
|
|
89
89
|
const model = google('gemini-2.5-flash');
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
-
You can use Google
|
|
92
|
+
You can use Google language models to generate text with the `generateText` function:
|
|
93
93
|
|
|
94
94
|
```ts
|
|
95
95
|
import { google } from '@ai-sdk/google';
|
|
@@ -101,11 +101,11 @@ const { text } = await generateText({
|
|
|
101
101
|
});
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
Google
|
|
104
|
+
Google language models can also be used in the `streamText` function
|
|
105
105
|
and support structured data generation with [`Output`](/docs/reference/ai-sdk-core/output)
|
|
106
106
|
(see [AI SDK Core](/docs/ai-sdk-core)).
|
|
107
107
|
|
|
108
|
-
Google
|
|
108
|
+
Google also supports some model specific settings that are not part of the [standard call settings](/docs/ai-sdk-core/settings).
|
|
109
109
|
You can pass them as an options argument:
|
|
110
110
|
|
|
111
111
|
```ts
|
|
@@ -128,7 +128,7 @@ await generateText({
|
|
|
128
128
|
});
|
|
129
129
|
```
|
|
130
130
|
|
|
131
|
-
The following optional provider options are available for Google
|
|
131
|
+
The following optional provider options are available for Google models:
|
|
132
132
|
|
|
133
133
|
- **cachedContent** _string_
|
|
134
134
|
|
|
@@ -141,7 +141,7 @@ The following optional provider options are available for Google Generative AI m
|
|
|
141
141
|
|
|
142
142
|
This is useful when the JSON Schema contains elements that are
|
|
143
143
|
not supported by the OpenAPI schema version that
|
|
144
|
-
Google
|
|
144
|
+
Google uses. You can use this to disable
|
|
145
145
|
structured outputs if you need to.
|
|
146
146
|
|
|
147
147
|
See [Troubleshooting: Schema Limitations](#schema-limitations) for more details.
|
|
@@ -177,7 +177,7 @@ The following optional provider options are available for Google Generative AI m
|
|
|
177
177
|
|
|
178
178
|
- **thinkingConfig** _\{ thinkingLevel?: 'minimal' | 'low' | 'medium' | 'high'; thinkingBudget?: number; includeThoughts?: boolean \}_
|
|
179
179
|
|
|
180
|
-
Optional. Configuration for the model's thinking process. Only supported by specific [Google
|
|
180
|
+
Optional. Configuration for the model's thinking process. Only supported by specific [Google models](https://ai.google.dev/gemini-api/docs/thinking).
|
|
181
181
|
|
|
182
182
|
- **thinkingLevel** _'minimal' | 'low' | 'medium' | 'high'_
|
|
183
183
|
|
|
@@ -186,7 +186,7 @@ The following optional provider options are available for Google Generative AI m
|
|
|
186
186
|
- **thinkingBudget** _number_
|
|
187
187
|
|
|
188
188
|
Optional. Gives the model guidance on the number of thinking tokens it can use when generating a response. Setting it to 0 disables thinking, if the model supports it.
|
|
189
|
-
For more information about the possible value ranges for each model see [Google
|
|
189
|
+
For more information about the possible value ranges for each model see [Google thinking documentation](https://ai.google.dev/gemini-api/docs/thinking#set-budget).
|
|
190
190
|
|
|
191
191
|
<Note>
|
|
192
192
|
This option is for Gemini 2.5 models. Gemini 3 models should use
|
|
@@ -199,7 +199,7 @@ The following optional provider options are available for Google Generative AI m
|
|
|
199
199
|
|
|
200
200
|
- **imageConfig** _\{ aspectRatio?: string, imageSize?: string \}_
|
|
201
201
|
|
|
202
|
-
Optional. Configuration for the models image generation. Only supported by specific [Google
|
|
202
|
+
Optional. Configuration for the models image generation. Only supported by specific [Google models](https://ai.google.dev/gemini-api/docs/image-generation).
|
|
203
203
|
|
|
204
204
|
- **aspectRatio** _string_
|
|
205
205
|
|
|
@@ -245,6 +245,12 @@ The following optional provider options are available for Google Generative AI m
|
|
|
245
245
|
Optional. Defines labels used in billing reports. Available on Vertex AI only.
|
|
246
246
|
See [Google Cloud labels documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/add-labels-to-api-calls).
|
|
247
247
|
|
|
248
|
+
- **serviceTier** _'standard' | 'flex' | 'priority'_
|
|
249
|
+
|
|
250
|
+
Optional. The service tier to use for the request.
|
|
251
|
+
Set to 'flex' for 50% cheaper processing at the cost of increased latency.
|
|
252
|
+
Set to 'priority' for ultra-low latency at a 75-100% price premium over 'standard'.
|
|
253
|
+
|
|
248
254
|
- **threshold** _string_
|
|
249
255
|
|
|
250
256
|
Optional. Standalone threshold setting that can be used independently of `safetySettings`.
|
|
@@ -252,7 +258,7 @@ The following optional provider options are available for Google Generative AI m
|
|
|
252
258
|
|
|
253
259
|
### Thinking
|
|
254
260
|
|
|
255
|
-
The Gemini 2.5 and Gemini 3 series models use an internal "thinking process" that significantly improves their reasoning and multi-step planning abilities, making them highly effective for complex tasks such as coding, advanced mathematics, and data analysis. For more information see [Google
|
|
261
|
+
The Gemini 2.5 and Gemini 3 series models use an internal "thinking process" that significantly improves their reasoning and multi-step planning abilities, making them highly effective for complex tasks such as coding, advanced mathematics, and data analysis. For more information see [Google thinking documentation](https://ai.google.dev/gemini-api/docs/thinking).
|
|
256
262
|
|
|
257
263
|
#### Gemini 3 Models
|
|
258
264
|
|
|
@@ -312,7 +318,7 @@ console.log(reasoning); // Reasoning summary
|
|
|
312
318
|
|
|
313
319
|
### File Inputs
|
|
314
320
|
|
|
315
|
-
The Google
|
|
321
|
+
The Google provider supports file inputs, e.g. PDF files.
|
|
316
322
|
|
|
317
323
|
```ts
|
|
318
324
|
import { google } from '@ai-sdk/google';
|
|
@@ -378,7 +384,7 @@ See [File Parts](/docs/foundations/prompts#file-parts) for details on how to use
|
|
|
378
384
|
|
|
379
385
|
### Cached Content
|
|
380
386
|
|
|
381
|
-
Google
|
|
387
|
+
Google supports both explicit and implicit caching to help reduce costs on repetitive content.
|
|
382
388
|
|
|
383
389
|
#### Implicit Caching
|
|
384
390
|
|
|
@@ -510,7 +516,7 @@ the model has access to the latest information using Google Search.
|
|
|
510
516
|
|
|
511
517
|
```ts highlight="8,17-20"
|
|
512
518
|
import { google } from '@ai-sdk/google';
|
|
513
|
-
import {
|
|
519
|
+
import { GoogleProviderMetadata } from '@ai-sdk/google';
|
|
514
520
|
import { generateText } from 'ai';
|
|
515
521
|
|
|
516
522
|
const { text, sources, providerMetadata } = await generateText({
|
|
@@ -526,7 +532,7 @@ const { text, sources, providerMetadata } = await generateText({
|
|
|
526
532
|
// access the grounding metadata. Casting to the provider metadata type
|
|
527
533
|
// is optional but provides autocomplete and type safety.
|
|
528
534
|
const metadata = providerMetadata?.google as
|
|
529
|
-
|
|
|
535
|
+
| GoogleProviderMetadata
|
|
530
536
|
| undefined;
|
|
531
537
|
const groundingMetadata = metadata?.groundingMetadata;
|
|
532
538
|
const safetyRatings = metadata?.safetyRatings;
|
|
@@ -619,10 +625,10 @@ the model has access to a compliance-focused web index designed for highly-regul
|
|
|
619
625
|
</Note>
|
|
620
626
|
|
|
621
627
|
```ts
|
|
622
|
-
import {
|
|
628
|
+
import { createGoogleVertex } from '@ai-sdk/google-vertex';
|
|
623
629
|
import { generateText } from 'ai';
|
|
624
630
|
|
|
625
|
-
const vertex =
|
|
631
|
+
const vertex = createGoogleVertex({
|
|
626
632
|
project: 'my-project',
|
|
627
633
|
location: 'us-central1',
|
|
628
634
|
});
|
|
@@ -687,7 +693,7 @@ const { text, sources, providerMetadata } = await generateText({
|
|
|
687
693
|
});
|
|
688
694
|
|
|
689
695
|
const metadata = providerMetadata?.google as
|
|
690
|
-
|
|
|
696
|
+
| GoogleProviderMetadata
|
|
691
697
|
| undefined;
|
|
692
698
|
const groundingMetadata = metadata?.groundingMetadata;
|
|
693
699
|
const urlContextMetadata = metadata?.urlContextMetadata;
|
|
@@ -708,7 +714,7 @@ Example response:
|
|
|
708
714
|
{
|
|
709
715
|
"urlMetadata": [
|
|
710
716
|
{
|
|
711
|
-
"retrievedUrl": "https://ai-sdk.dev/providers/ai-sdk-providers/google
|
|
717
|
+
"retrievedUrl": "https://ai-sdk.dev/providers/ai-sdk-providers/google",
|
|
712
718
|
"urlRetrievalStatus": "URL_RETRIEVAL_STATUS_SUCCESS"
|
|
713
719
|
}
|
|
714
720
|
]
|
|
@@ -722,8 +728,8 @@ With the URL context tool, you will also get the `groundingMetadata`.
|
|
|
722
728
|
"groundingChunks": [
|
|
723
729
|
{
|
|
724
730
|
"web": {
|
|
725
|
-
"uri": "https://ai-sdk.dev/providers/ai-sdk-providers/google
|
|
726
|
-
"title": "Google
|
|
731
|
+
"uri": "https://ai-sdk.dev/providers/ai-sdk-providers/google",
|
|
732
|
+
"title": "Google - AI SDK Providers"
|
|
727
733
|
}
|
|
728
734
|
}
|
|
729
735
|
],
|
|
@@ -760,7 +766,7 @@ import { generateText } from 'ai';
|
|
|
760
766
|
|
|
761
767
|
const { text, sources, providerMetadata } = await generateText({
|
|
762
768
|
model: google('gemini-2.5-flash'),
|
|
763
|
-
prompt: `Based on this context: https://ai-sdk.dev/providers/ai-sdk-providers/google
|
|
769
|
+
prompt: `Based on this context: https://ai-sdk.dev/providers/ai-sdk-providers/google, tell me how to use Gemini with AI SDK.
|
|
764
770
|
Also, provide the latest news about AI SDK V5.`,
|
|
765
771
|
tools: {
|
|
766
772
|
google_search: google.tools.googleSearch({}),
|
|
@@ -769,7 +775,7 @@ const { text, sources, providerMetadata } = await generateText({
|
|
|
769
775
|
});
|
|
770
776
|
|
|
771
777
|
const metadata = providerMetadata?.google as
|
|
772
|
-
|
|
|
778
|
+
| GoogleProviderMetadata
|
|
773
779
|
| undefined;
|
|
774
780
|
const groundingMetadata = metadata?.groundingMetadata;
|
|
775
781
|
const urlContextMetadata = metadata?.urlContextMetadata;
|
|
@@ -782,7 +788,7 @@ the model has access to Google Maps data for location-aware responses. This enab
|
|
|
782
788
|
|
|
783
789
|
```ts highlight="7-16"
|
|
784
790
|
import { google, type GoogleLanguageModelOptions } from '@ai-sdk/google';
|
|
785
|
-
import {
|
|
791
|
+
import { GoogleProviderMetadata } from '@ai-sdk/google';
|
|
786
792
|
import { generateText } from 'ai';
|
|
787
793
|
|
|
788
794
|
const { text, sources, providerMetadata } = await generateText({
|
|
@@ -802,7 +808,7 @@ const { text, sources, providerMetadata } = await generateText({
|
|
|
802
808
|
});
|
|
803
809
|
|
|
804
810
|
const metadata = providerMetadata?.google as
|
|
805
|
-
|
|
|
811
|
+
| GoogleProviderMetadata
|
|
806
812
|
| undefined;
|
|
807
813
|
const groundingMetadata = metadata?.groundingMetadata;
|
|
808
814
|
```
|
|
@@ -842,11 +848,11 @@ This enables the model to provide answers based on your specific data sources an
|
|
|
842
848
|
</Note>
|
|
843
849
|
|
|
844
850
|
```ts highlight="8,17-20"
|
|
845
|
-
import {
|
|
846
|
-
import {
|
|
851
|
+
import { createGoogleVertex } from '@ai-sdk/google-vertex';
|
|
852
|
+
import { GoogleProviderMetadata } from '@ai-sdk/google';
|
|
847
853
|
import { generateText } from 'ai';
|
|
848
854
|
|
|
849
|
-
const vertex =
|
|
855
|
+
const vertex = createGoogleVertex({
|
|
850
856
|
project: 'my-project',
|
|
851
857
|
location: 'us-central1',
|
|
852
858
|
});
|
|
@@ -867,7 +873,7 @@ const { text, sources, providerMetadata } = await generateText({
|
|
|
867
873
|
// access the grounding metadata. Casting to the provider metadata type
|
|
868
874
|
// is optional but provides autocomplete and type safety.
|
|
869
875
|
const metadata = providerMetadata?.google as
|
|
870
|
-
|
|
|
876
|
+
| GoogleProviderMetadata
|
|
871
877
|
| undefined;
|
|
872
878
|
const groundingMetadata = metadata?.groundingMetadata;
|
|
873
879
|
const safetyRatings = metadata?.safetyRatings;
|
|
@@ -1051,7 +1057,7 @@ const { output } = await generateText({
|
|
|
1051
1057
|
});
|
|
1052
1058
|
```
|
|
1053
1059
|
|
|
1054
|
-
The following Zod features are known to not work with Google
|
|
1060
|
+
The following Zod features are known to not work with Google:
|
|
1055
1061
|
|
|
1056
1062
|
- `z.union`
|
|
1057
1063
|
- `z.record`
|
|
@@ -1111,12 +1117,12 @@ using the `.embedding()` factory method.
|
|
|
1111
1117
|
const model = google.embedding('gemini-embedding-001');
|
|
1112
1118
|
```
|
|
1113
1119
|
|
|
1114
|
-
The Google
|
|
1120
|
+
The Google provider sends API calls to the right endpoint based on the type of embedding:
|
|
1115
1121
|
|
|
1116
1122
|
- **Single embeddings**: When embedding a single value with `embed()`, the provider uses the single `:embedContent` endpoint, which typically has higher rate limits compared to the batch endpoint.
|
|
1117
1123
|
- **Batch embeddings**: When embedding multiple values with `embedMany()` or multiple values in `embed()`, the provider uses the `:batchEmbedContents` endpoint.
|
|
1118
1124
|
|
|
1119
|
-
Google
|
|
1125
|
+
Google embedding models support additional settings. You can pass them as an options argument:
|
|
1120
1126
|
|
|
1121
1127
|
```ts
|
|
1122
1128
|
import { google, type GoogleEmbeddingModelOptions } from '@ai-sdk/google';
|
|
@@ -1158,7 +1164,7 @@ const { embeddings } = await embedMany({
|
|
|
1158
1164
|
});
|
|
1159
1165
|
```
|
|
1160
1166
|
|
|
1161
|
-
The following optional provider options are available for Google
|
|
1167
|
+
The following optional provider options are available for Google embedding models:
|
|
1162
1168
|
|
|
1163
1169
|
- **outputDimensionality**: _number_
|
|
1164
1170
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/google",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-canary.51",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"license": "Apache-2.0",
|
|
5
6
|
"sideEffects": false,
|
|
6
7
|
"main": "./dist/index.js",
|
|
7
|
-
"module": "./dist/index.mjs",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"files": [
|
|
10
10
|
"dist/**/*",
|
|
@@ -25,26 +25,25 @@
|
|
|
25
25
|
"./package.json": "./package.json",
|
|
26
26
|
".": {
|
|
27
27
|
"types": "./dist/index.d.ts",
|
|
28
|
-
"import": "./dist/index.
|
|
29
|
-
"
|
|
28
|
+
"import": "./dist/index.js",
|
|
29
|
+
"default": "./dist/index.js"
|
|
30
30
|
},
|
|
31
31
|
"./internal": {
|
|
32
32
|
"types": "./dist/internal/index.d.ts",
|
|
33
|
-
"import": "./dist/internal/index.
|
|
34
|
-
"
|
|
35
|
-
"require": "./dist/internal/index.js"
|
|
33
|
+
"import": "./dist/internal/index.js",
|
|
34
|
+
"default": "./dist/internal/index.js"
|
|
36
35
|
}
|
|
37
36
|
},
|
|
38
37
|
"dependencies": {
|
|
39
|
-
"@ai-sdk/provider": "4.0.0-
|
|
40
|
-
"@ai-sdk/provider-utils": "5.0.0-
|
|
38
|
+
"@ai-sdk/provider": "4.0.0-canary.16",
|
|
39
|
+
"@ai-sdk/provider-utils": "5.0.0-canary.32"
|
|
41
40
|
},
|
|
42
41
|
"devDependencies": {
|
|
43
42
|
"@types/node": "20.17.24",
|
|
44
43
|
"tsup": "^8",
|
|
45
44
|
"typescript": "5.8.3",
|
|
46
45
|
"zod": "3.25.76",
|
|
47
|
-
"@ai-sdk/test-server": "2.0.0-
|
|
46
|
+
"@ai-sdk/test-server": "2.0.0-canary.4",
|
|
48
47
|
"@vercel/ai-tsconfig": "0.0.0"
|
|
49
48
|
},
|
|
50
49
|
"peerDependencies": {
|
|
@@ -54,12 +53,14 @@
|
|
|
54
53
|
"node": ">=18"
|
|
55
54
|
},
|
|
56
55
|
"publishConfig": {
|
|
57
|
-
"access": "public"
|
|
56
|
+
"access": "public",
|
|
57
|
+
"provenance": true
|
|
58
58
|
},
|
|
59
59
|
"homepage": "https://ai-sdk.dev/docs",
|
|
60
60
|
"repository": {
|
|
61
61
|
"type": "git",
|
|
62
|
-
"url": "
|
|
62
|
+
"url": "https://github.com/vercel/ai",
|
|
63
|
+
"directory": "packages/google"
|
|
63
64
|
},
|
|
64
65
|
"bugs": {
|
|
65
66
|
"url": "https://github.com/vercel/ai/issues"
|
|
@@ -71,9 +72,7 @@
|
|
|
71
72
|
"build": "pnpm clean && tsup --tsconfig tsconfig.build.json",
|
|
72
73
|
"build:watch": "pnpm clean && tsup --watch",
|
|
73
74
|
"clean": "del-cli dist docs *.tsbuildinfo",
|
|
74
|
-
"lint": "eslint \"./**/*.ts*\"",
|
|
75
75
|
"type-check": "tsc --build",
|
|
76
|
-
"prettier-check": "prettier --check \"./**/*.ts*\"",
|
|
77
76
|
"test": "pnpm test:node && pnpm test:edge",
|
|
78
77
|
"test:update": "pnpm test:node -u",
|
|
79
78
|
"test:watch": "vitest --config vitest.node.config.js",
|
|
@@ -1,16 +1,23 @@
|
|
|
1
|
-
import { LanguageModelV4Usage } from '@ai-sdk/provider';
|
|
1
|
+
import type { LanguageModelV4Usage } from '@ai-sdk/provider';
|
|
2
2
|
|
|
3
|
-
export type
|
|
3
|
+
export type GoogleTokenDetail = {
|
|
4
|
+
modality: string;
|
|
5
|
+
tokenCount: number;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type GoogleUsageMetadata = {
|
|
4
9
|
promptTokenCount?: number | null;
|
|
5
10
|
candidatesTokenCount?: number | null;
|
|
6
11
|
totalTokenCount?: number | null;
|
|
7
12
|
cachedContentTokenCount?: number | null;
|
|
8
13
|
thoughtsTokenCount?: number | null;
|
|
9
14
|
trafficType?: string | null;
|
|
15
|
+
promptTokensDetails?: GoogleTokenDetail[] | null;
|
|
16
|
+
candidatesTokensDetails?: GoogleTokenDetail[] | null;
|
|
10
17
|
};
|
|
11
18
|
|
|
12
|
-
export function
|
|
13
|
-
usage:
|
|
19
|
+
export function convertGoogleUsage(
|
|
20
|
+
usage: GoogleUsageMetadata | undefined | null,
|
|
14
21
|
): LanguageModelV4Usage {
|
|
15
22
|
if (usage == null) {
|
|
16
23
|
return {
|