mirror of
https://github.com/wassname/openrouter-python-sdk-retry-errors.git
synced 2026-07-30 12:20:57 +08:00
Co-authored-by: speakeasybot <bot@speakeasyapi.dev> Co-authored-by: speakeasy-github[bot] <128539517+speakeasy-github[bot]@users.noreply.github.com>
231 lines
7.1 KiB
Python
231 lines
7.1 KiB
Python
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
|
|
from __future__ import annotations
|
|
from .costdetails import CostDetails, CostDetailsTypedDict
|
|
from .servertoolusedetails import ServerToolUseDetails, ServerToolUseDetailsTypedDict
|
|
from openrouter.types import (
|
|
BaseModel,
|
|
Nullable,
|
|
OptionalNullable,
|
|
UNSET,
|
|
UNSET_SENTINEL,
|
|
)
|
|
from pydantic import model_serializer
|
|
from typing import Optional
|
|
from typing_extensions import NotRequired, TypedDict
|
|
|
|
|
|
class ChatUsageCompletionTokensDetailsTypedDict(TypedDict):
|
|
r"""Detailed completion token usage"""
|
|
|
|
accepted_prediction_tokens: NotRequired[Nullable[int]]
|
|
r"""Accepted prediction tokens"""
|
|
audio_tokens: NotRequired[Nullable[int]]
|
|
r"""Tokens used for audio output"""
|
|
reasoning_tokens: NotRequired[Nullable[int]]
|
|
r"""Tokens used for reasoning"""
|
|
rejected_prediction_tokens: NotRequired[Nullable[int]]
|
|
r"""Rejected prediction tokens"""
|
|
|
|
|
|
class ChatUsageCompletionTokensDetails(BaseModel):
|
|
r"""Detailed completion token usage"""
|
|
|
|
accepted_prediction_tokens: OptionalNullable[int] = UNSET
|
|
r"""Accepted prediction tokens"""
|
|
|
|
audio_tokens: OptionalNullable[int] = UNSET
|
|
r"""Tokens used for audio output"""
|
|
|
|
reasoning_tokens: OptionalNullable[int] = UNSET
|
|
r"""Tokens used for reasoning"""
|
|
|
|
rejected_prediction_tokens: OptionalNullable[int] = UNSET
|
|
r"""Rejected prediction tokens"""
|
|
|
|
@model_serializer(mode="wrap")
|
|
def serialize_model(self, handler):
|
|
optional_fields = set(
|
|
[
|
|
"accepted_prediction_tokens",
|
|
"audio_tokens",
|
|
"reasoning_tokens",
|
|
"rejected_prediction_tokens",
|
|
]
|
|
)
|
|
nullable_fields = set(
|
|
[
|
|
"accepted_prediction_tokens",
|
|
"audio_tokens",
|
|
"reasoning_tokens",
|
|
"rejected_prediction_tokens",
|
|
]
|
|
)
|
|
serialized = handler(self)
|
|
m = {}
|
|
|
|
for n, f in type(self).model_fields.items():
|
|
k = f.alias or n
|
|
val = serialized.get(k, serialized.get(n))
|
|
is_nullable_and_explicitly_set = (
|
|
k in nullable_fields
|
|
and (self.__pydantic_fields_set__.intersection({n})) # pylint: disable=no-member
|
|
)
|
|
|
|
if val != UNSET_SENTINEL:
|
|
if (
|
|
val is not None
|
|
or k not in optional_fields
|
|
or is_nullable_and_explicitly_set
|
|
):
|
|
m[k] = val
|
|
|
|
return m
|
|
|
|
|
|
class ChatUsagePromptTokensDetailsTypedDict(TypedDict):
|
|
r"""Detailed prompt token usage"""
|
|
|
|
audio_tokens: NotRequired[int]
|
|
r"""Audio input tokens"""
|
|
cache_write_tokens: NotRequired[int]
|
|
r"""Tokens written to cache. Only returned for models with explicit caching and cache write pricing."""
|
|
cached_tokens: NotRequired[int]
|
|
r"""Cached prompt tokens"""
|
|
video_tokens: NotRequired[int]
|
|
r"""Video input tokens"""
|
|
|
|
|
|
class ChatUsagePromptTokensDetails(BaseModel):
|
|
r"""Detailed prompt token usage"""
|
|
|
|
audio_tokens: Optional[int] = None
|
|
r"""Audio input tokens"""
|
|
|
|
cache_write_tokens: Optional[int] = None
|
|
r"""Tokens written to cache. Only returned for models with explicit caching and cache write pricing."""
|
|
|
|
cached_tokens: Optional[int] = None
|
|
r"""Cached prompt tokens"""
|
|
|
|
video_tokens: Optional[int] = None
|
|
r"""Video input tokens"""
|
|
|
|
@model_serializer(mode="wrap")
|
|
def serialize_model(self, handler):
|
|
optional_fields = set(
|
|
["audio_tokens", "cache_write_tokens", "cached_tokens", "video_tokens"]
|
|
)
|
|
serialized = handler(self)
|
|
m = {}
|
|
|
|
for n, f in type(self).model_fields.items():
|
|
k = f.alias or n
|
|
val = serialized.get(k, serialized.get(n))
|
|
|
|
if val != UNSET_SENTINEL:
|
|
if val is not None or k not in optional_fields:
|
|
m[k] = val
|
|
|
|
return m
|
|
|
|
|
|
class ChatUsageTypedDict(TypedDict):
|
|
r"""Token usage statistics"""
|
|
|
|
completion_tokens: int
|
|
r"""Number of tokens in the completion"""
|
|
prompt_tokens: int
|
|
r"""Number of tokens in the prompt"""
|
|
total_tokens: int
|
|
r"""Total number of tokens"""
|
|
completion_tokens_details: NotRequired[
|
|
Nullable[ChatUsageCompletionTokensDetailsTypedDict]
|
|
]
|
|
r"""Detailed completion token usage"""
|
|
cost: NotRequired[Nullable[float]]
|
|
r"""Cost of the completion"""
|
|
cost_details: NotRequired[Nullable[CostDetailsTypedDict]]
|
|
r"""Breakdown of upstream inference costs"""
|
|
is_byok: NotRequired[bool]
|
|
r"""Whether a request was made using a Bring Your Own Key configuration"""
|
|
prompt_tokens_details: NotRequired[Nullable[ChatUsagePromptTokensDetailsTypedDict]]
|
|
r"""Detailed prompt token usage"""
|
|
server_tool_use_details: NotRequired[Nullable[ServerToolUseDetailsTypedDict]]
|
|
r"""Usage for server-side tool execution (e.g., web search)"""
|
|
|
|
|
|
class ChatUsage(BaseModel):
|
|
r"""Token usage statistics"""
|
|
|
|
completion_tokens: int
|
|
r"""Number of tokens in the completion"""
|
|
|
|
prompt_tokens: int
|
|
r"""Number of tokens in the prompt"""
|
|
|
|
total_tokens: int
|
|
r"""Total number of tokens"""
|
|
|
|
completion_tokens_details: OptionalNullable[ChatUsageCompletionTokensDetails] = (
|
|
UNSET
|
|
)
|
|
r"""Detailed completion token usage"""
|
|
|
|
cost: OptionalNullable[float] = UNSET
|
|
r"""Cost of the completion"""
|
|
|
|
cost_details: OptionalNullable[CostDetails] = UNSET
|
|
r"""Breakdown of upstream inference costs"""
|
|
|
|
is_byok: Optional[bool] = None
|
|
r"""Whether a request was made using a Bring Your Own Key configuration"""
|
|
|
|
prompt_tokens_details: OptionalNullable[ChatUsagePromptTokensDetails] = UNSET
|
|
r"""Detailed prompt token usage"""
|
|
|
|
server_tool_use_details: OptionalNullable[ServerToolUseDetails] = UNSET
|
|
r"""Usage for server-side tool execution (e.g., web search)"""
|
|
|
|
@model_serializer(mode="wrap")
|
|
def serialize_model(self, handler):
|
|
optional_fields = set(
|
|
[
|
|
"completion_tokens_details",
|
|
"cost",
|
|
"cost_details",
|
|
"is_byok",
|
|
"prompt_tokens_details",
|
|
"server_tool_use_details",
|
|
]
|
|
)
|
|
nullable_fields = set(
|
|
[
|
|
"completion_tokens_details",
|
|
"cost",
|
|
"cost_details",
|
|
"prompt_tokens_details",
|
|
"server_tool_use_details",
|
|
]
|
|
)
|
|
serialized = handler(self)
|
|
m = {}
|
|
|
|
for n, f in type(self).model_fields.items():
|
|
k = f.alias or n
|
|
val = serialized.get(k, serialized.get(n))
|
|
is_nullable_and_explicitly_set = (
|
|
k in nullable_fields
|
|
and (self.__pydantic_fields_set__.intersection({n})) # pylint: disable=no-member
|
|
)
|
|
|
|
if val != UNSET_SENTINEL:
|
|
if (
|
|
val is not None
|
|
or k not in optional_fields
|
|
or is_nullable_and_explicitly_set
|
|
):
|
|
m[k] = val
|
|
|
|
return m
|