mirror of
https://github.com/wassname/openrouter-python-sdk-retry-errors.git
synced 2026-07-30 12:20:57 +08:00
610 lines
18 KiB
Python
610 lines
18 KiB
Python
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
|
|
from __future__ import annotations
|
|
from openrouter.components import (
|
|
contentpartinputaudio as components_contentpartinputaudio,
|
|
contentpartinputfile as components_contentpartinputfile,
|
|
contentpartinputvideo as components_contentpartinputvideo,
|
|
providerpreferences as components_providerpreferences,
|
|
)
|
|
from openrouter.types import (
|
|
BaseModel,
|
|
Nullable,
|
|
OptionalNullable,
|
|
UNSET,
|
|
UNSET_SENTINEL,
|
|
UnrecognizedStr,
|
|
)
|
|
from openrouter.utils import (
|
|
FieldMetadata,
|
|
HeaderMetadata,
|
|
RequestMetadata,
|
|
get_discriminator,
|
|
)
|
|
import pydantic
|
|
from pydantic import Discriminator, Tag, model_serializer
|
|
from typing import List, Literal, Optional, Union
|
|
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict
|
|
|
|
|
|
class CreateEmbeddingsGlobalsTypedDict(TypedDict):
|
|
http_referer: NotRequired[str]
|
|
r"""The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
This is used to track API usage per application.
|
|
|
|
"""
|
|
x_open_router_title: NotRequired[str]
|
|
r"""The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
|
|
"""
|
|
x_open_router_categories: NotRequired[str]
|
|
r"""Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings.
|
|
|
|
"""
|
|
|
|
|
|
class CreateEmbeddingsGlobals(BaseModel):
|
|
http_referer: Annotated[
|
|
Optional[str],
|
|
pydantic.Field(alias="HTTP-Referer"),
|
|
FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
|
|
] = None
|
|
r"""The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
This is used to track API usage per application.
|
|
|
|
"""
|
|
|
|
x_open_router_title: Annotated[
|
|
Optional[str],
|
|
pydantic.Field(alias="X-OpenRouter-Title"),
|
|
FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
|
|
] = None
|
|
r"""The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
|
|
"""
|
|
|
|
x_open_router_categories: Annotated[
|
|
Optional[str],
|
|
pydantic.Field(alias="X-OpenRouter-Categories"),
|
|
FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
|
|
] = None
|
|
r"""Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings.
|
|
|
|
"""
|
|
|
|
@model_serializer(mode="wrap")
|
|
def serialize_model(self, handler):
|
|
optional_fields = set(
|
|
["HTTP-Referer", "X-OpenRouter-Title", "X-OpenRouter-Categories"]
|
|
)
|
|
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
|
|
|
|
|
|
EncodingFormat = Union[
|
|
Literal[
|
|
"float",
|
|
"base64",
|
|
],
|
|
UnrecognizedStr,
|
|
]
|
|
r"""The format of the output embeddings"""
|
|
|
|
|
|
class ImageURLTypedDict(TypedDict):
|
|
url: str
|
|
|
|
|
|
class ImageURL(BaseModel):
|
|
url: str
|
|
|
|
|
|
TypeImageURL = Literal["image_url",]
|
|
|
|
|
|
class ContentImageURLTypedDict(TypedDict):
|
|
image_url: ImageURLTypedDict
|
|
type: TypeImageURL
|
|
|
|
|
|
class ContentImageURL(BaseModel):
|
|
image_url: ImageURL
|
|
|
|
type: TypeImageURL
|
|
|
|
|
|
TypeText = Literal["text",]
|
|
|
|
|
|
class ContentTextTypedDict(TypedDict):
|
|
text: str
|
|
type: TypeText
|
|
|
|
|
|
class ContentText(BaseModel):
|
|
text: str
|
|
|
|
type: TypeText
|
|
|
|
|
|
ContentTypedDict = TypeAliasType(
|
|
"ContentTypedDict",
|
|
Union[
|
|
ContentTextTypedDict,
|
|
ContentImageURLTypedDict,
|
|
components_contentpartinputaudio.ContentPartInputAudioTypedDict,
|
|
components_contentpartinputvideo.ContentPartInputVideoTypedDict,
|
|
components_contentpartinputfile.ContentPartInputFileTypedDict,
|
|
],
|
|
)
|
|
|
|
|
|
Content = Annotated[
|
|
Union[
|
|
Annotated[ContentText, Tag("text")],
|
|
Annotated[ContentImageURL, Tag("image_url")],
|
|
Annotated[
|
|
components_contentpartinputaudio.ContentPartInputAudio, Tag("input_audio")
|
|
],
|
|
Annotated[
|
|
components_contentpartinputvideo.ContentPartInputVideo, Tag("input_video")
|
|
],
|
|
Annotated[
|
|
components_contentpartinputfile.ContentPartInputFile, Tag("input_file")
|
|
],
|
|
],
|
|
Discriminator(lambda m: get_discriminator(m, "type", "type")),
|
|
]
|
|
|
|
|
|
class InputTypedDict(TypedDict):
|
|
content: List[ContentTypedDict]
|
|
|
|
|
|
class Input(BaseModel):
|
|
content: List[Content]
|
|
|
|
|
|
InputUnionTypedDict = TypeAliasType(
|
|
"InputUnionTypedDict",
|
|
Union[str, List[str], List[float], List[List[float]], List[InputTypedDict]],
|
|
)
|
|
r"""Text, token, or multimodal input(s) to embed"""
|
|
|
|
|
|
InputUnion = TypeAliasType(
|
|
"InputUnion", Union[str, List[str], List[float], List[List[float]], List[Input]]
|
|
)
|
|
r"""Text, token, or multimodal input(s) to embed"""
|
|
|
|
|
|
class CreateEmbeddingsRequestBodyTypedDict(TypedDict):
|
|
r"""Embeddings request input"""
|
|
|
|
input: InputUnionTypedDict
|
|
r"""Text, token, or multimodal input(s) to embed"""
|
|
model: str
|
|
r"""The model to use for embeddings"""
|
|
dimensions: NotRequired[int]
|
|
r"""The number of dimensions for the output embeddings"""
|
|
encoding_format: NotRequired[EncodingFormat]
|
|
r"""The format of the output embeddings"""
|
|
input_type: NotRequired[str]
|
|
r"""The type of input (e.g. search_query, search_document)"""
|
|
provider: NotRequired[
|
|
Nullable[components_providerpreferences.ProviderPreferencesTypedDict]
|
|
]
|
|
user: NotRequired[str]
|
|
r"""A unique identifier for the end-user"""
|
|
|
|
|
|
class CreateEmbeddingsRequestBody(BaseModel):
|
|
r"""Embeddings request input"""
|
|
|
|
input: InputUnion
|
|
r"""Text, token, or multimodal input(s) to embed"""
|
|
|
|
model: str
|
|
r"""The model to use for embeddings"""
|
|
|
|
dimensions: Optional[int] = None
|
|
r"""The number of dimensions for the output embeddings"""
|
|
|
|
encoding_format: Optional[EncodingFormat] = None
|
|
r"""The format of the output embeddings"""
|
|
|
|
input_type: Optional[str] = None
|
|
r"""The type of input (e.g. search_query, search_document)"""
|
|
|
|
provider: OptionalNullable[components_providerpreferences.ProviderPreferences] = (
|
|
UNSET
|
|
)
|
|
|
|
user: Optional[str] = None
|
|
r"""A unique identifier for the end-user"""
|
|
|
|
@model_serializer(mode="wrap")
|
|
def serialize_model(self, handler):
|
|
optional_fields = set(
|
|
["dimensions", "encoding_format", "input_type", "provider", "user"]
|
|
)
|
|
nullable_fields = set(["provider"])
|
|
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 CreateEmbeddingsRequestTypedDict(TypedDict):
|
|
request_body: CreateEmbeddingsRequestBodyTypedDict
|
|
http_referer: NotRequired[str]
|
|
r"""The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
This is used to track API usage per application.
|
|
|
|
"""
|
|
x_open_router_title: NotRequired[str]
|
|
r"""The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
|
|
"""
|
|
x_open_router_categories: NotRequired[str]
|
|
r"""Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings.
|
|
|
|
"""
|
|
|
|
|
|
class CreateEmbeddingsRequest(BaseModel):
|
|
request_body: Annotated[
|
|
CreateEmbeddingsRequestBody,
|
|
FieldMetadata(request=RequestMetadata(media_type="application/json")),
|
|
]
|
|
|
|
http_referer: Annotated[
|
|
Optional[str],
|
|
pydantic.Field(alias="HTTP-Referer"),
|
|
FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
|
|
] = None
|
|
r"""The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
This is used to track API usage per application.
|
|
|
|
"""
|
|
|
|
x_open_router_title: Annotated[
|
|
Optional[str],
|
|
pydantic.Field(alias="X-OpenRouter-Title"),
|
|
FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
|
|
] = None
|
|
r"""The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
|
|
"""
|
|
|
|
x_open_router_categories: Annotated[
|
|
Optional[str],
|
|
pydantic.Field(alias="X-OpenRouter-Categories"),
|
|
FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
|
|
] = None
|
|
r"""Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings.
|
|
|
|
"""
|
|
|
|
@model_serializer(mode="wrap")
|
|
def serialize_model(self, handler):
|
|
optional_fields = set(
|
|
["HTTP-Referer", "X-OpenRouter-Title", "X-OpenRouter-Categories"]
|
|
)
|
|
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
|
|
|
|
|
|
EmbeddingTypedDict = TypeAliasType("EmbeddingTypedDict", Union[List[float], str])
|
|
r"""Embedding vector as an array of floats or a base64 string"""
|
|
|
|
|
|
Embedding = TypeAliasType("Embedding", Union[List[float], str])
|
|
r"""Embedding vector as an array of floats or a base64 string"""
|
|
|
|
|
|
ObjectEmbedding = Literal["embedding",]
|
|
|
|
|
|
class CreateEmbeddingsDataTypedDict(TypedDict):
|
|
r"""A single embedding object"""
|
|
|
|
embedding: EmbeddingTypedDict
|
|
r"""Embedding vector as an array of floats or a base64 string"""
|
|
object: ObjectEmbedding
|
|
index: NotRequired[int]
|
|
r"""Index of the embedding in the input list"""
|
|
|
|
|
|
class CreateEmbeddingsData(BaseModel):
|
|
r"""A single embedding object"""
|
|
|
|
embedding: Embedding
|
|
r"""Embedding vector as an array of floats or a base64 string"""
|
|
|
|
object: ObjectEmbedding
|
|
|
|
index: Optional[int] = None
|
|
r"""Index of the embedding in the input list"""
|
|
|
|
@model_serializer(mode="wrap")
|
|
def serialize_model(self, handler):
|
|
optional_fields = set(["index"])
|
|
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
|
|
|
|
|
|
Object = Literal["list",]
|
|
|
|
|
|
class CostDetailsTypedDict(TypedDict):
|
|
r"""Breakdown of upstream inference costs"""
|
|
|
|
upstream_inference_completions_cost: float
|
|
upstream_inference_prompt_cost: float
|
|
upstream_inference_cost: NotRequired[Nullable[float]]
|
|
|
|
|
|
class CostDetails(BaseModel):
|
|
r"""Breakdown of upstream inference costs"""
|
|
|
|
upstream_inference_completions_cost: float
|
|
|
|
upstream_inference_prompt_cost: float
|
|
|
|
upstream_inference_cost: OptionalNullable[float] = UNSET
|
|
|
|
@model_serializer(mode="wrap")
|
|
def serialize_model(self, handler):
|
|
optional_fields = set(["upstream_inference_cost"])
|
|
nullable_fields = set(["upstream_inference_cost"])
|
|
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 PromptTokensDetailsTypedDict(TypedDict):
|
|
r"""Per-modality token breakdown. Only present when the input contains 2+ modalities (e.g. text + image) and the upstream provider returns modality-level usage data. Only non-zero modality counts are included."""
|
|
|
|
audio_tokens: NotRequired[int]
|
|
r"""Number of audio tokens in the input"""
|
|
file_tokens: NotRequired[int]
|
|
r"""Number of file/document tokens in the input"""
|
|
image_tokens: NotRequired[int]
|
|
r"""Number of image tokens in the input"""
|
|
text_tokens: NotRequired[int]
|
|
r"""Number of text tokens in the input"""
|
|
video_tokens: NotRequired[int]
|
|
r"""Number of video tokens in the input"""
|
|
|
|
|
|
class PromptTokensDetails(BaseModel):
|
|
r"""Per-modality token breakdown. Only present when the input contains 2+ modalities (e.g. text + image) and the upstream provider returns modality-level usage data. Only non-zero modality counts are included."""
|
|
|
|
audio_tokens: Optional[int] = None
|
|
r"""Number of audio tokens in the input"""
|
|
|
|
file_tokens: Optional[int] = None
|
|
r"""Number of file/document tokens in the input"""
|
|
|
|
image_tokens: Optional[int] = None
|
|
r"""Number of image tokens in the input"""
|
|
|
|
text_tokens: Optional[int] = None
|
|
r"""Number of text tokens in the input"""
|
|
|
|
video_tokens: Optional[int] = None
|
|
r"""Number of video tokens in the input"""
|
|
|
|
@model_serializer(mode="wrap")
|
|
def serialize_model(self, handler):
|
|
optional_fields = set(
|
|
[
|
|
"audio_tokens",
|
|
"file_tokens",
|
|
"image_tokens",
|
|
"text_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 CreateEmbeddingsUsageTypedDict(TypedDict):
|
|
r"""Token usage statistics"""
|
|
|
|
prompt_tokens: int
|
|
r"""Number of tokens in the input"""
|
|
total_tokens: int
|
|
r"""Total number of tokens used"""
|
|
cost: NotRequired[float]
|
|
r"""Cost of the request in credits"""
|
|
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[PromptTokensDetailsTypedDict]
|
|
r"""Per-modality token breakdown. Only present when the input contains 2+ modalities (e.g. text + image) and the upstream provider returns modality-level usage data. Only non-zero modality counts are included."""
|
|
|
|
|
|
class CreateEmbeddingsUsage(BaseModel):
|
|
r"""Token usage statistics"""
|
|
|
|
prompt_tokens: int
|
|
r"""Number of tokens in the input"""
|
|
|
|
total_tokens: int
|
|
r"""Total number of tokens used"""
|
|
|
|
cost: Optional[float] = None
|
|
r"""Cost of the request in credits"""
|
|
|
|
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: Optional[PromptTokensDetails] = None
|
|
r"""Per-modality token breakdown. Only present when the input contains 2+ modalities (e.g. text + image) and the upstream provider returns modality-level usage data. Only non-zero modality counts are included."""
|
|
|
|
@model_serializer(mode="wrap")
|
|
def serialize_model(self, handler):
|
|
optional_fields = set(
|
|
["cost", "cost_details", "is_byok", "prompt_tokens_details"]
|
|
)
|
|
nullable_fields = set(["cost_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
|
|
|
|
|
|
class CreateEmbeddingsResponseBodyTypedDict(TypedDict):
|
|
r"""Embeddings response containing embedding vectors"""
|
|
|
|
data: List[CreateEmbeddingsDataTypedDict]
|
|
r"""List of embedding objects"""
|
|
model: str
|
|
r"""The model used for embeddings"""
|
|
object: Object
|
|
id: NotRequired[str]
|
|
r"""Unique identifier for the embeddings response"""
|
|
usage: NotRequired[CreateEmbeddingsUsageTypedDict]
|
|
r"""Token usage statistics"""
|
|
|
|
|
|
class CreateEmbeddingsResponseBody(BaseModel):
|
|
r"""Embeddings response containing embedding vectors"""
|
|
|
|
data: List[CreateEmbeddingsData]
|
|
r"""List of embedding objects"""
|
|
|
|
model: str
|
|
r"""The model used for embeddings"""
|
|
|
|
object: Object
|
|
|
|
id: Optional[str] = None
|
|
r"""Unique identifier for the embeddings response"""
|
|
|
|
usage: Optional[CreateEmbeddingsUsage] = None
|
|
r"""Token usage statistics"""
|
|
|
|
@model_serializer(mode="wrap")
|
|
def serialize_model(self, handler):
|
|
optional_fields = set(["id", "usage"])
|
|
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
|
|
|
|
|
|
CreateEmbeddingsResponseTypedDict = TypeAliasType(
|
|
"CreateEmbeddingsResponseTypedDict",
|
|
Union[CreateEmbeddingsResponseBodyTypedDict, str],
|
|
)
|
|
|
|
|
|
CreateEmbeddingsResponse = TypeAliasType(
|
|
"CreateEmbeddingsResponse", Union[CreateEmbeddingsResponseBody, str]
|
|
)
|