"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from openrouter.components import providerpreferences as components_providerpreferences
from openrouter.types import BaseModel, UnrecognizedStr
from openrouter.utils import (
    FieldMetadata,
    HeaderMetadata,
    RequestMetadata,
    get_discriminator,
    validate_open_enum,
)
import pydantic
from pydantic import Discriminator, Tag
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_title: NotRequired[str]
    r"""The app display name allows you to customize how your app appears in OpenRouter's dashboard.

    """


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_title: Annotated[
        Optional[str],
        pydantic.Field(alias="X-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.

    """


TypeImageURL = Literal["image_url",]


class ImageURLTypedDict(TypedDict):
    url: str


class ImageURL(BaseModel):
    url: str


class ContentImageURLTypedDict(TypedDict):
    type: TypeImageURL
    image_url: ImageURLTypedDict


class ContentImageURL(BaseModel):
    type: TypeImageURL

    image_url: ImageURL


TypeText = Literal["text",]


class ContentTextTypedDict(TypedDict):
    type: TypeText
    text: str


class ContentText(BaseModel):
    type: TypeText

    text: str


ContentTypedDict = TypeAliasType(
    "ContentTypedDict", Union[ContentTextTypedDict, ContentImageURLTypedDict]
)


Content = Annotated[
    Union[
        Annotated[ContentText, Tag("text")],
        Annotated[ContentImageURL, Tag("image_url")],
    ],
    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]],
)


InputUnion = TypeAliasType(
    "InputUnion", Union[str, List[str], List[float], List[List[float]], List[Input]]
)


EncodingFormat = Union[
    Literal[
        "float",
        "base64",
    ],
    UnrecognizedStr,
]


class CreateEmbeddingsRequestBodyTypedDict(TypedDict):
    input: InputUnionTypedDict
    model: str
    encoding_format: NotRequired[EncodingFormat]
    dimensions: NotRequired[int]
    user: NotRequired[str]
    provider: NotRequired[components_providerpreferences.ProviderPreferencesTypedDict]
    r"""Provider routing preferences for the request."""
    input_type: NotRequired[str]


class CreateEmbeddingsRequestBody(BaseModel):
    input: InputUnion

    model: str

    encoding_format: Annotated[
        Optional[EncodingFormat], PlainValidator(validate_open_enum(False))
    ] = None

    dimensions: Optional[int] = None

    user: Optional[str] = None

    provider: Optional[components_providerpreferences.ProviderPreferences] = None
    r"""Provider routing preferences for the request."""

    input_type: Optional[str] = None


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_title: NotRequired[str]
    r"""The app display name allows you to customize how your app appears in OpenRouter's dashboard.

    """


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_title: Annotated[
        Optional[str],
        pydantic.Field(alias="X-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.

    """


Object = Literal["list",]


ObjectEmbedding = Literal["embedding",]


EmbeddingTypedDict = TypeAliasType("EmbeddingTypedDict", Union[List[float], str])


Embedding = TypeAliasType("Embedding", Union[List[float], str])


class CreateEmbeddingsDataTypedDict(TypedDict):
    object: ObjectEmbedding
    embedding: EmbeddingTypedDict
    index: NotRequired[float]


class CreateEmbeddingsData(BaseModel):
    object: ObjectEmbedding

    embedding: Embedding

    index: Optional[float] = None


class UsageTypedDict(TypedDict):
    prompt_tokens: float
    total_tokens: float
    cost: NotRequired[float]


class Usage(BaseModel):
    prompt_tokens: float

    total_tokens: float

    cost: Optional[float] = None


class CreateEmbeddingsResponseBodyTypedDict(TypedDict):
    r"""Embedding response"""

    object: Object
    data: List[CreateEmbeddingsDataTypedDict]
    model: str
    id: NotRequired[str]
    usage: NotRequired[UsageTypedDict]


class CreateEmbeddingsResponseBody(BaseModel):
    r"""Embedding response"""

    object: Object

    data: List[CreateEmbeddingsData]

    model: str

    id: Optional[str] = None

    usage: Optional[Usage] = None


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


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