@ai-sdk/google 4.0.0-canary.71 → 4.0.0-canary.72

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.
@@ -1897,6 +1897,29 @@ const { image } = await generateImage({
1897
1897
  details.
1898
1898
  </Note>
1899
1899
 
1900
+ #### Google Search Grounding
1901
+
1902
+ Gemini image models support [Google Search grounding](#google-search) through `providerOptions.google.googleSearch`. The value matches the args of `google.tools.googleSearch(...)`; pass `{}` to enable with defaults, or `{ searchTypes: { imageSearch: {} } }` to ground on reference photos.
1903
+
1904
+ ```ts
1905
+ import { google } from '@ai-sdk/google';
1906
+ import { generateImage } from 'ai';
1907
+
1908
+ const result = await generateImage({
1909
+ model: google.image('gemini-3.1-flash-image-preview'),
1910
+ prompt:
1911
+ 'Search for live footage of the 2026 Super Bowl halftime show artist, then generate a close-up in space.',
1912
+ providerOptions: {
1913
+ google: {
1914
+ googleSearch: { searchTypes: { imageSearch: {} } },
1915
+ },
1916
+ },
1917
+ });
1918
+
1919
+ // Grounding metadata is forwarded onto the image result:
1920
+ console.log(result.providerMetadata?.google?.groundingMetadata);
1921
+ ```
1922
+
1900
1923
  #### Gemini Image Model Capabilities
1901
1924
 
1902
1925
  | Model | Image Generation | Image Editing | Aspect Ratios |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/google",
3
- "version": "4.0.0-canary.71",
3
+ "version": "4.0.0-canary.72",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -4,6 +4,7 @@ import {
4
4
  type InferSchema,
5
5
  } from '@ai-sdk/provider-utils';
6
6
  import { z } from 'zod/v4';
7
+ import { googleSearchToolArgsBaseSchema } from './tool/google-search';
7
8
 
8
9
  // Note: For the initial GA launch of Imagen 3, safety filters are not configurable.
9
10
  // https://ai.google.dev/gemini-api/docs/imagen#imagen-model
@@ -14,6 +15,17 @@ export const googleImageModelOptionsSchema = lazySchema(() =>
14
15
  .enum(['dont_allow', 'allow_adult', 'allow_all'])
15
16
  .nullish(),
16
17
  aspectRatio: z.enum(['1:1', '3:4', '4:3', '9:16', '16:9']).nullish(),
18
+
19
+ /**
20
+ * Enable Google Search grounding for Gemini image models. The value is
21
+ * forwarded as the args of the `google.tools.googleSearch` provider
22
+ * tool on the underlying language-model call. Pass `{}` for defaults.
23
+ *
24
+ * `generateImage` does not accept a `tools` parameter, so this is the
25
+ * dedicated escape hatch for grounding image generation the same way
26
+ * `generateText` does.
27
+ */
28
+ googleSearch: googleSearchToolArgsBaseSchema.optional(),
17
29
  }),
18
30
  ),
19
31
  );
@@ -156,7 +156,17 @@ export class GoogleImageModel implements ImageModelV4 {
156
156
  }
157
157
 
158
158
  if (googleOptions) {
159
- Object.assign(parameters, googleOptions);
159
+ const { googleSearch: imagenGoogleSearch, ...imagenOptions } =
160
+ googleOptions;
161
+ if (imagenGoogleSearch != null) {
162
+ warnings.push({
163
+ type: 'unsupported',
164
+ feature: 'googleSearch',
165
+ details:
166
+ 'Google Search grounding is only supported on Gemini image models.',
167
+ });
168
+ }
169
+ Object.assign(parameters, imagenOptions);
160
170
  }
161
171
 
162
172
  const body = {
@@ -283,6 +293,18 @@ export class GoogleImageModel implements ImageModelV4 {
283
293
  { role: 'user', content: userContent },
284
294
  ];
285
295
 
296
+ // Parse image-model-specific provider options so we can map them onto
297
+ // the underlying language-model call. `googleSearch` is the dedicated
298
+ // escape hatch for grounding (generateImage has no `tools` parameter).
299
+ const googleImageOptions = await parseProviderOptions({
300
+ provider: 'google',
301
+ providerOptions,
302
+ schema: googleImageModelOptionsSchema,
303
+ });
304
+
305
+ const { googleSearch: _strippedGoogleSearch, ...passthroughGoogleOptions } =
306
+ providerOptions?.google ?? {};
307
+
286
308
  // Instantiate language model
287
309
  const languageModel = new GoogleLanguageModel(this.modelId, {
288
310
  provider: this.config.provider,
@@ -306,12 +328,23 @@ export class GoogleImageModel implements ImageModelV4 {
306
328
  >['aspectRatio'],
307
329
  }
308
330
  : undefined,
309
- ...((providerOptions?.google as Omit<
331
+ ...(passthroughGoogleOptions as Omit<
310
332
  GoogleLanguageModelOptions,
311
333
  'responseModalities' | 'imageConfig'
312
- >) ?? {}),
334
+ >),
313
335
  } satisfies GoogleLanguageModelOptions,
314
336
  },
337
+ tools:
338
+ googleImageOptions?.googleSearch != null
339
+ ? [
340
+ {
341
+ type: 'provider',
342
+ id: 'google.google_search',
343
+ name: 'google_search',
344
+ args: googleImageOptions.googleSearch,
345
+ },
346
+ ]
347
+ : undefined,
315
348
  headers,
316
349
  abortSignal,
317
350
  });
@@ -329,11 +362,17 @@ export class GoogleImageModel implements ImageModelV4 {
329
362
  }
330
363
  }
331
364
 
365
+ const languageModelGoogleMetadata =
366
+ (result.providerMetadata?.google as
367
+ | Record<string, unknown>
368
+ | undefined) ?? {};
369
+
332
370
  return {
333
371
  images,
334
372
  warnings,
335
373
  providerMetadata: {
336
374
  google: {
375
+ ...languageModelGoogleMetadata,
337
376
  images: images.map(() => ({})),
338
377
  },
339
378
  },
@@ -9,7 +9,7 @@ import { z } from 'zod/v4';
9
9
  // https://ai.google.dev/api/generate-content#GroundingSupport
10
10
  // https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/grounding-with-google-search
11
11
 
12
- const googleSearchToolArgsBaseSchema = z
12
+ export const googleSearchToolArgsBaseSchema = z
13
13
  .object({
14
14
  searchTypes: z
15
15
  .object({