Files
openrouter-python-sdk-retry…/src/openrouter/components/chatgenerationparams.py
T
OpenRouter SDK Bot 5ab44f08f0 feat: regenerate SDK with updated OpenAPI spec
Speakeasy regeneration with latest schema changes including
type renames and new server tool models.
2026-03-27 15:18:14 -04:00

961 lines
37 KiB
Python

"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from .chatstreamoptions import ChatStreamOptions, ChatStreamOptionsTypedDict
from .datacollection import DataCollection
from .debugoptions import DebugOptions, DebugOptionsTypedDict
from .message import Message, MessageTypedDict
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,
OptionalNullable,
UNSET,
UNSET_SENTINEL,
UnrecognizedStr,
)
from openrouter.utils import get_discriminator, validate_open_enum
import pydantic
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
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[
"price",
"throughput",
"latency",
"exacto",
],
UnrecognizedStr,
]
ChatGenerationParamsProviderSortConfigEnum = Literal[
"price",
"throughput",
"latency",
"exacto",
]
ChatGenerationParamsBy = Union[
Literal[
"price",
"throughput",
"latency",
"exacto",
],
UnrecognizedStr,
]
r"""The provider sorting strategy (price, throughput, latency)"""
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."""
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."""
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 = ["by", "partition"]
nullable_fields = ["by", "partition"]
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
ChatGenerationParamsProviderSortConfigUnionTypedDict = TypeAliasType(
"ChatGenerationParamsProviderSortConfigUnionTypedDict",
Union[
ChatGenerationParamsProviderSortConfigTypedDict,
ChatGenerationParamsProviderSortConfigEnum,
],
)
ChatGenerationParamsProviderSortConfigUnion = TypeAliasType(
"ChatGenerationParamsProviderSortConfigUnion",
Union[
ChatGenerationParamsProviderSortConfig,
ChatGenerationParamsProviderSortConfigEnum,
],
)
ChatGenerationParamsProviderSort = Union[
Literal[
"price",
"throughput",
"latency",
"exacto",
],
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]]
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]]
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 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[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[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[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[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[Quantization, PlainValidator(validate_open_enum(False))]]
] = UNSET
r"""A list of quantization levels to filter the provider by."""
sort: OptionalNullable[ChatGenerationParamsSortUnion] = UNSET
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[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[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):
optional_fields = [
"allow_fallbacks",
"require_parameters",
"data_collection",
"zdr",
"enforce_distillable_text",
"order",
"only",
"ignore",
"quantizations",
"sort",
"max_price",
"preferred_min_throughput",
"preferred_max_latency",
]
nullable_fields = [
"allow_fallbacks",
"require_parameters",
"data_collection",
"zdr",
"enforce_distillable_text",
"order",
"only",
"ignore",
"quantizations",
"sort",
"preferred_min_throughput",
"preferred_max_latency",
]
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
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."""
include_domains: NotRequired[List[str]]
r"""A list of domains to restrict web search results to. Supports wildcards (e.g. \"*.substack.com\") and path filtering (e.g. \"openai.com/blog\")."""
exclude_domains: NotRequired[List[str]]
r"""A list of domains to exclude from web search results. Supports wildcards (e.g. \"*.substack.com\") and path filtering (e.g. \"openai.com/blog\")."""
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."""
include_domains: Optional[List[str]] = None
r"""A list of domains to restrict web search results to. Supports wildcards (e.g. \"*.substack.com\") and path filtering (e.g. \"openai.com/blog\")."""
exclude_domains: Optional[List[str]] = None
r"""A list of domains to exclude from web search results. Supports wildcards (e.g. \"*.substack.com\") and path filtering (e.g. \"openai.com/blog\")."""
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,
],
)
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",
"high",
"medium",
"low",
"minimal",
"none",
],
UnrecognizedStr,
]
r"""Constrains effort on reasoning for reasoning models"""
class ReasoningTypedDict(TypedDict):
r"""Configuration options for reasoning models"""
effort: NotRequired[Nullable[Effort]]
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: OptionalNullable[Any] = UNSET
@model_serializer(mode="wrap")
def serialize_model(self, handler):
optional_fields = ["effort", "summary"]
nullable_fields = ["effort", "summary"]
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
ResponseFormatTypedDict = TypeAliasType(
"ResponseFormatTypedDict",
Union[
ResponseFormatTextTypedDict,
ResponseFormatJSONObjectTypedDict,
ResponseFormatTextPythonTypedDict,
ResponseFormatJSONSchemaTypedDict,
ResponseFormatTextGrammarTypedDict,
],
)
r"""Response format configuration"""
ResponseFormat = Annotated[
Union[
Annotated[ResponseFormatText, Tag("text")],
Annotated[ResponseFormatJSONObject, Tag("json_object")],
Annotated[ResponseFormatJSONSchema, Tag("json_schema")],
Annotated[ResponseFormatTextGrammar, Tag("grammar")],
Annotated[ResponseFormatTextPython, Tag("python")],
],
Discriminator(lambda m: get_discriminator(m, "type", "type")),
]
r"""Response format configuration"""
StopTypedDict = TypeAliasType("StopTypedDict", Union[str, List[str], Any])
r"""Stop sequences (up to 4)"""
Stop = TypeAliasType("Stop", Union[str, List[str], Any])
r"""Stop sequences (up to 4)"""
ChatGenerationParamsImageConfigTypedDict = TypeAliasType(
"ChatGenerationParamsImageConfigTypedDict", Union[str, float, List[Nullable[Any]]]
)
ChatGenerationParamsImageConfig = TypeAliasType(
"ChatGenerationParamsImageConfig", Union[str, float, List[Nullable[Any]]]
)
Modality = Union[
Literal[
"text",
"image",
"audio",
],
UnrecognizedStr,
]
ChatGenerationParamsType = Literal["ephemeral",]
ChatGenerationParamsTTL = Union[
Literal[
"5m",
"1h",
],
UnrecognizedStr,
]
class CacheControlTypedDict(TypedDict):
r"""Enable automatic prompt caching. When set, the system automatically applies cache breakpoints to the last cacheable block in the request. Currently supported for Anthropic Claude models."""
type: ChatGenerationParamsType
ttl: NotRequired[ChatGenerationParamsTTL]
class CacheControl(BaseModel):
r"""Enable automatic prompt caching. When set, the system automatically applies cache breakpoints to the last cacheable block in the request. Currently supported for Anthropic Claude models."""
type: ChatGenerationParamsType
ttl: Annotated[
Optional[ChatGenerationParamsTTL], PlainValidator(validate_open_enum(False))
] = None
class ChatGenerationParamsTypedDict(TypedDict):
r"""Chat completion request parameters"""
messages: List[MessageTypedDict]
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). Note: some providers enforce a minimum of 16."""
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]]
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]]
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\", \"image\", and \"audio\"."""
cache_control: NotRequired[CacheControlTypedDict]
r"""Enable automatic prompt caching. When set, the system automatically applies cache breakpoints to the last cacheable block in the request. Currently supported for Anthropic Claude models."""
class ChatGenerationParams(BaseModel):
r"""Chat completion request parameters"""
messages: List[Message]
r"""List of messages for the conversation"""
provider: OptionalNullable[ChatGenerationParamsProvider] = UNSET
r"""When multiple model providers are available, optionally indicate your routing preference."""
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). Note: some providers enforce a minimum of 16."""
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] = 1
r"""Sampling temperature (0-2)"""
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] = 1
r"""Nucleus sampling parameter (0-1)"""
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\", \"image\", and \"audio\"."""
cache_control: Optional[CacheControl] = None
r"""Enable automatic prompt caching. When set, the system automatically applies cache breakpoints to the last cacheable block in the request. Currently supported for Anthropic Claude models."""
@model_serializer(mode="wrap")
def serialize_model(self, handler):
optional_fields = [
"provider",
"plugins",
"user",
"session_id",
"trace",
"model",
"models",
"frequency_penalty",
"logit_bias",
"logprobs",
"top_logprobs",
"max_completion_tokens",
"max_tokens",
"metadata",
"presence_penalty",
"reasoning",
"response_format",
"seed",
"stop",
"stream",
"stream_options",
"temperature",
"parallel_tool_calls",
"tool_choice",
"tools",
"top_p",
"debug",
"image_config",
"modalities",
"cache_control",
]
nullable_fields = [
"provider",
"frequency_penalty",
"logit_bias",
"logprobs",
"top_logprobs",
"max_completion_tokens",
"max_tokens",
"presence_penalty",
"seed",
"stop",
"stream_options",
"temperature",
"parallel_tool_calls",
"top_p",
]
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