Skip to content

Commit 6a6501c

Browse files
amirhcopybara-github
authored andcommitted
feat: add billable token counts fields
PiperOrigin-RevId: 997594067
1 parent 8a641d8 commit 6a6501c

4 files changed

Lines changed: 96 additions & 0 deletions

File tree

‎google/genai/_gaos/resources/interactions/usage/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
1919

20+
from ....types.interactions.billableusage import BillableUsage
2021
from ....types.interactions.groundingtoolcount import GroundingToolCount
2122
from ....types.interactions.modalitytokens import (
2223
ModalityTokens as CachedTokensByModality,
@@ -26,6 +27,7 @@
2627
OutputTokensByModality = CachedTokensByModality
2728
ToolUseTokensByModality = CachedTokensByModality
2829
__all__ = [
30+
"BillableUsage",
2931
"CachedTokensByModality",
3032
"GroundingToolCount",
3133
"InputTokensByModality",

‎google/genai/_gaos/types/interactions/__init__.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
AudioResponseFormatMimeType,
4545
AudioResponseFormatParam,
4646
)
47+
from .billableusage import BillableUsage, BillableUsageTypedDict
4748
from .codeexecution import CodeExecution, CodeExecutionParam
4849
from .codeexecutioncallarguments import (
4950
CodeExecutionCallArguments,
@@ -469,6 +470,8 @@
469470
"AudioResponseFormatDelivery",
470471
"AudioResponseFormatMimeType",
471472
"AudioResponseFormatParam",
473+
"BillableUsage",
474+
"BillableUsageTypedDict",
472475
"CodeExecution",
473476
"CodeExecutionCallArguments",
474477
"CodeExecutionCallArgumentsParam",
@@ -879,6 +882,8 @@
879882
"AudioResponseFormatDelivery": ".audioresponseformat",
880883
"AudioResponseFormatMimeType": ".audioresponseformat",
881884
"AudioResponseFormatParam": ".audioresponseformat",
885+
"BillableUsage": ".billableusage",
886+
"BillableUsageTypedDict": ".billableusage",
882887
"CodeExecution": ".codeexecution",
883888
"CodeExecutionParam": ".codeexecution",
884889
"CodeExecutionCallArguments": ".codeexecutioncallarguments",
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# pyformat: disable
16+
# pylint: skip-file
17+
18+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
19+
20+
from __future__ import annotations
21+
from .. import BaseModel, UNSET_SENTINEL
22+
from pydantic import model_serializer
23+
from typing import Optional
24+
from typing_extensions import NotRequired, TypedDict
25+
26+
27+
class BillableUsageTypedDict(TypedDict):
28+
r"""Accumulated billable token usage across all continuation calls."""
29+
30+
total_cached_tokens: NotRequired[int]
31+
r"""Total billable cached tokens across all continuation calls."""
32+
total_input_tokens: NotRequired[int]
33+
r"""Total billable input tokens across all continuation calls."""
34+
total_output_tokens: NotRequired[int]
35+
r"""Total billable output tokens across all continuation calls."""
36+
total_thought_tokens: NotRequired[int]
37+
r"""Total billable thought tokens across all continuation calls."""
38+
total_tokens: NotRequired[int]
39+
r"""Total billable token count across all continuation calls."""
40+
41+
42+
class BillableUsage(BaseModel):
43+
r"""Accumulated billable token usage across all continuation calls."""
44+
45+
total_cached_tokens: Optional[int] = None
46+
r"""Total billable cached tokens across all continuation calls."""
47+
48+
total_input_tokens: Optional[int] = None
49+
r"""Total billable input tokens across all continuation calls."""
50+
51+
total_output_tokens: Optional[int] = None
52+
r"""Total billable output tokens across all continuation calls."""
53+
54+
total_thought_tokens: Optional[int] = None
55+
r"""Total billable thought tokens across all continuation calls."""
56+
57+
total_tokens: Optional[int] = None
58+
r"""Total billable token count across all continuation calls."""
59+
60+
@model_serializer(mode="wrap")
61+
def serialize_model(self, handler):
62+
optional_fields = set(
63+
[
64+
"total_cached_tokens",
65+
"total_input_tokens",
66+
"total_output_tokens",
67+
"total_thought_tokens",
68+
"total_tokens",
69+
]
70+
)
71+
serialized = handler(self)
72+
m = {}
73+
74+
for n, f in type(self).model_fields.items():
75+
k = f.alias or n
76+
val = serialized.get(k, serialized.get(n))
77+
78+
if val != UNSET_SENTINEL:
79+
if val is not None or k not in optional_fields:
80+
m[k] = val
81+
82+
return m

‎google/genai/_gaos/types/interactions/usage.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from __future__ import annotations
2121
from .. import BaseModel, UNSET_SENTINEL
22+
from .billableusage import BillableUsage, BillableUsageTypedDict
2223
from .groundingtoolcount import GroundingToolCount, GroundingToolCountTypedDict
2324
from .modalitytokens import ModalityTokens, ModalityTokensTypedDict
2425
from pydantic import model_serializer
@@ -29,6 +30,8 @@
2930
class UsageTypedDict(TypedDict):
3031
r"""Statistics on the interaction request's token usage."""
3132

33+
billable_usage: NotRequired[BillableUsageTypedDict]
34+
r"""Accumulated billable token usage across all continuation calls."""
3235
cached_tokens_by_modality: NotRequired[List[ModalityTokensTypedDict]]
3336
r"""A breakdown of cached token usage by modality."""
3437
grounding_tool_count: NotRequired[List[GroundingToolCountTypedDict]]
@@ -58,6 +61,9 @@ class UsageTypedDict(TypedDict):
5861
class Usage(BaseModel):
5962
r"""Statistics on the interaction request's token usage."""
6063

64+
billable_usage: Optional[BillableUsage] = None
65+
r"""Accumulated billable token usage across all continuation calls."""
66+
6167
cached_tokens_by_modality: Optional[List[ModalityTokens]] = None
6268
r"""A breakdown of cached token usage by modality."""
6369

@@ -97,6 +103,7 @@ class Usage(BaseModel):
97103
def serialize_model(self, handler):
98104
optional_fields = set(
99105
[
106+
"billable_usage",
100107
"cached_tokens_by_modality",
101108
"grounding_tool_count",
102109
"input_tokens_by_modality",

0 commit comments

Comments
 (0)