Commits included in this export:

- 56d382078cfce7fa597d1da2bce531af2d060b47
  - 9ef6db7e04c9401536763a321b05d00311cef31a
  - bf855082e30820d466f0f86a6d6e87de2ecfb06f
  - 335b1cbe361214e48b945b987b4e164457aa817b
  - 648485fdc7f9d8ae86fd857eccedcc5e41fb2e69
  - 80c49474a15a2bd549a5f26efad3858aa45b7c7b
  - 70e8ac317f9c4472db3decd024d1819650df4182
  - 9f2a6659ab6dbf111a0c29e4366328c3d2048826
  - a3a28b1fc6ec7d2941232a4ebde8c5f470497876
  - 4b5dc9193480b7c5c9ddb882ccf3ee2128ca0d51
  - bb413e979a46ef67c2f266743f7ebd798af42afb
  - b60e92d5dcec83f31986164f51c010d1728b2b17
  - 45687f423707f5838461585c568a024a19eb2f06
  - 3103d3ca68b6e42ccdb6136588ec2b6edc8dcab0
  - fd9f991606027cd86116317c71f8eb7b4e2aa3eb
  - 0f312019161edd76c1e5923d142c788d22f096d5
  - 5dbab2094bc744db4a90b3097520d897e5d0d634
  - 4c47d1af1735db18a1c1a7f463e801c7f71ad4e5

GitOrigin-RevId: 56d382078cfce7fa597d1da2bce531af2d060b47
This commit is contained in:
OpenRouter Team
2026-02-23 21:34:42 +00:00
parent b2098ff28e
commit c734c52d9c
289 changed files with 7971 additions and 5521 deletions
+497 -135
View File
@@ -1,22 +1,38 @@
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from ._schema10 import Schema10, Schema10TypedDict
from ._schema17 import Schema17, Schema17TypedDict
from ._schema5 import Schema5, Schema5TypedDict
from .chatstreamoptions import ChatStreamOptions, ChatStreamOptionsTypedDict
from .datacollection import DataCollection
from .debugoptions import DebugOptions, DebugOptionsTypedDict
from .message import Message, MessageTypedDict
from .providersortunion import ProviderSortUnion, ProviderSortUnionTypedDict
from .reasoningsummaryverbosity import ReasoningSummaryVerbosity
from .pdfparseroptions import PDFParserOptions, PDFParserOptionsTypedDict
from .preferredmaxlatency import PreferredMaxLatency, PreferredMaxLatencyTypedDict
from .preferredminthroughput import (
PreferredMinThroughput,
PreferredMinThroughputTypedDict,
)
from .providername import ProviderName
from .quantization import Quantization
from .responseformatjsonobject import (
ResponseFormatJSONObject,
ResponseFormatJSONObjectTypedDict,
)
from .responseformatjsonschema import (
ResponseFormatJSONSchema,
ResponseFormatJSONSchemaTypedDict,
)
from .responseformattext import ResponseFormatText, ResponseFormatTextTypedDict
from .responseformattextgrammar import (
ResponseFormatTextGrammar,
ResponseFormatTextGrammarTypedDict,
)
from .responseformattextpython import (
ResponseFormatTextPython,
ResponseFormatTextPythonTypedDict,
)
from .toolchoiceoption import ToolChoiceOption, ToolChoiceOptionTypedDict
from .tooldefinitionjson import ToolDefinitionJSON, ToolDefinitionJSONTypedDict
from .websearchengine import WebSearchEngine
from openrouter.types import (
BaseModel,
Nullable,
@@ -25,59 +41,109 @@ from openrouter.types import (
UNSET_SENTINEL,
UnrecognizedStr,
)
from openrouter.utils import get_discriminator, validate_const, validate_open_enum
from openrouter.utils import get_discriminator, validate_open_enum
import pydantic
from pydantic import Discriminator, Tag, model_serializer
from pydantic.functional_validators import AfterValidator, PlainValidator
from pydantic import ConfigDict, Discriminator, Tag, model_serializer
from pydantic.functional_validators import PlainValidator
from typing import Any, Dict, List, Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict
Schema3 = Union[
ChatGenerationParamsOrderTypedDict = TypeAliasType(
"ChatGenerationParamsOrderTypedDict", Union[ProviderName, str]
)
ChatGenerationParamsOrder = TypeAliasType(
"ChatGenerationParamsOrder",
Union[Annotated[ProviderName, PlainValidator(validate_open_enum(False))], str],
)
ChatGenerationParamsOnlyTypedDict = TypeAliasType(
"ChatGenerationParamsOnlyTypedDict", Union[ProviderName, str]
)
ChatGenerationParamsOnly = TypeAliasType(
"ChatGenerationParamsOnly",
Union[Annotated[ProviderName, PlainValidator(validate_open_enum(False))], str],
)
ChatGenerationParamsIgnoreTypedDict = TypeAliasType(
"ChatGenerationParamsIgnoreTypedDict", Union[ProviderName, str]
)
ChatGenerationParamsIgnore = TypeAliasType(
"ChatGenerationParamsIgnore",
Union[Annotated[ProviderName, PlainValidator(validate_open_enum(False))], str],
)
ChatGenerationParamsSortEnum = Union[
Literal[
"deny",
"allow",
"price",
"throughput",
"latency",
],
UnrecognizedStr,
]
Schema8 = Union[
Literal[
"int4",
"int8",
"fp4",
"fp6",
"fp8",
"fp16",
"bf16",
"fp32",
"unknown",
],
UnrecognizedStr,
ChatGenerationParamsProviderSortConfigEnum = Literal[
"price",
"throughput",
"latency",
]
class Schema15TypedDict(TypedDict):
p50: NotRequired[Nullable[float]]
p75: NotRequired[Nullable[float]]
p90: NotRequired[Nullable[float]]
p99: NotRequired[Nullable[float]]
ChatGenerationParamsBy = Union[
Literal[
"price",
"throughput",
"latency",
],
UnrecognizedStr,
]
r"""The provider sorting strategy (price, throughput, latency)"""
class Schema15(BaseModel):
p50: OptionalNullable[float] = UNSET
ChatGenerationParamsPartition = Union[
Literal[
"model",
"none",
],
UnrecognizedStr,
]
r"""Partitioning strategy for sorting: \"model\" (default) groups endpoints by model before sorting (fallback models remain fallbacks), \"none\" sorts all endpoints together regardless of model."""
p75: OptionalNullable[float] = UNSET
p90: OptionalNullable[float] = UNSET
class ChatGenerationParamsProviderSortConfigTypedDict(TypedDict):
by: NotRequired[Nullable[ChatGenerationParamsBy]]
r"""The provider sorting strategy (price, throughput, latency)"""
partition: NotRequired[Nullable[ChatGenerationParamsPartition]]
r"""Partitioning strategy for sorting: \"model\" (default) groups endpoints by model before sorting (fallback models remain fallbacks), \"none\" sorts all endpoints together regardless of model."""
p99: OptionalNullable[float] = UNSET
class ChatGenerationParamsProviderSortConfig(BaseModel):
by: Annotated[
OptionalNullable[ChatGenerationParamsBy],
PlainValidator(validate_open_enum(False)),
] = UNSET
r"""The provider sorting strategy (price, throughput, latency)"""
partition: Annotated[
OptionalNullable[ChatGenerationParamsPartition],
PlainValidator(validate_open_enum(False)),
] = UNSET
r"""Partitioning strategy for sorting: \"model\" (default) groups endpoints by model before sorting (fallback models remain fallbacks), \"none\" sorts all endpoints together regardless of model."""
@model_serializer(mode="wrap")
def serialize_model(self, handler):
optional_fields = ["p50", "p75", "p90", "p99"]
nullable_fields = ["p50", "p75", "p90", "p99"]
optional_fields = ["by", "partition"]
nullable_fields = ["by", "partition"]
null_default_fields = []
serialized = handler(self)
@@ -105,60 +171,177 @@ class Schema15(BaseModel):
return m
Schema15UnionTypedDict = TypeAliasType(
"Schema15UnionTypedDict", Union[Schema15TypedDict, float]
ChatGenerationParamsProviderSortConfigUnionTypedDict = TypeAliasType(
"ChatGenerationParamsProviderSortConfigUnionTypedDict",
Union[
ChatGenerationParamsProviderSortConfigTypedDict,
ChatGenerationParamsProviderSortConfigEnum,
],
)
Schema15Union = TypeAliasType("Schema15Union", Union[Schema15, float])
ChatGenerationParamsProviderSortConfigUnion = TypeAliasType(
"ChatGenerationParamsProviderSortConfigUnion",
Union[
ChatGenerationParamsProviderSortConfig,
ChatGenerationParamsProviderSortConfigEnum,
],
)
class Schema0TypedDict(TypedDict):
ChatGenerationParamsProviderSort = Union[
Literal[
"price",
"throughput",
"latency",
],
UnrecognizedStr,
]
r"""The provider sorting strategy (price, throughput, latency)"""
ChatGenerationParamsSortUnionTypedDict = TypeAliasType(
"ChatGenerationParamsSortUnionTypedDict",
Union[
ChatGenerationParamsProviderSort,
ChatGenerationParamsProviderSortConfigUnionTypedDict,
ChatGenerationParamsSortEnum,
],
)
r"""The sorting strategy to use for this request, if \"order\" is not specified. When set, no load balancing is performed."""
ChatGenerationParamsSortUnion = TypeAliasType(
"ChatGenerationParamsSortUnion",
Union[
Annotated[
ChatGenerationParamsProviderSort, PlainValidator(validate_open_enum(False))
],
ChatGenerationParamsProviderSortConfigUnion,
Annotated[
ChatGenerationParamsSortEnum, PlainValidator(validate_open_enum(False))
],
],
)
r"""The sorting strategy to use for this request, if \"order\" is not specified. When set, no load balancing is performed."""
class ChatGenerationParamsMaxPriceTypedDict(TypedDict):
r"""The object specifying the maximum price you want to pay for this request. USD price per million tokens, for prompt and completion."""
prompt: NotRequired[str]
r"""Price per million prompt tokens"""
completion: NotRequired[str]
image: NotRequired[str]
audio: NotRequired[str]
request: NotRequired[str]
class ChatGenerationParamsMaxPrice(BaseModel):
r"""The object specifying the maximum price you want to pay for this request. USD price per million tokens, for prompt and completion."""
prompt: Optional[str] = None
r"""Price per million prompt tokens"""
completion: Optional[str] = None
image: Optional[str] = None
audio: Optional[str] = None
request: Optional[str] = None
class ChatGenerationParamsProviderTypedDict(TypedDict):
r"""When multiple model providers are available, optionally indicate your routing preference."""
allow_fallbacks: NotRequired[Nullable[bool]]
r"""Whether to allow backup providers to serve requests
- true: (default) when the primary provider (or your custom providers in \"order\") is unavailable, use the next best provider.
- false: use only the primary/custom provider, and return the upstream error if it's unavailable.
"""
require_parameters: NotRequired[Nullable[bool]]
data_collection: NotRequired[Nullable[Schema3]]
r"""Whether to filter providers to only those that support the parameters you've provided. If this setting is omitted or set to false, then providers will receive only the parameters they support, and ignore the rest."""
data_collection: NotRequired[Nullable[DataCollection]]
r"""Data collection setting. If no available model provider meets the requirement, your request will return an error.
- allow: (default) allow providers which store user data non-transiently and may train on it
- deny: use only providers which do not collect user data.
"""
zdr: NotRequired[Nullable[bool]]
r"""Whether to restrict routing to only ZDR (Zero Data Retention) endpoints. When true, only endpoints that do not retain prompts will be used."""
enforce_distillable_text: NotRequired[Nullable[bool]]
order: NotRequired[Nullable[List[Schema5TypedDict]]]
only: NotRequired[Nullable[List[Schema5TypedDict]]]
ignore: NotRequired[Nullable[List[Schema5TypedDict]]]
quantizations: NotRequired[Nullable[List[Schema8]]]
sort: NotRequired[Nullable[ProviderSortUnionTypedDict]]
max_price: NotRequired[Schema10TypedDict]
preferred_min_throughput: NotRequired[Nullable[Schema15UnionTypedDict]]
preferred_max_latency: NotRequired[Nullable[Schema15UnionTypedDict]]
r"""Whether to restrict routing to only models that allow text distillation. When true, only models where the author has allowed distillation will be used."""
order: NotRequired[Nullable[List[ChatGenerationParamsOrderTypedDict]]]
r"""An ordered list of provider slugs. The router will attempt to use the first provider in the subset of this list that supports your requested model, and fall back to the next if it is unavailable. If no providers are available, the request will fail with an error message."""
only: NotRequired[Nullable[List[ChatGenerationParamsOnlyTypedDict]]]
r"""List of provider slugs to allow. If provided, this list is merged with your account-wide allowed provider settings for this request."""
ignore: NotRequired[Nullable[List[ChatGenerationParamsIgnoreTypedDict]]]
r"""List of provider slugs to ignore. If provided, this list is merged with your account-wide ignored provider settings for this request."""
quantizations: NotRequired[Nullable[List[Quantization]]]
r"""A list of quantization levels to filter the provider by."""
sort: NotRequired[Nullable[ChatGenerationParamsSortUnionTypedDict]]
max_price: NotRequired[ChatGenerationParamsMaxPriceTypedDict]
r"""The object specifying the maximum price you want to pay for this request. USD price per million tokens, for prompt and completion."""
preferred_min_throughput: NotRequired[Nullable[PreferredMinThroughputTypedDict]]
r"""Preferred minimum throughput (in tokens per second). Can be a number (applies to p50) or an object with percentile-specific cutoffs. Endpoints below the threshold(s) may still be used, but are deprioritized in routing. When using fallback models, this may cause a fallback model to be used instead of the primary model if it meets the threshold."""
preferred_max_latency: NotRequired[Nullable[PreferredMaxLatencyTypedDict]]
r"""Preferred maximum latency (in seconds). Can be a number (applies to p50) or an object with percentile-specific cutoffs. Endpoints above the threshold(s) may still be used, but are deprioritized in routing. When using fallback models, this may cause a fallback model to be used instead of the primary model if it meets the threshold."""
class Schema0(BaseModel):
class ChatGenerationParamsProvider(BaseModel):
r"""When multiple model providers are available, optionally indicate your routing preference."""
allow_fallbacks: OptionalNullable[bool] = UNSET
r"""Whether to allow backup providers to serve requests
- true: (default) when the primary provider (or your custom providers in \"order\") is unavailable, use the next best provider.
- false: use only the primary/custom provider, and return the upstream error if it's unavailable.
"""
require_parameters: OptionalNullable[bool] = UNSET
r"""Whether to filter providers to only those that support the parameters you've provided. If this setting is omitted or set to false, then providers will receive only the parameters they support, and ignore the rest."""
data_collection: Annotated[
OptionalNullable[Schema3], PlainValidator(validate_open_enum(False))
OptionalNullable[DataCollection], PlainValidator(validate_open_enum(False))
] = UNSET
r"""Data collection setting. If no available model provider meets the requirement, your request will return an error.
- allow: (default) allow providers which store user data non-transiently and may train on it
- deny: use only providers which do not collect user data.
"""
zdr: OptionalNullable[bool] = UNSET
r"""Whether to restrict routing to only ZDR (Zero Data Retention) endpoints. When true, only endpoints that do not retain prompts will be used."""
enforce_distillable_text: OptionalNullable[bool] = UNSET
r"""Whether to restrict routing to only models that allow text distillation. When true, only models where the author has allowed distillation will be used."""
order: OptionalNullable[List[Schema5]] = UNSET
order: OptionalNullable[List[ChatGenerationParamsOrder]] = UNSET
r"""An ordered list of provider slugs. The router will attempt to use the first provider in the subset of this list that supports your requested model, and fall back to the next if it is unavailable. If no providers are available, the request will fail with an error message."""
only: OptionalNullable[List[Schema5]] = UNSET
only: OptionalNullable[List[ChatGenerationParamsOnly]] = UNSET
r"""List of provider slugs to allow. If provided, this list is merged with your account-wide allowed provider settings for this request."""
ignore: OptionalNullable[List[Schema5]] = UNSET
ignore: OptionalNullable[List[ChatGenerationParamsIgnore]] = UNSET
r"""List of provider slugs to ignore. If provided, this list is merged with your account-wide ignored provider settings for this request."""
quantizations: OptionalNullable[
List[Annotated[Schema8, PlainValidator(validate_open_enum(False))]]
List[Annotated[Quantization, PlainValidator(validate_open_enum(False))]]
] = UNSET
r"""A list of quantization levels to filter the provider by."""
sort: OptionalNullable[ProviderSortUnion] = UNSET
sort: OptionalNullable[ChatGenerationParamsSortUnion] = UNSET
max_price: Optional[Schema10] = None
max_price: Optional[ChatGenerationParamsMaxPrice] = None
r"""The object specifying the maximum price you want to pay for this request. USD price per million tokens, for prompt and completion."""
preferred_min_throughput: OptionalNullable[Schema15Union] = UNSET
preferred_min_throughput: OptionalNullable[PreferredMinThroughput] = UNSET
r"""Preferred minimum throughput (in tokens per second). Can be a number (applies to p50) or an object with percentile-specific cutoffs. Endpoints below the threshold(s) may still be used, but are deprioritized in routing. When using fallback models, this may cause a fallback model to be used instead of the primary model if it meets the threshold."""
preferred_max_latency: OptionalNullable[Schema15Union] = UNSET
preferred_max_latency: OptionalNullable[PreferredMaxLatency] = UNSET
r"""Preferred maximum latency (in seconds). Can be a number (applies to p50) or an object with percentile-specific cutoffs. Endpoints above the threshold(s) may still be used, but are deprioritized in routing. When using fallback models, this may cause a fallback model to be used instead of the primary model if it meets the threshold."""
@model_serializer(mode="wrap")
def serialize_model(self, handler):
@@ -218,15 +401,165 @@ class Schema0(BaseModel):
return m
Route = Union[
Literal[
"fallback",
"sort",
ChatGenerationParamsIDResponseHealing = Literal["response-healing",]
class ChatGenerationParamsPluginResponseHealingTypedDict(TypedDict):
id: ChatGenerationParamsIDResponseHealing
enabled: NotRequired[bool]
r"""Set to false to disable the response-healing plugin for this request. Defaults to true."""
class ChatGenerationParamsPluginResponseHealing(BaseModel):
id: ChatGenerationParamsIDResponseHealing
enabled: Optional[bool] = None
r"""Set to false to disable the response-healing plugin for this request. Defaults to true."""
ChatGenerationParamsIDFileParser = Literal["file-parser",]
class ChatGenerationParamsPluginFileParserTypedDict(TypedDict):
id: ChatGenerationParamsIDFileParser
enabled: NotRequired[bool]
r"""Set to false to disable the file-parser plugin for this request. Defaults to true."""
pdf: NotRequired[PDFParserOptionsTypedDict]
r"""Options for PDF parsing."""
class ChatGenerationParamsPluginFileParser(BaseModel):
id: ChatGenerationParamsIDFileParser
enabled: Optional[bool] = None
r"""Set to false to disable the file-parser plugin for this request. Defaults to true."""
pdf: Optional[PDFParserOptions] = None
r"""Options for PDF parsing."""
ChatGenerationParamsIDWeb = Literal["web",]
class ChatGenerationParamsPluginWebTypedDict(TypedDict):
id: ChatGenerationParamsIDWeb
enabled: NotRequired[bool]
r"""Set to false to disable the web-search plugin for this request. Defaults to true."""
max_results: NotRequired[float]
search_prompt: NotRequired[str]
engine: NotRequired[WebSearchEngine]
r"""The search engine to use for web search."""
class ChatGenerationParamsPluginWeb(BaseModel):
id: ChatGenerationParamsIDWeb
enabled: Optional[bool] = None
r"""Set to false to disable the web-search plugin for this request. Defaults to true."""
max_results: Optional[float] = None
search_prompt: Optional[str] = None
engine: Annotated[
Optional[WebSearchEngine], PlainValidator(validate_open_enum(False))
] = None
r"""The search engine to use for web search."""
ChatGenerationParamsIDModeration = Literal["moderation",]
class ChatGenerationParamsPluginModerationTypedDict(TypedDict):
id: ChatGenerationParamsIDModeration
class ChatGenerationParamsPluginModeration(BaseModel):
id: ChatGenerationParamsIDModeration
ChatGenerationParamsIDAutoRouter = Literal["auto-router",]
class ChatGenerationParamsPluginAutoRouterTypedDict(TypedDict):
id: ChatGenerationParamsIDAutoRouter
enabled: NotRequired[bool]
r"""Set to false to disable the auto-router plugin for this request. Defaults to true."""
allowed_models: NotRequired[List[str]]
r"""List of model patterns to filter which models the auto-router can route between. Supports wildcards (e.g., \"anthropic/*\" matches all Anthropic models). When not specified, uses the default supported models list."""
class ChatGenerationParamsPluginAutoRouter(BaseModel):
id: ChatGenerationParamsIDAutoRouter
enabled: Optional[bool] = None
r"""Set to false to disable the auto-router plugin for this request. Defaults to true."""
allowed_models: Optional[List[str]] = None
r"""List of model patterns to filter which models the auto-router can route between. Supports wildcards (e.g., \"anthropic/*\" matches all Anthropic models). When not specified, uses the default supported models list."""
ChatGenerationParamsPluginUnionTypedDict = TypeAliasType(
"ChatGenerationParamsPluginUnionTypedDict",
Union[
ChatGenerationParamsPluginModerationTypedDict,
ChatGenerationParamsPluginResponseHealingTypedDict,
ChatGenerationParamsPluginAutoRouterTypedDict,
ChatGenerationParamsPluginFileParserTypedDict,
ChatGenerationParamsPluginWebTypedDict,
],
UnrecognizedStr,
)
ChatGenerationParamsPluginUnion = Annotated[
Union[
Annotated[ChatGenerationParamsPluginAutoRouter, Tag("auto-router")],
Annotated[ChatGenerationParamsPluginModeration, Tag("moderation")],
Annotated[ChatGenerationParamsPluginWeb, Tag("web")],
Annotated[ChatGenerationParamsPluginFileParser, Tag("file-parser")],
Annotated[ChatGenerationParamsPluginResponseHealing, Tag("response-healing")],
],
Discriminator(lambda m: get_discriminator(m, "id", "id")),
]
class ChatGenerationParamsTraceTypedDict(TypedDict):
r"""Metadata for observability and tracing. Known keys (trace_id, trace_name, span_name, generation_name, parent_span_id) have special handling. Additional keys are passed through as custom metadata to configured broadcast destinations."""
trace_id: NotRequired[str]
trace_name: NotRequired[str]
span_name: NotRequired[str]
generation_name: NotRequired[str]
parent_span_id: NotRequired[str]
class ChatGenerationParamsTrace(BaseModel):
r"""Metadata for observability and tracing. Known keys (trace_id, trace_name, span_name, generation_name, parent_span_id) have special handling. Additional keys are passed through as custom metadata to configured broadcast destinations."""
model_config = ConfigDict(
populate_by_name=True, arbitrary_types_allowed=True, extra="allow"
)
__pydantic_extra__: Dict[str, Nullable[Any]] = pydantic.Field(init=False)
trace_id: Optional[str] = None
trace_name: Optional[str] = None
span_name: Optional[str] = None
generation_name: Optional[str] = None
parent_span_id: Optional[str] = None
@property
def additional_properties(self):
return self.__pydantic_extra__
@additional_properties.setter
def additional_properties(self, value):
self.__pydantic_extra__ = value # pyright: ignore[reportIncompatibleVariableOverride]
Effort = Union[
Literal[
"xhigh",
@@ -238,22 +571,26 @@ Effort = Union[
],
UnrecognizedStr,
]
r"""Constrains effort on reasoning for reasoning models"""
class ReasoningTypedDict(TypedDict):
r"""Configuration options for reasoning models"""
effort: NotRequired[Nullable[Effort]]
summary: NotRequired[Nullable[ReasoningSummaryVerbosity]]
r"""Constrains effort on reasoning for reasoning models"""
summary: NotRequired[Nullable[Any]]
class Reasoning(BaseModel):
r"""Configuration options for reasoning models"""
effort: Annotated[
OptionalNullable[Effort], PlainValidator(validate_open_enum(False))
] = UNSET
r"""Constrains effort on reasoning for reasoning models"""
summary: Annotated[
OptionalNullable[ReasoningSummaryVerbosity],
PlainValidator(validate_open_enum(False)),
] = UNSET
summary: OptionalNullable[Any] = UNSET
@model_serializer(mode="wrap")
def serialize_model(self, handler):
@@ -286,51 +623,17 @@ class Reasoning(BaseModel):
return m
class ResponseFormatPythonTypedDict(TypedDict):
type: Literal["python"]
class ResponseFormatPython(BaseModel):
TYPE: Annotated[
Annotated[Literal["python"], AfterValidator(validate_const("python"))],
pydantic.Field(alias="type"),
] = "python"
class ResponseFormatJSONObjectTypedDict(TypedDict):
type: Literal["json_object"]
class ResponseFormatJSONObject(BaseModel):
TYPE: Annotated[
Annotated[
Literal["json_object"], AfterValidator(validate_const("json_object"))
],
pydantic.Field(alias="type"),
] = "json_object"
class ResponseFormatTextTypedDict(TypedDict):
type: Literal["text"]
class ResponseFormatText(BaseModel):
TYPE: Annotated[
Annotated[Literal["text"], AfterValidator(validate_const("text"))],
pydantic.Field(alias="type"),
] = "text"
ResponseFormatTypedDict = TypeAliasType(
"ResponseFormatTypedDict",
Union[
ResponseFormatTextTypedDict,
ResponseFormatJSONObjectTypedDict,
ResponseFormatPythonTypedDict,
ResponseFormatTextPythonTypedDict,
ResponseFormatJSONSchemaTypedDict,
ResponseFormatTextGrammarTypedDict,
],
)
r"""Response format configuration"""
ResponseFormat = Annotated[
@@ -339,33 +642,28 @@ ResponseFormat = Annotated[
Annotated[ResponseFormatJSONObject, Tag("json_object")],
Annotated[ResponseFormatJSONSchema, Tag("json_schema")],
Annotated[ResponseFormatTextGrammar, Tag("grammar")],
Annotated[ResponseFormatPython, Tag("python")],
Annotated[ResponseFormatTextPython, Tag("python")],
],
Discriminator(lambda m: get_discriminator(m, "type", "type")),
]
r"""Response format configuration"""
StopTypedDict = TypeAliasType("StopTypedDict", Union[str, List[str]])
StopTypedDict = TypeAliasType("StopTypedDict", Union[str, List[str], Any])
r"""Stop sequences (up to 4)"""
Stop = TypeAliasType("Stop", Union[str, List[str]])
class DebugTypedDict(TypedDict):
echo_upstream_body: NotRequired[bool]
class Debug(BaseModel):
echo_upstream_body: Optional[bool] = None
Stop = TypeAliasType("Stop", Union[str, List[str], Any])
r"""Stop sequences (up to 4)"""
ChatGenerationParamsImageConfigTypedDict = TypeAliasType(
"ChatGenerationParamsImageConfigTypedDict", Union[str, float, List[Any]]
"ChatGenerationParamsImageConfigTypedDict", Union[str, float, List[Nullable[Any]]]
)
ChatGenerationParamsImageConfig = TypeAliasType(
"ChatGenerationParamsImageConfig", Union[str, float, List[Any]]
"ChatGenerationParamsImageConfig", Union[str, float, List[Nullable[Any]]]
)
@@ -379,108 +677,171 @@ Modality = Union[
class ChatGenerationParamsTypedDict(TypedDict):
r"""Chat completion request parameters"""
messages: List[MessageTypedDict]
provider: NotRequired[Nullable[Schema0TypedDict]]
plugins: NotRequired[List[Schema17TypedDict]]
route: NotRequired[Nullable[Route]]
r"""List of messages for the conversation"""
provider: NotRequired[Nullable[ChatGenerationParamsProviderTypedDict]]
r"""When multiple model providers are available, optionally indicate your routing preference."""
plugins: NotRequired[List[ChatGenerationParamsPluginUnionTypedDict]]
r"""Plugins you want to enable for this request, including their settings."""
user: NotRequired[str]
r"""Unique user identifier"""
session_id: NotRequired[str]
r"""A unique identifier for grouping related requests (e.g., a conversation or agent workflow) for observability. If provided in both the request body and the x-session-id header, the body value takes precedence. Maximum of 128 characters."""
trace: NotRequired[ChatGenerationParamsTraceTypedDict]
r"""Metadata for observability and tracing. Known keys (trace_id, trace_name, span_name, generation_name, parent_span_id) have special handling. Additional keys are passed through as custom metadata to configured broadcast destinations."""
model: NotRequired[str]
r"""Model to use for completion"""
models: NotRequired[List[str]]
r"""Models to use for completion"""
frequency_penalty: NotRequired[Nullable[float]]
r"""Frequency penalty (-2.0 to 2.0)"""
logit_bias: NotRequired[Nullable[Dict[str, float]]]
r"""Token logit bias adjustments"""
logprobs: NotRequired[Nullable[bool]]
r"""Return log probabilities"""
top_logprobs: NotRequired[Nullable[float]]
r"""Number of top log probabilities to return (0-20)"""
max_completion_tokens: NotRequired[Nullable[float]]
r"""Maximum tokens in completion"""
max_tokens: NotRequired[Nullable[float]]
r"""Maximum tokens (deprecated, use max_completion_tokens)"""
metadata: NotRequired[Dict[str, str]]
r"""Key-value pairs for additional object information (max 16 pairs, 64 char keys, 512 char values)"""
presence_penalty: NotRequired[Nullable[float]]
r"""Presence penalty (-2.0 to 2.0)"""
reasoning: NotRequired[ReasoningTypedDict]
r"""Configuration options for reasoning models"""
response_format: NotRequired[ResponseFormatTypedDict]
r"""Response format configuration"""
seed: NotRequired[Nullable[int]]
r"""Random seed for deterministic outputs"""
stop: NotRequired[Nullable[StopTypedDict]]
r"""Stop sequences (up to 4)"""
stream: NotRequired[bool]
r"""Enable streaming response"""
stream_options: NotRequired[Nullable[ChatStreamOptionsTypedDict]]
r"""Streaming configuration options"""
temperature: NotRequired[Nullable[float]]
tool_choice: NotRequired[Any]
r"""Sampling temperature (0-2)"""
parallel_tool_calls: NotRequired[Nullable[bool]]
tool_choice: NotRequired[ToolChoiceOptionTypedDict]
r"""Tool choice configuration"""
tools: NotRequired[List[ToolDefinitionJSONTypedDict]]
r"""Available tools for function calling"""
top_p: NotRequired[Nullable[float]]
debug: NotRequired[DebugTypedDict]
r"""Nucleus sampling parameter (0-1)"""
debug: NotRequired[DebugOptionsTypedDict]
r"""Debug options for inspecting request transformations (streaming only)"""
image_config: NotRequired[Dict[str, ChatGenerationParamsImageConfigTypedDict]]
r"""Provider-specific image configuration options. Keys and values vary by model/provider. See https://openrouter.ai/docs/guides/overview/multimodal/image-generation for more details."""
modalities: NotRequired[List[Modality]]
r"""Output modalities for the response. Supported values are \"text\" and \"image\"."""
class ChatGenerationParams(BaseModel):
r"""Chat completion request parameters"""
messages: List[Message]
r"""List of messages for the conversation"""
provider: OptionalNullable[Schema0] = UNSET
provider: OptionalNullable[ChatGenerationParamsProvider] = UNSET
r"""When multiple model providers are available, optionally indicate your routing preference."""
plugins: Optional[List[Schema17]] = None
route: Annotated[
OptionalNullable[Route], PlainValidator(validate_open_enum(False))
] = UNSET
plugins: Optional[List[ChatGenerationParamsPluginUnion]] = None
r"""Plugins you want to enable for this request, including their settings."""
user: Optional[str] = None
r"""Unique user identifier"""
session_id: Optional[str] = None
r"""A unique identifier for grouping related requests (e.g., a conversation or agent workflow) for observability. If provided in both the request body and the x-session-id header, the body value takes precedence. Maximum of 128 characters."""
trace: Optional[ChatGenerationParamsTrace] = None
r"""Metadata for observability and tracing. Known keys (trace_id, trace_name, span_name, generation_name, parent_span_id) have special handling. Additional keys are passed through as custom metadata to configured broadcast destinations."""
model: Optional[str] = None
r"""Model to use for completion"""
models: Optional[List[str]] = None
r"""Models to use for completion"""
frequency_penalty: OptionalNullable[float] = UNSET
r"""Frequency penalty (-2.0 to 2.0)"""
logit_bias: OptionalNullable[Dict[str, float]] = UNSET
r"""Token logit bias adjustments"""
logprobs: OptionalNullable[bool] = UNSET
r"""Return log probabilities"""
top_logprobs: OptionalNullable[float] = UNSET
r"""Number of top log probabilities to return (0-20)"""
max_completion_tokens: OptionalNullable[float] = UNSET
r"""Maximum tokens in completion"""
max_tokens: OptionalNullable[float] = UNSET
r"""Maximum tokens (deprecated, use max_completion_tokens)"""
metadata: Optional[Dict[str, str]] = None
r"""Key-value pairs for additional object information (max 16 pairs, 64 char keys, 512 char values)"""
presence_penalty: OptionalNullable[float] = UNSET
r"""Presence penalty (-2.0 to 2.0)"""
reasoning: Optional[Reasoning] = None
r"""Configuration options for reasoning models"""
response_format: Optional[ResponseFormat] = None
r"""Response format configuration"""
seed: OptionalNullable[int] = UNSET
r"""Random seed for deterministic outputs"""
stop: OptionalNullable[Stop] = UNSET
r"""Stop sequences (up to 4)"""
stream: Optional[bool] = False
r"""Enable streaming response"""
stream_options: OptionalNullable[ChatStreamOptions] = UNSET
r"""Streaming configuration options"""
temperature: OptionalNullable[float] = UNSET
temperature: OptionalNullable[float] = 1
r"""Sampling temperature (0-2)"""
tool_choice: Optional[Any] = None
parallel_tool_calls: OptionalNullable[bool] = UNSET
tool_choice: Optional[ToolChoiceOption] = None
r"""Tool choice configuration"""
tools: Optional[List[ToolDefinitionJSON]] = None
r"""Available tools for function calling"""
top_p: OptionalNullable[float] = UNSET
top_p: OptionalNullable[float] = 1
r"""Nucleus sampling parameter (0-1)"""
debug: Optional[Debug] = None
debug: Optional[DebugOptions] = None
r"""Debug options for inspecting request transformations (streaming only)"""
image_config: Optional[Dict[str, ChatGenerationParamsImageConfig]] = None
r"""Provider-specific image configuration options. Keys and values vary by model/provider. See https://openrouter.ai/docs/guides/overview/multimodal/image-generation for more details."""
modalities: Optional[
List[Annotated[Modality, PlainValidator(validate_open_enum(False))]]
] = None
r"""Output modalities for the response. Supported values are \"text\" and \"image\"."""
@model_serializer(mode="wrap")
def serialize_model(self, handler):
optional_fields = [
"provider",
"plugins",
"route",
"user",
"session_id",
"trace",
"model",
"models",
"frequency_penalty",
@@ -498,6 +859,7 @@ class ChatGenerationParams(BaseModel):
"stream",
"stream_options",
"temperature",
"parallel_tool_calls",
"tool_choice",
"tools",
"top_p",
@@ -507,7 +869,6 @@ class ChatGenerationParams(BaseModel):
]
nullable_fields = [
"provider",
"route",
"frequency_penalty",
"logit_bias",
"logprobs",
@@ -519,6 +880,7 @@ class ChatGenerationParams(BaseModel):
"stop",
"stream_options",
"temperature",
"parallel_tool_calls",
"top_p",
]
null_default_fields = []