Files
openrouter-python-sdk-retry…/src/openrouter/operations/getmodels.py
T
github-actions[bot]GitHubspeakeasybotspeakeasy-github[bot] <128539517+speakeasy-github[bot]@users.noreply.github.com>
738aed60ad chore: 🐝 Update SDK - Generate (spec change merged) 0.11.5 (#398)
Co-authored-by: speakeasybot <bot@speakeasyapi.dev>
Co-authored-by: speakeasy-github[bot] <128539517+speakeasy-github[bot]@users.noreply.github.com>
2026-07-07 17:29:09 +00:00

476 lines
19 KiB
Python

"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from openrouter.types import (
BaseModel,
Nullable,
OptionalNullable,
UNSET,
UNSET_SENTINEL,
UnrecognizedStr,
)
from openrouter.utils import FieldMetadata, HeaderMetadata, QueryParamMetadata
import pydantic
from pydantic import model_serializer
from typing import Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypedDict
class GetModelsGlobalsTypedDict(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 GetModelsGlobals(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
GetModelsCategory = Union[
Literal[
"programming",
"roleplay",
"marketing",
"marketing/seo",
"technology",
"science",
"translation",
"legal",
"finance",
"health",
"trivia",
"academia",
],
UnrecognizedStr,
]
r"""Filter models by use case category"""
GetModelsSort = Union[
Literal[
"most-popular",
"newest",
"top-weekly",
"pricing-low-to-high",
"pricing-high-to-low",
"context-high-to-low",
"throughput-high-to-low",
"latency-low-to-high",
"intelligence-high-to-low",
"coding-high-to-low",
"agentic-high-to-low",
"design-arena-elo-high-to-low",
],
UnrecognizedStr,
]
r"""Sort the returned models server-side. Prefer this over fetching the full list and sorting client-side. Options: pricing-low-to-high, pricing-high-to-low (average prompt/completion price), context-high-to-low (context length), throughput-high-to-low, latency-low-to-high (recent median performance), most-popular, top-weekly (tokens processed in the last week), newest (creation date), intelligence-high-to-low, coding-high-to-low, agentic-high-to-low (Artificial Analysis indices), design-arena-elo-high-to-low (best Design Arena ELO across arenas). Models without a score for the chosen benchmark are placed last. When omitted, the existing default ordering is preserved."""
Distillable = Union[
Literal[
"true",
"false",
],
UnrecognizedStr,
]
r"""Filter by distillation capability. \"true\" returns only distillable models, \"false\" excludes them."""
Zdr = Literal["true",]
r"""When set to \"true\", return only models with zero data retention endpoints."""
Region = Literal["eu",]
r"""Filter to models with endpoints in the given data region. Currently only \"eu\" is supported."""
class GetModelsRequestTypedDict(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.
"""
category: NotRequired[GetModelsCategory]
r"""Filter models by use case category"""
supported_parameters: NotRequired[str]
r"""Filter models by supported parameter (comma-separated)"""
output_modalities: NotRequired[str]
r"""Filter models by output modality. Accepts a comma-separated list of modalities (text, image, audio, embeddings) or \"all\" to include all models. Defaults to \"text\"."""
sort: NotRequired[GetModelsSort]
r"""Sort the returned models server-side. Prefer this over fetching the full list and sorting client-side. Options: pricing-low-to-high, pricing-high-to-low (average prompt/completion price), context-high-to-low (context length), throughput-high-to-low, latency-low-to-high (recent median performance), most-popular, top-weekly (tokens processed in the last week), newest (creation date), intelligence-high-to-low, coding-high-to-low, agentic-high-to-low (Artificial Analysis indices), design-arena-elo-high-to-low (best Design Arena ELO across arenas). Models without a score for the chosen benchmark are placed last. When omitted, the existing default ordering is preserved."""
q: NotRequired[str]
r"""Free-text search by model name or slug."""
input_modalities: NotRequired[str]
r"""Filter models by input modality. Comma-separated list of: text, image, audio, file."""
context: NotRequired[int]
r"""Minimum context length (tokens). Models with smaller context are excluded."""
min_price: NotRequired[Nullable[float]]
r"""Minimum prompt price in $/M tokens."""
max_price: NotRequired[Nullable[float]]
r"""Maximum prompt price in $/M tokens."""
arch: NotRequired[str]
r"""Filter models by architecture/model family (e.g. GPT, Claude, Gemini, Llama)."""
model_authors: NotRequired[str]
r"""Filter models by the organization that created the model. Comma-separated list of author slugs."""
providers: NotRequired[str]
r"""Filter models by hosting provider. Comma-separated list of provider names."""
distillable: NotRequired[Distillable]
r"""Filter by distillation capability. \"true\" returns only distillable models, \"false\" excludes them."""
zdr: NotRequired[Zdr]
r"""When set to \"true\", return only models with zero data retention endpoints."""
region: NotRequired[Region]
r"""Filter to models with endpoints in the given data region. Currently only \"eu\" is supported."""
min_output_price: NotRequired[Nullable[float]]
r"""Minimum completion (output) price in $/M tokens."""
max_output_price: NotRequired[Nullable[float]]
r"""Maximum completion (output) price in $/M tokens."""
min_age_days: NotRequired[Nullable[int]]
r"""Minimum model age in days since its creation date."""
max_age_days: NotRequired[Nullable[int]]
r"""Maximum model age in days since its creation date."""
min_intelligence_index: NotRequired[Nullable[float]]
r"""Minimum Artificial Analysis intelligence index."""
max_intelligence_index: NotRequired[Nullable[float]]
r"""Maximum Artificial Analysis intelligence index."""
min_coding_index: NotRequired[Nullable[float]]
r"""Minimum Artificial Analysis coding index."""
max_coding_index: NotRequired[Nullable[float]]
r"""Maximum Artificial Analysis coding index."""
min_agentic_index: NotRequired[Nullable[float]]
r"""Minimum Artificial Analysis agentic index."""
max_agentic_index: NotRequired[Nullable[float]]
r"""Maximum Artificial Analysis agentic index."""
min_tool_success_rate: NotRequired[Nullable[float]]
r"""Minimum tool-calling success rate, as a fraction in [0, 1] (e.g. 0.9 = 90% of requests finishing with a tool_calls finish reason)."""
max_tool_success_rate: NotRequired[Nullable[float]]
r"""Maximum tool-calling success rate, as a fraction in [0, 1]."""
class GetModelsRequest(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.
"""
category: Annotated[
Optional[GetModelsCategory],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] = None
r"""Filter models by use case category"""
supported_parameters: Annotated[
Optional[str],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] = None
r"""Filter models by supported parameter (comma-separated)"""
output_modalities: Annotated[
Optional[str],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] = None
r"""Filter models by output modality. Accepts a comma-separated list of modalities (text, image, audio, embeddings) or \"all\" to include all models. Defaults to \"text\"."""
sort: Annotated[
Optional[GetModelsSort],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] = None
r"""Sort the returned models server-side. Prefer this over fetching the full list and sorting client-side. Options: pricing-low-to-high, pricing-high-to-low (average prompt/completion price), context-high-to-low (context length), throughput-high-to-low, latency-low-to-high (recent median performance), most-popular, top-weekly (tokens processed in the last week), newest (creation date), intelligence-high-to-low, coding-high-to-low, agentic-high-to-low (Artificial Analysis indices), design-arena-elo-high-to-low (best Design Arena ELO across arenas). Models without a score for the chosen benchmark are placed last. When omitted, the existing default ordering is preserved."""
q: Annotated[
Optional[str],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] = None
r"""Free-text search by model name or slug."""
input_modalities: Annotated[
Optional[str],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] = None
r"""Filter models by input modality. Comma-separated list of: text, image, audio, file."""
context: Annotated[
Optional[int],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] = None
r"""Minimum context length (tokens). Models with smaller context are excluded."""
min_price: Annotated[
OptionalNullable[float],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] = UNSET
r"""Minimum prompt price in $/M tokens."""
max_price: Annotated[
OptionalNullable[float],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] = UNSET
r"""Maximum prompt price in $/M tokens."""
arch: Annotated[
Optional[str],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] = None
r"""Filter models by architecture/model family (e.g. GPT, Claude, Gemini, Llama)."""
model_authors: Annotated[
Optional[str],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] = None
r"""Filter models by the organization that created the model. Comma-separated list of author slugs."""
providers: Annotated[
Optional[str],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] = None
r"""Filter models by hosting provider. Comma-separated list of provider names."""
distillable: Annotated[
Optional[Distillable],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] = None
r"""Filter by distillation capability. \"true\" returns only distillable models, \"false\" excludes them."""
zdr: Annotated[
Optional[Zdr],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] = None
r"""When set to \"true\", return only models with zero data retention endpoints."""
region: Annotated[
Optional[Region],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] = None
r"""Filter to models with endpoints in the given data region. Currently only \"eu\" is supported."""
min_output_price: Annotated[
OptionalNullable[float],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] = UNSET
r"""Minimum completion (output) price in $/M tokens."""
max_output_price: Annotated[
OptionalNullable[float],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] = UNSET
r"""Maximum completion (output) price in $/M tokens."""
min_age_days: Annotated[
OptionalNullable[int],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] = UNSET
r"""Minimum model age in days since its creation date."""
max_age_days: Annotated[
OptionalNullable[int],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] = UNSET
r"""Maximum model age in days since its creation date."""
min_intelligence_index: Annotated[
OptionalNullable[float],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] = UNSET
r"""Minimum Artificial Analysis intelligence index."""
max_intelligence_index: Annotated[
OptionalNullable[float],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] = UNSET
r"""Maximum Artificial Analysis intelligence index."""
min_coding_index: Annotated[
OptionalNullable[float],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] = UNSET
r"""Minimum Artificial Analysis coding index."""
max_coding_index: Annotated[
OptionalNullable[float],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] = UNSET
r"""Maximum Artificial Analysis coding index."""
min_agentic_index: Annotated[
OptionalNullable[float],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] = UNSET
r"""Minimum Artificial Analysis agentic index."""
max_agentic_index: Annotated[
OptionalNullable[float],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] = UNSET
r"""Maximum Artificial Analysis agentic index."""
min_tool_success_rate: Annotated[
OptionalNullable[float],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] = UNSET
r"""Minimum tool-calling success rate, as a fraction in [0, 1] (e.g. 0.9 = 90% of requests finishing with a tool_calls finish reason)."""
max_tool_success_rate: Annotated[
OptionalNullable[float],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] = UNSET
r"""Maximum tool-calling success rate, as a fraction in [0, 1]."""
@model_serializer(mode="wrap")
def serialize_model(self, handler):
optional_fields = set(
[
"HTTP-Referer",
"X-OpenRouter-Title",
"X-OpenRouter-Categories",
"category",
"supported_parameters",
"output_modalities",
"sort",
"q",
"input_modalities",
"context",
"min_price",
"max_price",
"arch",
"model_authors",
"providers",
"distillable",
"zdr",
"region",
"min_output_price",
"max_output_price",
"min_age_days",
"max_age_days",
"min_intelligence_index",
"max_intelligence_index",
"min_coding_index",
"max_coding_index",
"min_agentic_index",
"max_agentic_index",
"min_tool_success_rate",
"max_tool_success_rate",
]
)
nullable_fields = set(
[
"min_price",
"max_price",
"min_output_price",
"max_output_price",
"min_age_days",
"max_age_days",
"min_intelligence_index",
"max_intelligence_index",
"min_coding_index",
"max_coding_index",
"min_agentic_index",
"max_agentic_index",
"min_tool_success_rate",
"max_tool_success_rate",
]
)
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