|
| 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 |
0 commit comments