mirror of
https://github.com/wassname/openrouter-python-sdk-retry-errors.git
synced 2026-07-30 12:20:57 +08:00
184 lines
5.1 KiB
Python
184 lines
5.1 KiB
Python
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
|
|
from __future__ import annotations
|
|
from .apierrortype import APIErrorType
|
|
from .chatstreamchoice import ChatStreamChoice, ChatStreamChoiceTypedDict
|
|
from .chatusage import ChatUsage, ChatUsageTypedDict
|
|
from .openroutermetadata import OpenRouterMetadata, OpenRouterMetadataTypedDict
|
|
from openrouter.types import (
|
|
BaseModel,
|
|
Nullable,
|
|
OptionalNullable,
|
|
UNSET,
|
|
UNSET_SENTINEL,
|
|
)
|
|
from pydantic import model_serializer
|
|
from typing import List, Literal, Optional
|
|
from typing_extensions import NotRequired, TypedDict
|
|
|
|
|
|
class ChatStreamChunkMetadataTypedDict(TypedDict):
|
|
r"""Structured error metadata"""
|
|
|
|
error_type: APIErrorType
|
|
r"""Canonical OpenRouter error type, stable across all API formats"""
|
|
provider_code: NotRequired[str]
|
|
r"""Upstream provider-specific error code, when available"""
|
|
|
|
|
|
class ChatStreamChunkMetadata(BaseModel):
|
|
r"""Structured error metadata"""
|
|
|
|
error_type: APIErrorType
|
|
r"""Canonical OpenRouter error type, stable across all API formats"""
|
|
|
|
provider_code: Optional[str] = None
|
|
r"""Upstream provider-specific error code, when available"""
|
|
|
|
@model_serializer(mode="wrap")
|
|
def serialize_model(self, handler):
|
|
optional_fields = set(["provider_code"])
|
|
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 ChatStreamChunkErrorTypedDict(TypedDict):
|
|
r"""Error information"""
|
|
|
|
code: int
|
|
r"""Error code"""
|
|
message: str
|
|
r"""Error message"""
|
|
metadata: NotRequired[ChatStreamChunkMetadataTypedDict]
|
|
r"""Structured error metadata"""
|
|
|
|
|
|
class ChatStreamChunkError(BaseModel):
|
|
r"""Error information"""
|
|
|
|
code: int
|
|
r"""Error code"""
|
|
|
|
message: str
|
|
r"""Error message"""
|
|
|
|
metadata: Optional[ChatStreamChunkMetadata] = None
|
|
r"""Structured error metadata"""
|
|
|
|
@model_serializer(mode="wrap")
|
|
def serialize_model(self, handler):
|
|
optional_fields = set(["metadata"])
|
|
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
|
|
|
|
|
|
ChatStreamChunkObject = Literal["chat.completion.chunk",]
|
|
|
|
|
|
class ChatStreamChunkTypedDict(TypedDict):
|
|
r"""Streaming chat completion chunk"""
|
|
|
|
choices: List[ChatStreamChoiceTypedDict]
|
|
r"""List of streaming chunk choices"""
|
|
created: int
|
|
r"""Unix timestamp of creation"""
|
|
id: str
|
|
r"""Unique chunk identifier"""
|
|
model: str
|
|
r"""Model used for completion"""
|
|
object: ChatStreamChunkObject
|
|
error: NotRequired[ChatStreamChunkErrorTypedDict]
|
|
r"""Error information"""
|
|
openrouter_metadata: NotRequired[OpenRouterMetadataTypedDict]
|
|
service_tier: NotRequired[Nullable[str]]
|
|
r"""The service tier used by the upstream provider for this request"""
|
|
system_fingerprint: NotRequired[str]
|
|
r"""System fingerprint"""
|
|
usage: NotRequired[ChatUsageTypedDict]
|
|
r"""Token usage statistics"""
|
|
|
|
|
|
class ChatStreamChunk(BaseModel):
|
|
r"""Streaming chat completion chunk"""
|
|
|
|
choices: List[ChatStreamChoice]
|
|
r"""List of streaming chunk choices"""
|
|
|
|
created: int
|
|
r"""Unix timestamp of creation"""
|
|
|
|
id: str
|
|
r"""Unique chunk identifier"""
|
|
|
|
model: str
|
|
r"""Model used for completion"""
|
|
|
|
object: ChatStreamChunkObject
|
|
|
|
error: Optional[ChatStreamChunkError] = None
|
|
r"""Error information"""
|
|
|
|
openrouter_metadata: Optional[OpenRouterMetadata] = None
|
|
|
|
service_tier: OptionalNullable[str] = UNSET
|
|
r"""The service tier used by the upstream provider for this request"""
|
|
|
|
system_fingerprint: Optional[str] = None
|
|
r"""System fingerprint"""
|
|
|
|
usage: Optional[ChatUsage] = None
|
|
r"""Token usage statistics"""
|
|
|
|
@model_serializer(mode="wrap")
|
|
def serialize_model(self, handler):
|
|
optional_fields = set(
|
|
[
|
|
"error",
|
|
"openrouter_metadata",
|
|
"service_tier",
|
|
"system_fingerprint",
|
|
"usage",
|
|
]
|
|
)
|
|
nullable_fields = set(["service_tier"])
|
|
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
|