From 8c14c71f6bfdd60f183a2b88bcb08638bba74008 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 2 Oct 2025 13:23:07 +0000 Subject: [PATCH 1/3] feat(ai): Add imageconfig and new finishreasons for image generation Adds new `FinishReason` enum values for various image generation scenarios to provide more granular information when a generation request finishes. Also introduces a new `ImageConfig` interface and a corresponding `AspectRatio` enum. This allows specifying image-related configurations, like aspect ratio, within the main `GenerationConfig`. --- packages/ai/src/types/enums.ts | 76 ++++++++++++++++++++++++++++++- packages/ai/src/types/requests.ts | 18 ++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) diff --git a/packages/ai/src/types/enums.ts b/packages/ai/src/types/enums.ts index cd7029df3b..32cd3027fe 100644 --- a/packages/ai/src/types/enums.ts +++ b/packages/ai/src/types/enums.ts @@ -238,7 +238,28 @@ export const FinishReason = { /** * The function call generated by the model was invalid. */ - MALFORMED_FUNCTION_CALL: 'MALFORMED_FUNCTION_CALL' + MALFORMED_FUNCTION_CALL: 'MALFORMED_FUNCTION_CALL', + /** + * Image generation stopped due to safety settings. + */ + IMAGE_SAFETY: 'IMAGE_SAFETY', + /** + * Image generation stopped because generated images has other prohibited + * content. + */ + IMAGE_PROHIBITED_CONTENT: 'IMAGE_PROHIBITED_CONTENT', + /** + * Image generation stopped due to recitation. + */ + IMAGE_RECITATION: 'IMAGE_RECITATION', + /** + * Image generation stopped because of other miscellaneous issue. + */ + IMAGE_OTHER: 'IMAGE_OTHER', + /** + * The model was expected to generate an image, but none was generated. + */ + NO_IMAGE: 'NO_IMAGE' } as const; /** @@ -414,3 +435,56 @@ export const Language = { * @beta */ export type Language = (typeof Language)[keyof typeof Language]; + +/** + * Aspect ratios for generated images. + * @public + */ +export const AspectRatio = { + /** + * Square (1:1) aspect ratio. + */ + SQUARE_1x1: '1:1', + /** + * Portrait (2:3) aspect ratio. + */ + PORTRAIT_2x3: '2:3', + /** + * Landscape (3:2) aspect ratio. + */ + LANDSCAPE_3x2: '3:2', + /** + * Portrait (3:4) aspect ratio. + */ + PORTRAIT_3x4: '3:4', + /** + * Landscape (4:3) aspect ratio. + */ + LANDSCAPE_4x3: '4:3', + /** + * Portrait (4:5) aspect ratio. + */ + PORTRAIT_4x5: '4:5', + /** + * Landscape (5:4) aspect ratio. + */ + LANDSCAPE_5x4: '5:4', + /** + * Portrait (9:16) aspect ratio. + */ + PORTRAIT_9x16: '9:16', + /** + * Landscape (16:9) aspect ratio. + */ + LANDSCAPE_16x9: '16:9', + /** + * Landscape (21:9) aspect ratio. + */ + LANDSCAPE_21x9: '21:9' +} as const; + +/** + * Aspect ratios for generated images. + * @public + */ +export type AspectRatio = (typeof AspectRatio)[keyof typeof AspectRatio]; diff --git a/packages/ai/src/types/requests.ts b/packages/ai/src/types/requests.ts index 1e5fa36742..277ccc848b 100644 --- a/packages/ai/src/types/requests.ts +++ b/packages/ai/src/types/requests.ts @@ -22,6 +22,7 @@ import { LanguageModelPromptOptions } from './language-model'; import { + AspectRatio, FunctionCallingMode, HarmBlockMethod, HarmBlockThreshold, @@ -133,6 +134,12 @@ export interface GenerationConfig { * Configuration for "thinking" behavior of compatible Gemini models. */ thinkingConfig?: ThinkingConfig; + /** + * Configuration for image generation. + * + * @beta + */ + imageConfig?: ImageConfig; } /** @@ -441,6 +448,17 @@ export interface ThinkingConfig { includeThoughts?: boolean; } +/** + * Configuration for image generation. + * @public + */ +export interface ImageConfig { + /** + * The aspect ratio of the generated images. + */ + aspectRatio?: AspectRatio; +} + /** * Configuration for a pre-built voice. * From 9c4c2d6db379f9e3fcaa7acc5bc88ae349be39d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ros=C3=A1rio=20P=2E=20Fernandes?= Date: Tue, 16 Dec 2025 18:41:24 +0000 Subject: [PATCH 2/3] fix camelCase warnings --- packages/ai/src/types/enums.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/ai/src/types/enums.ts b/packages/ai/src/types/enums.ts index 32cd3027fe..5dcdb657f7 100644 --- a/packages/ai/src/types/enums.ts +++ b/packages/ai/src/types/enums.ts @@ -444,43 +444,43 @@ export const AspectRatio = { /** * Square (1:1) aspect ratio. */ - SQUARE_1x1: '1:1', + 'SQUARE_1x1': '1:1', /** * Portrait (2:3) aspect ratio. */ - PORTRAIT_2x3: '2:3', + 'PORTRAIT_2x3': '2:3', /** * Landscape (3:2) aspect ratio. */ - LANDSCAPE_3x2: '3:2', + 'LANDSCAPE_3x2': '3:2', /** * Portrait (3:4) aspect ratio. */ - PORTRAIT_3x4: '3:4', + 'PORTRAIT_3x4': '3:4', /** * Landscape (4:3) aspect ratio. */ - LANDSCAPE_4x3: '4:3', + 'LANDSCAPE_4x3': '4:3', /** * Portrait (4:5) aspect ratio. */ - PORTRAIT_4x5: '4:5', + 'PORTRAIT_4x5': '4:5', /** * Landscape (5:4) aspect ratio. */ - LANDSCAPE_5x4: '5:4', + 'LANDSCAPE_5x4': '5:4', /** * Portrait (9:16) aspect ratio. */ - PORTRAIT_9x16: '9:16', + 'PORTRAIT_9x16': '9:16', /** * Landscape (16:9) aspect ratio. */ - LANDSCAPE_16x9: '16:9', + 'LANDSCAPE_16x9': '16:9', /** * Landscape (21:9) aspect ratio. */ - LANDSCAPE_21x9: '21:9' + 'LANDSCAPE_21x9': '21:9' } as const; /** From 47ff3ae2da7602442c84cb6800ff8d7ea4f77bfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ros=C3=A1rio=20P=2E=20Fernandes?= Date: Tue, 16 Dec 2025 18:45:31 +0000 Subject: [PATCH 3/3] add imagesize support --- packages/ai/src/types/enums.ts | 16 ++++++++++++++++ packages/ai/src/types/requests.ts | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/packages/ai/src/types/enums.ts b/packages/ai/src/types/enums.ts index 5dcdb657f7..3cc6b04955 100644 --- a/packages/ai/src/types/enums.ts +++ b/packages/ai/src/types/enums.ts @@ -488,3 +488,19 @@ export const AspectRatio = { * @public */ export type AspectRatio = (typeof AspectRatio)[keyof typeof AspectRatio]; + +/** + * Specifies the size of generated images. + * @public + */ +export const ImageSize = { + 'SIZE_1K': '1K', + 'SIZE_2K': '2K', + 'SIZE_4K': '4K', +} as const; + +/** + * Specifies the size of generated images. + * @public + */ +export type ImageSize = (typeof ImageSize)[keyof typeof ImageSize]; diff --git a/packages/ai/src/types/requests.ts b/packages/ai/src/types/requests.ts index 277ccc848b..a7bfa2ed81 100644 --- a/packages/ai/src/types/requests.ts +++ b/packages/ai/src/types/requests.ts @@ -27,6 +27,7 @@ import { HarmBlockMethod, HarmBlockThreshold, HarmCategory, + ImageSize, InferenceMode, ResponseModality } from './enums'; @@ -457,6 +458,11 @@ export interface ImageConfig { * The aspect ratio of the generated images. */ aspectRatio?: AspectRatio; + + /** + * The size of generated images.. + */ + imageSize?: ImageSize; } /**