"""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,
    validate_open_enum,
)
import pydantic
from pydantic import Discriminator, Tag, model_serializer
from pydantic.functional_validators import PlainValidator
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.

    """


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: Annotated[
        Optional[EncodingFormat], PlainValidator(validate_open_enum(False))
    ] = 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 = [
            "dimensions",
            "encoding_format",
            "input_type",
            "provider",
            "user",
        ]
        nullable_fields = ["provider"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_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.

    """


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"""


Object = Literal["list",]


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"""


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"""
    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"""

    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."""


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"""


CreateEmbeddingsResponseTypedDict = TypeAliasType(
    "CreateEmbeddingsResponseTypedDict",
    Union[CreateEmbeddingsResponseBodyTypedDict, str],
)


CreateEmbeddingsResponse = TypeAliasType(
    "CreateEmbeddingsResponse", Union[CreateEmbeddingsResponseBody, str]
)
