diff --git a/js/plugins/google-genai/src/common/converters.ts b/js/plugins/google-genai/src/common/converters.ts index fee41107f5..1536d839ee 100644 --- a/js/plugins/google-genai/src/common/converters.ts +++ b/js/plugins/google-genai/src/common/converters.ts @@ -134,6 +134,11 @@ function toGeminiMedia(part: Part): GeminiPart { media.videoMetadata = { ...videoMetadata }; } + // Media resolution + if (part.metadata?.mediaResolution) { + media.mediaResolution = { ...part.metadata.mediaResolution }; + } + return maybeAddGeminiThoughtSignature(part, media); } diff --git a/js/plugins/google-genai/src/common/types.ts b/js/plugins/google-genai/src/common/types.ts index 9f72ccf5fd..33f185e99e 100644 --- a/js/plugins/google-genai/src/common/types.ts +++ b/js/plugins/google-genai/src/common/types.ts @@ -717,6 +717,16 @@ export declare interface VideoMetadata { fps?: number; } +export enum MediaResolutionLevel { + MEDIA_RESOUTION_LOW = 'MEDIA_RESOUTION_LOW', + MEDIA_RESOLUTION_MEDIUM = 'MEDIA_RESOLUTION_MEDIUM', + MEDIA_RESOLUTION_HIGH = 'MEDIA_RESOLUTION_HIGH', +} + +export declare interface MediaResolution { + level?: MediaResolutionLevel; +} + /** * This is a Gemini Part. (Users never see this * structure, it is just built by the converters.) @@ -732,6 +742,7 @@ export declare interface Part { executableCode?: ExecutableCode; codeExecutionResult?: CodeExecutionResult; videoMetadata?: VideoMetadata; + mediaResolution?: MediaResolution; } /** diff --git a/js/plugins/google-genai/tests/common/converters_test.ts b/js/plugins/google-genai/tests/common/converters_test.ts index ddd228cb11..5dd45c87c0 100644 --- a/js/plugins/google-genai/tests/common/converters_test.ts +++ b/js/plugins/google-genai/tests/common/converters_test.ts @@ -125,6 +125,11 @@ describe('toGeminiMessage', () => { contentType: 'image/jpeg', url: 'data:image/jpeg;base64,SHORTENED_BASE64_DATA', }, + metadata: { + mediaResolution: { + level: 'MEDIA_RESOLUTION_HIGH', + }, + }, }, ], }, @@ -137,6 +142,9 @@ describe('toGeminiMessage', () => { mimeType: 'image/jpeg', data: 'SHORTENED_BASE64_DATA', }, + mediaResolution: { + level: 'MEDIA_RESOLUTION_HIGH', + }, }, ], }, diff --git a/js/testapps/basic-gemini/src/index-vertexai.ts b/js/testapps/basic-gemini/src/index-vertexai.ts index a3be81297f..85e6c7b57a 100644 --- a/js/testapps/basic-gemini/src/index-vertexai.ts +++ b/js/testapps/basic-gemini/src/index-vertexai.ts @@ -378,6 +378,28 @@ ai.defineFlow('reasoning', async (_, { sendChunk }) => { return message; }); +// Media resolution +ai.defineFlow('gemini-media-resolution', async (_) => { + const plant = fs.readFileSync('palm_tree.png', { encoding: 'base64' }); + const { text } = await ai.generate({ + model: vertexAI.model('gemini-3-pro-preview'), + prompt: [ + { text: 'What is in this picture?' }, + { + media: { url: `data:image/png;base64,${plant}` }, + metadata: { + mediaResolution: { + // Or MEDIA_RESOLUTION_LOW Or MEDIA_RESOLUTION_MEDIUM + level: 'MEDIA_RESOLUTION_HIGH', + }, + }, + }, + ], + }); + + return text; +}); + // Image editing with Gemini. ai.defineFlow('gemini-image-editing', async (_) => { const plant = fs.readFileSync('palm_tree.png', { encoding: 'base64' }); diff --git a/js/testapps/basic-gemini/src/index.ts b/js/testapps/basic-gemini/src/index.ts index 611f6d8898..b47523cbf9 100644 --- a/js/testapps/basic-gemini/src/index.ts +++ b/js/testapps/basic-gemini/src/index.ts @@ -366,6 +366,31 @@ ai.defineFlow('reasoning', async (_, { sendChunk }) => { return message; }); +// Media resolution +ai.defineFlow('gemini-media-resolution', async (_) => { + const plant = fs.readFileSync('palm_tree.png', { encoding: 'base64' }); + const { text } = await ai.generate({ + model: googleAI.model('gemini-3-pro-preview'), + prompt: [ + { text: 'What is in this picture?' }, + { + media: { url: `data:image/png;base64,${plant}` }, + metadata: { + mediaResolution: { + // Or MEDIA_RESOLUTION_LOW Or MEDIA_RESOLUTION_MEDIUM + level: 'MEDIA_RESOLUTION_HIGH', + }, + }, + }, + ], + config: { + // MediaResolution is currently only supported in v1alpha for googleAI + apiVersion: 'v1alpha', + }, + }); + return text; +}); + // Image editing with Gemini. ai.defineFlow('gemini-image-editing', async (_) => { const plant = fs.readFileSync('palm_tree.png', { encoding: 'base64' });