diff --git a/google/genai/batches.py b/google/genai/batches.py index 77e2b34bf..0dbd0b8ac 100644 --- a/google/genai/batches.py +++ b/google/genai/batches.py @@ -1052,6 +1052,9 @@ def _GenerateContentConfig_to_mldev( 'model_armor_config parameter is not supported in Gemini API.' ) + if getv(from_object, ['service_tier']) is not None: + setv(parent_object, ['serviceTier'], getv(from_object, ['service_tier'])) + return to_object diff --git a/google/genai/models.py b/google/genai/models.py index 6a5bd8d6f..325a47251 100644 --- a/google/genai/models.py +++ b/google/genai/models.py @@ -1316,6 +1316,9 @@ def _GenerateContentConfig_to_mldev( 'model_armor_config parameter is not supported in Gemini API.' ) + if getv(from_object, ['service_tier']) is not None: + setv(parent_object, ['serviceTier'], getv(from_object, ['service_tier'])) + return to_object @@ -1502,6 +1505,9 @@ def _GenerateContentConfig_to_vertex( getv(from_object, ['model_armor_config']), ) + if getv(from_object, ['service_tier']) is not None: + raise ValueError('service_tier parameter is not supported in Vertex AI.') + return to_object diff --git a/google/genai/tests/models/test_generate_content.py b/google/genai/tests/models/test_generate_content.py index bf5c0ea70..e37b5f54b 100644 --- a/google/genai/tests/models/test_generate_content.py +++ b/google/genai/tests/models/test_generate_content.py @@ -142,9 +142,7 @@ class InstrumentEnum(Enum): model=GEMINI_FLASH_LATEST, contents=t.t_contents('high'), config={ - 'system_instruction': t.t_content( - 'I say high, you say low' - ) + 'system_instruction': t.t_content('I say high, you say low') }, ), ), @@ -237,13 +235,13 @@ class InstrumentEnum(Enum): config=types.GenerateContentConfig( tools=[{'google_maps': {}}], tool_config={ - "retrieval_config": { - "lat_lng": { - "latitude": 37.421993, - "longitude": -122.079725, + 'retrieval_config': { + 'lat_lng': { + 'latitude': 37.421993, + 'longitude': -122.079725, } } - } + }, ), ), ), @@ -357,9 +355,7 @@ class InstrumentEnum(Enum): name='test_speech_with_config', parameters=types._GenerateContentParameters( model='gemini-2.5-flash-preview-tts', - contents=t.t_contents( - 'Produce a speech response saying "Cheese"' - ), + contents=t.t_contents('Produce a speech response saying "Cheese"'), config=types.GenerateContentConfig( response_modalities=['audio'], speech_config=types.SpeechConfig( @@ -536,8 +532,8 @@ class InstrumentEnum(Enum): parameters=types._GenerateContentParameters( model=GEMINI_FLASH_LATEST, contents=t.t_contents( - 'Summarize the evidence that confirms widespread voter fraud was' - ' the reason the last national election results were' + 'Summarize the evidence that confirms widespread voter fraud' + ' was the reason the last national election results were' ' inaccurate.' ), config={ @@ -562,6 +558,17 @@ class InstrumentEnum(Enum): ), exception_if_mldev='not supported', ), + pytest_helper.TestTableItem( + name='test_service_tier', + parameters=types._GenerateContentParameters( + model=GEMINI_FLASH_LATEST, + contents=t.t_contents('What is your name?'), + config={ + 'service_tier': 'flex', + }, + ), + exception_if_vertex='not supported', + ), ] pytestmark = pytest_helper.setup( diff --git a/google/genai/types.py b/google/genai/types.py index 0ef38eb62..d8971d1c9 100644 --- a/google/genai/types.py +++ b/google/genai/types.py @@ -831,6 +831,19 @@ class ResourceScope(_common.CaseInSensitiveEnum): "https://aiplatform.googleapis.com/publishers/google/models/gemini-3-pro-preview""" +class ServiceTier(_common.CaseInSensitiveEnum): + """Pricing and performance service tier.""" + + SERVICE_TIER_UNSPECIFIED = 'SERVICE_TIER_UNSPECIFIED' + """Default service tier, which is standard.""" + SERVICE_TIER_FLEX = 'SERVICE_TIER_FLEX' + """Flex service tier.""" + SERVICE_TIER_STANDARD = 'SERVICE_TIER_STANDARD' + """Standard service tier.""" + SERVICE_TIER_PRIORITY = 'SERVICE_TIER_PRIORITY' + """Priority service tier.""" + + class JSONSchemaType(Enum): """The type of the data supported by JSON Schema. @@ -5937,6 +5950,10 @@ class GenerateContentConfig(_common.BaseModel): service. If supplied, safety_settings must not be supplied. """, ) + service_tier: Optional[ServiceTier] = Field( + default=None, + description="""The service tier to use for the request. For example, FLEX.""", + ) @pydantic.field_validator('response_schema', mode='before') @classmethod @@ -6151,6 +6168,9 @@ class GenerateContentConfigDict(TypedDict, total=False): service. If supplied, safety_settings must not be supplied. """ + service_tier: Optional[ServiceTier] + """The service tier to use for the request. For example, FLEX.""" + GenerateContentConfigOrDict = Union[ GenerateContentConfig, GenerateContentConfigDict