Skip to content

Commit 86846c9

Browse files
committed
fix: parse service tier in usage metadata
1 parent f907d4b commit 86846c9

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

google/genai/tests/common/test_common.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,18 @@ def test_repr_complex_object():
677677
assert repr(obj) == expected
678678

679679

680+
def test_generate_content_usage_metadata_service_tier():
681+
response = types.GenerateContentResponse.model_validate({
682+
'usageMetadata': {
683+
'promptTokenCount': 1,
684+
'totalTokenCount': 1,
685+
'serviceTier': 'priority',
686+
}
687+
})
688+
689+
assert response.usage_metadata.service_tier == types.ServiceTier.PRIORITY
690+
691+
680692
def test_move_value_by_path():
681693
"""Test move_value_by_path function with array wildcard notation."""
682694
data = {

google/genai/types.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7809,6 +7809,10 @@ class GenerateContentResponseUsageMetadata(_common.BaseModel):
78097809
default=None,
78107810
description="""Output only. A detailed breakdown of the token count for each modality in the prompt.""",
78117811
)
7812+
service_tier: Optional[ServiceTier] = Field(
7813+
default=None,
7814+
description="""Output only. The service tier used for this request.""",
7815+
)
78127816
thoughts_token_count: Optional[int] = Field(
78137817
default=None,
78147818
description="""Output only. The number of tokens that were part of the model's generated "thoughts" output, if applicable.""",
@@ -7856,6 +7860,9 @@ class GenerateContentResponseUsageMetadataDict(TypedDict, total=False):
78567860
prompt_tokens_details: Optional[list[ModalityTokenCountDict]]
78577861
"""Output only. A detailed breakdown of the token count for each modality in the prompt."""
78587862

7863+
service_tier: Optional[ServiceTier]
7864+
"""Output only. The service tier used for this request."""
7865+
78597866
thoughts_token_count: Optional[int]
78607867
"""Output only. The number of tokens that were part of the model's generated "thoughts" output, if applicable."""
78617868

0 commit comments

Comments
 (0)