Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions js/plugins/google-genai/src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,8 @@ export declare interface GenerateContentRequest {
tools?: Tool[];
/** Optional. This config is shared for all tools provided in the request. */
toolConfig?: ToolConfig;
/** Optional. Service tier (e.g. 'standard', 'flex', or 'priority'). */
serviceTier?: string;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions js/plugins/google-genai/src/googleai/gemini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ export const GeminiConfigSchema = GenerationCommonConfigSchema.extend({
GenerationCommonConfigDescriptions.topP + ' The default value is 0.95.'
)
.optional(),
serviceTier: z
.union([z.enum(['standard', 'flex', 'priority']), z.string()])
.describe('Service tier for the Gemini API.')
.optional(),
thinkingConfig: z
.object({
includeThoughts: z
Expand Down Expand Up @@ -722,6 +726,7 @@ export function defineModel(
urlContext,
tools: toolsFromConfig,
retrievalConfig,
serviceTier,
...restOfConfigOptions
} = requestOptions;

Expand Down Expand Up @@ -845,6 +850,7 @@ export function defineModel(
(setting) => setting.category !== 'HARM_CATEGORY_UNSPECIFIED'
) as SafetySetting[],
contents: messages.map((message) => toGeminiMessage(message, ref)),
serviceTier,
};

const generateApiKey = calculateApiKey(
Expand Down
17 changes: 17 additions & 0 deletions js/plugins/google-genai/tests/googleai/gemini_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,23 @@ describe('Google AI Gemini', () => {
});
});

it('passes serviceTier to the API', async () => {
const model = defineModel('gemini-flash-latest', defaultPluginOptions);
mockFetchResponse(defaultApiResponse);
const request: GenerateRequest<typeof GeminiConfigSchema> = {
...minimalRequest,
config: {
serviceTier: 'flex',
},
};
await model.run(request);

const apiRequest: GenerateContentRequest = JSON.parse(
fetchStub.lastCall.args[1].body
);
assert.strictEqual(apiRequest.serviceTier, 'flex');
});

it('passes imageConfig to the API', async () => {
const model = defineModel(
'gemini-2.5-flash-image',
Expand Down
12 changes: 12 additions & 0 deletions js/testapps/basic-gemini/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ ai.defineFlow('basic-hi', async () => {
return text;
});

ai.defineFlow('basic-hi-flex-tier', async () => {
const { text } = await ai.generate({
model: googleAI.model('gemini-flash-lite-latest'),
prompt: 'You are a helpful AI assistant named Walt, say hello',
config: {
serviceTier: 'flex', // or 'standard' or 'priority'
},
});

return text;
});

ai.defineFlow('basic-hi-with-retry', async () => {
const { text } = await ai.generate({
model: googleAI.model('gemini-pro-latest'),
Expand Down
Loading