mirror of
https://github.com/wassname/openrouter-python-sdk-retry-errors.git
synced 2026-08-01 12:40:23 +08:00
1076 lines
33 KiB
Python
1076 lines
33 KiB
Python
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
|
|
from __future__ import annotations
|
|
from .chatcompletionmessageparam import (
|
|
ChatCompletionMessageParam,
|
|
ChatCompletionMessageParamTypedDict,
|
|
)
|
|
from .chatcompletiontool import ChatCompletionTool, ChatCompletionToolTypedDict
|
|
from .chatcompletiontoolchoiceoption import (
|
|
ChatCompletionToolChoiceOption,
|
|
ChatCompletionToolChoiceOptionTypedDict,
|
|
)
|
|
from .responseformatjsonschemaschema import (
|
|
ResponseFormatJSONSchemaSchema,
|
|
ResponseFormatJSONSchemaSchemaTypedDict,
|
|
)
|
|
from openrouter.types import (
|
|
BaseModel,
|
|
Nullable,
|
|
OptionalNullable,
|
|
UNSET,
|
|
UNSET_SENTINEL,
|
|
)
|
|
import pydantic
|
|
from pydantic import model_serializer
|
|
from typing import Any, Dict, List, Literal, Optional, Union
|
|
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict
|
|
|
|
|
|
ChatCompletionCreateParamsEffort = Literal["high", "medium", "low", "minimal"]
|
|
r"""OpenAI-style reasoning effort setting"""
|
|
|
|
|
|
class ChatCompletionCreateParamsReasoningTypedDict(TypedDict):
|
|
r"""Reasoning configuration"""
|
|
|
|
enabled: NotRequired[bool]
|
|
r"""Enables reasoning with default settings. Only work for some models."""
|
|
effort: NotRequired[Nullable[ChatCompletionCreateParamsEffort]]
|
|
r"""OpenAI-style reasoning effort setting"""
|
|
max_tokens: NotRequired[Nullable[float]]
|
|
r"""non-OpenAI-style reasoning effort setting"""
|
|
exclude: NotRequired[bool]
|
|
|
|
|
|
class ChatCompletionCreateParamsReasoning(BaseModel):
|
|
r"""Reasoning configuration"""
|
|
|
|
enabled: Optional[bool] = None
|
|
r"""Enables reasoning with default settings. Only work for some models."""
|
|
|
|
effort: OptionalNullable[ChatCompletionCreateParamsEffort] = UNSET
|
|
r"""OpenAI-style reasoning effort setting"""
|
|
|
|
max_tokens: OptionalNullable[float] = UNSET
|
|
r"""non-OpenAI-style reasoning effort setting"""
|
|
|
|
exclude: Optional[bool] = False
|
|
|
|
@model_serializer(mode="wrap")
|
|
def serialize_model(self, handler):
|
|
optional_fields = ["enabled", "effort", "max_tokens", "exclude"]
|
|
nullable_fields = ["effort", "max_tokens"]
|
|
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
|
|
|
|
|
|
ChatCompletionCreateParamsTypePython = Literal["python"]
|
|
|
|
|
|
class ChatCompletionCreateParamsResponseFormatPythonTypedDict(TypedDict):
|
|
r"""Python code response format"""
|
|
|
|
type: ChatCompletionCreateParamsTypePython
|
|
|
|
|
|
class ChatCompletionCreateParamsResponseFormatPython(BaseModel):
|
|
r"""Python code response format"""
|
|
|
|
type: ChatCompletionCreateParamsTypePython
|
|
|
|
|
|
ChatCompletionCreateParamsTypeGrammar = Literal["grammar"]
|
|
|
|
|
|
class ChatCompletionCreateParamsResponseFormatGrammarTypedDict(TypedDict):
|
|
r"""Custom grammar response format"""
|
|
|
|
type: ChatCompletionCreateParamsTypeGrammar
|
|
grammar: str
|
|
r"""Custom grammar for text generation"""
|
|
|
|
|
|
class ChatCompletionCreateParamsResponseFormatGrammar(BaseModel):
|
|
r"""Custom grammar response format"""
|
|
|
|
type: ChatCompletionCreateParamsTypeGrammar
|
|
|
|
grammar: str
|
|
r"""Custom grammar for text generation"""
|
|
|
|
|
|
ChatCompletionCreateParamsTypeJSONSchema = Literal["json_schema"]
|
|
|
|
|
|
class ChatCompletionCreateParamsJSONSchemaTypedDict(TypedDict):
|
|
name: str
|
|
r"""Schema name (a-z, A-Z, 0-9, underscores, dashes, max 64 chars)"""
|
|
description: NotRequired[str]
|
|
r"""Schema description for the model"""
|
|
schema_: NotRequired[ResponseFormatJSONSchemaSchemaTypedDict]
|
|
r"""The schema for the response format, described as a JSON Schema object"""
|
|
strict: NotRequired[Nullable[bool]]
|
|
r"""Enable strict schema adherence"""
|
|
|
|
|
|
class ChatCompletionCreateParamsJSONSchema(BaseModel):
|
|
name: str
|
|
r"""Schema name (a-z, A-Z, 0-9, underscores, dashes, max 64 chars)"""
|
|
|
|
description: Optional[str] = None
|
|
r"""Schema description for the model"""
|
|
|
|
schema_: Annotated[
|
|
Optional[ResponseFormatJSONSchemaSchema], pydantic.Field(alias="schema")
|
|
] = None
|
|
r"""The schema for the response format, described as a JSON Schema object"""
|
|
|
|
strict: OptionalNullable[bool] = UNSET
|
|
r"""Enable strict schema adherence"""
|
|
|
|
@model_serializer(mode="wrap")
|
|
def serialize_model(self, handler):
|
|
optional_fields = ["description", "schema", "strict"]
|
|
nullable_fields = ["strict"]
|
|
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 ChatCompletionCreateParamsResponseFormatJSONSchemaTypedDict(TypedDict):
|
|
r"""JSON Schema response format for structured outputs"""
|
|
|
|
type: ChatCompletionCreateParamsTypeJSONSchema
|
|
json_schema: ChatCompletionCreateParamsJSONSchemaTypedDict
|
|
|
|
|
|
class ChatCompletionCreateParamsResponseFormatJSONSchema(BaseModel):
|
|
r"""JSON Schema response format for structured outputs"""
|
|
|
|
type: ChatCompletionCreateParamsTypeJSONSchema
|
|
|
|
json_schema: ChatCompletionCreateParamsJSONSchema
|
|
|
|
|
|
ChatCompletionCreateParamsTypeJSONObject = Literal["json_object"]
|
|
|
|
|
|
class ChatCompletionCreateParamsResponseFormatJSONObjectTypedDict(TypedDict):
|
|
r"""JSON object response format"""
|
|
|
|
type: ChatCompletionCreateParamsTypeJSONObject
|
|
|
|
|
|
class ChatCompletionCreateParamsResponseFormatJSONObject(BaseModel):
|
|
r"""JSON object response format"""
|
|
|
|
type: ChatCompletionCreateParamsTypeJSONObject
|
|
|
|
|
|
ChatCompletionCreateParamsTypeText = Literal["text"]
|
|
|
|
|
|
class ChatCompletionCreateParamsResponseFormatTextTypedDict(TypedDict):
|
|
r"""Default text response format"""
|
|
|
|
type: ChatCompletionCreateParamsTypeText
|
|
|
|
|
|
class ChatCompletionCreateParamsResponseFormatText(BaseModel):
|
|
r"""Default text response format"""
|
|
|
|
type: ChatCompletionCreateParamsTypeText
|
|
|
|
|
|
ChatCompletionCreateParamsResponseFormatUnionTypedDict = TypeAliasType(
|
|
"ChatCompletionCreateParamsResponseFormatUnionTypedDict",
|
|
Union[
|
|
ChatCompletionCreateParamsResponseFormatTextTypedDict,
|
|
ChatCompletionCreateParamsResponseFormatJSONObjectTypedDict,
|
|
ChatCompletionCreateParamsResponseFormatPythonTypedDict,
|
|
ChatCompletionCreateParamsResponseFormatJSONSchemaTypedDict,
|
|
ChatCompletionCreateParamsResponseFormatGrammarTypedDict,
|
|
],
|
|
)
|
|
r"""Response format configuration"""
|
|
|
|
|
|
ChatCompletionCreateParamsResponseFormatUnion = TypeAliasType(
|
|
"ChatCompletionCreateParamsResponseFormatUnion",
|
|
Union[
|
|
ChatCompletionCreateParamsResponseFormatText,
|
|
ChatCompletionCreateParamsResponseFormatJSONObject,
|
|
ChatCompletionCreateParamsResponseFormatPython,
|
|
ChatCompletionCreateParamsResponseFormatJSONSchema,
|
|
ChatCompletionCreateParamsResponseFormatGrammar,
|
|
],
|
|
)
|
|
r"""Response format configuration"""
|
|
|
|
|
|
ChatCompletionCreateParamsStopTypedDict = TypeAliasType(
|
|
"ChatCompletionCreateParamsStopTypedDict", Union[str, List[str], Any]
|
|
)
|
|
r"""Stop sequences (up to 4)"""
|
|
|
|
|
|
ChatCompletionCreateParamsStop = TypeAliasType(
|
|
"ChatCompletionCreateParamsStop", Union[str, List[str], Any]
|
|
)
|
|
r"""Stop sequences (up to 4)"""
|
|
|
|
|
|
class ChatCompletionCreateParamsStreamOptionsTypedDict(TypedDict):
|
|
r"""Streaming configuration options"""
|
|
|
|
include_usage: NotRequired[bool]
|
|
r"""Include usage information in streaming response"""
|
|
|
|
|
|
class ChatCompletionCreateParamsStreamOptions(BaseModel):
|
|
r"""Streaming configuration options"""
|
|
|
|
include_usage: Optional[bool] = None
|
|
r"""Include usage information in streaming response"""
|
|
|
|
|
|
ChatCompletionCreateParamsReasoningEffort = Literal["high", "medium", "low", "minimal"]
|
|
r"""Reasoning effort"""
|
|
|
|
ChatCompletionCreateParamsDataCollection = Literal["deny", "allow"]
|
|
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.
|
|
|
|
"""
|
|
|
|
ChatCompletionCreateParamsOrderEnum = Literal[
|
|
"AnyScale",
|
|
"Cent-ML",
|
|
"HuggingFace",
|
|
"Hyperbolic 2",
|
|
"Lepton",
|
|
"Lynn 2",
|
|
"Lynn",
|
|
"Mancer",
|
|
"Modal",
|
|
"OctoAI",
|
|
"Recursal",
|
|
"Reflection",
|
|
"Replicate",
|
|
"SambaNova 2",
|
|
"SF Compute",
|
|
"Together 2",
|
|
"01.AI",
|
|
"AI21",
|
|
"AionLabs",
|
|
"Alibaba",
|
|
"Amazon Bedrock",
|
|
"Anthropic",
|
|
"AtlasCloud",
|
|
"Atoma",
|
|
"Avian",
|
|
"Azure",
|
|
"BaseTen",
|
|
"Cerebras",
|
|
"Chutes",
|
|
"Cloudflare",
|
|
"Cohere",
|
|
"CrofAI",
|
|
"Crusoe",
|
|
"DeepInfra",
|
|
"DeepSeek",
|
|
"Enfer",
|
|
"Featherless",
|
|
"Fireworks",
|
|
"Friendli",
|
|
"GMICloud",
|
|
"Google",
|
|
"Google AI Studio",
|
|
"Groq",
|
|
"Hyperbolic",
|
|
"Inception",
|
|
"InferenceNet",
|
|
"Infermatic",
|
|
"Inflection",
|
|
"InoCloud",
|
|
"Kluster",
|
|
"Lambda",
|
|
"Liquid",
|
|
"Mancer 2",
|
|
"Meta",
|
|
"Minimax",
|
|
"Mistral",
|
|
"Moonshot AI",
|
|
"Morph",
|
|
"NCompass",
|
|
"Nebius",
|
|
"NextBit",
|
|
"Nineteen",
|
|
"Novita",
|
|
"OpenAI",
|
|
"OpenInference",
|
|
"Parasail",
|
|
"Perplexity",
|
|
"Phala",
|
|
"SambaNova",
|
|
"Stealth",
|
|
"Switchpoint",
|
|
"Targon",
|
|
"Together",
|
|
"Ubicloud",
|
|
"Venice",
|
|
"WandB",
|
|
"xAI",
|
|
"Z.AI",
|
|
]
|
|
|
|
ChatCompletionCreateParamsOrderUnionTypedDict = TypeAliasType(
|
|
"ChatCompletionCreateParamsOrderUnionTypedDict",
|
|
Union[ChatCompletionCreateParamsOrderEnum, str],
|
|
)
|
|
|
|
|
|
ChatCompletionCreateParamsOrderUnion = TypeAliasType(
|
|
"ChatCompletionCreateParamsOrderUnion",
|
|
Union[ChatCompletionCreateParamsOrderEnum, str],
|
|
)
|
|
|
|
|
|
ChatCompletionCreateParamsOnlyEnum = Literal[
|
|
"AnyScale",
|
|
"Cent-ML",
|
|
"HuggingFace",
|
|
"Hyperbolic 2",
|
|
"Lepton",
|
|
"Lynn 2",
|
|
"Lynn",
|
|
"Mancer",
|
|
"Modal",
|
|
"OctoAI",
|
|
"Recursal",
|
|
"Reflection",
|
|
"Replicate",
|
|
"SambaNova 2",
|
|
"SF Compute",
|
|
"Together 2",
|
|
"01.AI",
|
|
"AI21",
|
|
"AionLabs",
|
|
"Alibaba",
|
|
"Amazon Bedrock",
|
|
"Anthropic",
|
|
"AtlasCloud",
|
|
"Atoma",
|
|
"Avian",
|
|
"Azure",
|
|
"BaseTen",
|
|
"Cerebras",
|
|
"Chutes",
|
|
"Cloudflare",
|
|
"Cohere",
|
|
"CrofAI",
|
|
"Crusoe",
|
|
"DeepInfra",
|
|
"DeepSeek",
|
|
"Enfer",
|
|
"Featherless",
|
|
"Fireworks",
|
|
"Friendli",
|
|
"GMICloud",
|
|
"Google",
|
|
"Google AI Studio",
|
|
"Groq",
|
|
"Hyperbolic",
|
|
"Inception",
|
|
"InferenceNet",
|
|
"Infermatic",
|
|
"Inflection",
|
|
"InoCloud",
|
|
"Kluster",
|
|
"Lambda",
|
|
"Liquid",
|
|
"Mancer 2",
|
|
"Meta",
|
|
"Minimax",
|
|
"Mistral",
|
|
"Moonshot AI",
|
|
"Morph",
|
|
"NCompass",
|
|
"Nebius",
|
|
"NextBit",
|
|
"Nineteen",
|
|
"Novita",
|
|
"OpenAI",
|
|
"OpenInference",
|
|
"Parasail",
|
|
"Perplexity",
|
|
"Phala",
|
|
"SambaNova",
|
|
"Stealth",
|
|
"Switchpoint",
|
|
"Targon",
|
|
"Together",
|
|
"Ubicloud",
|
|
"Venice",
|
|
"WandB",
|
|
"xAI",
|
|
"Z.AI",
|
|
]
|
|
|
|
ChatCompletionCreateParamsOnlyUnionTypedDict = TypeAliasType(
|
|
"ChatCompletionCreateParamsOnlyUnionTypedDict",
|
|
Union[ChatCompletionCreateParamsOnlyEnum, str],
|
|
)
|
|
|
|
|
|
ChatCompletionCreateParamsOnlyUnion = TypeAliasType(
|
|
"ChatCompletionCreateParamsOnlyUnion",
|
|
Union[ChatCompletionCreateParamsOnlyEnum, str],
|
|
)
|
|
|
|
|
|
ChatCompletionCreateParamsIgnoreEnum = Literal[
|
|
"AnyScale",
|
|
"Cent-ML",
|
|
"HuggingFace",
|
|
"Hyperbolic 2",
|
|
"Lepton",
|
|
"Lynn 2",
|
|
"Lynn",
|
|
"Mancer",
|
|
"Modal",
|
|
"OctoAI",
|
|
"Recursal",
|
|
"Reflection",
|
|
"Replicate",
|
|
"SambaNova 2",
|
|
"SF Compute",
|
|
"Together 2",
|
|
"01.AI",
|
|
"AI21",
|
|
"AionLabs",
|
|
"Alibaba",
|
|
"Amazon Bedrock",
|
|
"Anthropic",
|
|
"AtlasCloud",
|
|
"Atoma",
|
|
"Avian",
|
|
"Azure",
|
|
"BaseTen",
|
|
"Cerebras",
|
|
"Chutes",
|
|
"Cloudflare",
|
|
"Cohere",
|
|
"CrofAI",
|
|
"Crusoe",
|
|
"DeepInfra",
|
|
"DeepSeek",
|
|
"Enfer",
|
|
"Featherless",
|
|
"Fireworks",
|
|
"Friendli",
|
|
"GMICloud",
|
|
"Google",
|
|
"Google AI Studio",
|
|
"Groq",
|
|
"Hyperbolic",
|
|
"Inception",
|
|
"InferenceNet",
|
|
"Infermatic",
|
|
"Inflection",
|
|
"InoCloud",
|
|
"Kluster",
|
|
"Lambda",
|
|
"Liquid",
|
|
"Mancer 2",
|
|
"Meta",
|
|
"Minimax",
|
|
"Mistral",
|
|
"Moonshot AI",
|
|
"Morph",
|
|
"NCompass",
|
|
"Nebius",
|
|
"NextBit",
|
|
"Nineteen",
|
|
"Novita",
|
|
"OpenAI",
|
|
"OpenInference",
|
|
"Parasail",
|
|
"Perplexity",
|
|
"Phala",
|
|
"SambaNova",
|
|
"Stealth",
|
|
"Switchpoint",
|
|
"Targon",
|
|
"Together",
|
|
"Ubicloud",
|
|
"Venice",
|
|
"WandB",
|
|
"xAI",
|
|
"Z.AI",
|
|
]
|
|
|
|
ChatCompletionCreateParamsIgnoreUnionTypedDict = TypeAliasType(
|
|
"ChatCompletionCreateParamsIgnoreUnionTypedDict",
|
|
Union[ChatCompletionCreateParamsIgnoreEnum, str],
|
|
)
|
|
|
|
|
|
ChatCompletionCreateParamsIgnoreUnion = TypeAliasType(
|
|
"ChatCompletionCreateParamsIgnoreUnion",
|
|
Union[ChatCompletionCreateParamsIgnoreEnum, str],
|
|
)
|
|
|
|
|
|
ChatCompletionCreateParamsQuantization = Literal[
|
|
"int4", "int8", "fp4", "fp6", "fp8", "fp16", "bf16", "fp32", "unknown"
|
|
]
|
|
|
|
ChatCompletionCreateParamsSort = Literal["price", "throughput", "latency"]
|
|
r"""The sorting strategy to use for this request, if \"order\" is not specified. When set, no load balancing is performed."""
|
|
|
|
ChatCompletionCreateParamsPromptTypedDict = TypeAliasType(
|
|
"ChatCompletionCreateParamsPromptTypedDict", Union[float, str, Any]
|
|
)
|
|
|
|
|
|
ChatCompletionCreateParamsPrompt = TypeAliasType(
|
|
"ChatCompletionCreateParamsPrompt", Union[float, str, Any]
|
|
)
|
|
|
|
|
|
ChatCompletionCreateParamsCompletionTypedDict = TypeAliasType(
|
|
"ChatCompletionCreateParamsCompletionTypedDict", Union[float, str, Any]
|
|
)
|
|
|
|
|
|
ChatCompletionCreateParamsCompletion = TypeAliasType(
|
|
"ChatCompletionCreateParamsCompletion", Union[float, str, Any]
|
|
)
|
|
|
|
|
|
ChatCompletionCreateParamsImageTypedDict = TypeAliasType(
|
|
"ChatCompletionCreateParamsImageTypedDict", Union[float, str, Any]
|
|
)
|
|
|
|
|
|
ChatCompletionCreateParamsImage = TypeAliasType(
|
|
"ChatCompletionCreateParamsImage", Union[float, str, Any]
|
|
)
|
|
|
|
|
|
ChatCompletionCreateParamsAudioTypedDict = TypeAliasType(
|
|
"ChatCompletionCreateParamsAudioTypedDict", Union[float, str, Any]
|
|
)
|
|
|
|
|
|
ChatCompletionCreateParamsAudio = TypeAliasType(
|
|
"ChatCompletionCreateParamsAudio", Union[float, str, Any]
|
|
)
|
|
|
|
|
|
ChatCompletionCreateParamsRequestTypedDict = TypeAliasType(
|
|
"ChatCompletionCreateParamsRequestTypedDict", Union[float, str, Any]
|
|
)
|
|
|
|
|
|
ChatCompletionCreateParamsRequest = TypeAliasType(
|
|
"ChatCompletionCreateParamsRequest", Union[float, str, Any]
|
|
)
|
|
|
|
|
|
class ChatCompletionCreateParamsMaxPriceTypedDict(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[ChatCompletionCreateParamsPromptTypedDict]
|
|
completion: NotRequired[ChatCompletionCreateParamsCompletionTypedDict]
|
|
image: NotRequired[ChatCompletionCreateParamsImageTypedDict]
|
|
audio: NotRequired[ChatCompletionCreateParamsAudioTypedDict]
|
|
request: NotRequired[ChatCompletionCreateParamsRequestTypedDict]
|
|
|
|
|
|
class ChatCompletionCreateParamsMaxPrice(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[ChatCompletionCreateParamsPrompt] = None
|
|
|
|
completion: Optional[ChatCompletionCreateParamsCompletion] = None
|
|
|
|
image: Optional[ChatCompletionCreateParamsImage] = None
|
|
|
|
audio: Optional[ChatCompletionCreateParamsAudio] = None
|
|
|
|
request: Optional[ChatCompletionCreateParamsRequest] = None
|
|
|
|
|
|
class ChatCompletionCreateParamsProviderTypedDict(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[ChatCompletionCreateParamsDataCollection]]
|
|
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.
|
|
|
|
"""
|
|
order: NotRequired[Nullable[List[ChatCompletionCreateParamsOrderUnionTypedDict]]]
|
|
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[ChatCompletionCreateParamsOnlyUnionTypedDict]]]
|
|
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[ChatCompletionCreateParamsIgnoreUnionTypedDict]]]
|
|
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[ChatCompletionCreateParamsQuantization]]]
|
|
r"""A list of quantization levels to filter the provider by."""
|
|
sort: NotRequired[Nullable[ChatCompletionCreateParamsSort]]
|
|
r"""The sorting strategy to use for this request, if \"order\" is not specified. When set, no load balancing is performed."""
|
|
max_price: NotRequired[ChatCompletionCreateParamsMaxPriceTypedDict]
|
|
r"""The object specifying the maximum price you want to pay for this request. USD price per million tokens, for prompt and completion."""
|
|
|
|
|
|
class ChatCompletionCreateParamsProvider(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: OptionalNullable[ChatCompletionCreateParamsDataCollection] = 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.
|
|
|
|
"""
|
|
|
|
order: OptionalNullable[List[ChatCompletionCreateParamsOrderUnion]] = 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[ChatCompletionCreateParamsOnlyUnion]] = 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[ChatCompletionCreateParamsIgnoreUnion]] = 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[ChatCompletionCreateParamsQuantization]] = (
|
|
UNSET
|
|
)
|
|
r"""A list of quantization levels to filter the provider by."""
|
|
|
|
sort: OptionalNullable[ChatCompletionCreateParamsSort] = UNSET
|
|
r"""The sorting strategy to use for this request, if \"order\" is not specified. When set, no load balancing is performed."""
|
|
|
|
max_price: Optional[ChatCompletionCreateParamsMaxPrice] = None
|
|
r"""The object specifying the maximum price you want to pay for this request. USD price per million tokens, for prompt and completion."""
|
|
|
|
@model_serializer(mode="wrap")
|
|
def serialize_model(self, handler):
|
|
optional_fields = [
|
|
"allow_fallbacks",
|
|
"require_parameters",
|
|
"data_collection",
|
|
"order",
|
|
"only",
|
|
"ignore",
|
|
"quantizations",
|
|
"sort",
|
|
"max_price",
|
|
]
|
|
nullable_fields = [
|
|
"allow_fallbacks",
|
|
"require_parameters",
|
|
"data_collection",
|
|
"order",
|
|
"only",
|
|
"ignore",
|
|
"quantizations",
|
|
"sort",
|
|
]
|
|
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
|
|
|
|
|
|
ChatCompletionCreateParamsIDFileParser = Literal["file-parser"]
|
|
|
|
ChatCompletionCreateParamsPdfEngine = Literal["mistral-ocr", "pdf-text", "native"]
|
|
|
|
|
|
class ChatCompletionCreateParamsPdfTypedDict(TypedDict):
|
|
engine: NotRequired[ChatCompletionCreateParamsPdfEngine]
|
|
|
|
|
|
class ChatCompletionCreateParamsPdf(BaseModel):
|
|
engine: Optional[ChatCompletionCreateParamsPdfEngine] = None
|
|
|
|
|
|
class ChatCompletionCreateParamsPluginFileParserTypedDict(TypedDict):
|
|
id: ChatCompletionCreateParamsIDFileParser
|
|
max_files: NotRequired[float]
|
|
pdf: NotRequired[ChatCompletionCreateParamsPdfTypedDict]
|
|
|
|
|
|
class ChatCompletionCreateParamsPluginFileParser(BaseModel):
|
|
id: ChatCompletionCreateParamsIDFileParser
|
|
|
|
max_files: Optional[float] = None
|
|
|
|
pdf: Optional[ChatCompletionCreateParamsPdf] = None
|
|
|
|
|
|
ChatCompletionCreateParamsIDChainOfThought = Literal["chain-of-thought"]
|
|
|
|
|
|
class ChatCompletionCreateParamsPluginChainOfThoughtTypedDict(TypedDict):
|
|
id: ChatCompletionCreateParamsIDChainOfThought
|
|
|
|
|
|
class ChatCompletionCreateParamsPluginChainOfThought(BaseModel):
|
|
id: ChatCompletionCreateParamsIDChainOfThought
|
|
|
|
|
|
ChatCompletionCreateParamsIDWeb = Literal["web"]
|
|
|
|
ChatCompletionCreateParamsEngine = Literal["native", "exa"]
|
|
|
|
|
|
class ChatCompletionCreateParamsPluginWebTypedDict(TypedDict):
|
|
id: ChatCompletionCreateParamsIDWeb
|
|
max_results: NotRequired[float]
|
|
search_prompt: NotRequired[str]
|
|
engine: NotRequired[ChatCompletionCreateParamsEngine]
|
|
|
|
|
|
class ChatCompletionCreateParamsPluginWeb(BaseModel):
|
|
id: ChatCompletionCreateParamsIDWeb
|
|
|
|
max_results: Optional[float] = None
|
|
|
|
search_prompt: Optional[str] = None
|
|
|
|
engine: Optional[ChatCompletionCreateParamsEngine] = None
|
|
|
|
|
|
ChatCompletionCreateParamsIDModeration = Literal["moderation"]
|
|
|
|
|
|
class ChatCompletionCreateParamsPluginModerationTypedDict(TypedDict):
|
|
id: ChatCompletionCreateParamsIDModeration
|
|
|
|
|
|
class ChatCompletionCreateParamsPluginModeration(BaseModel):
|
|
id: ChatCompletionCreateParamsIDModeration
|
|
|
|
|
|
ChatCompletionCreateParamsPluginUnionTypedDict = TypeAliasType(
|
|
"ChatCompletionCreateParamsPluginUnionTypedDict",
|
|
Union[
|
|
ChatCompletionCreateParamsPluginModerationTypedDict,
|
|
ChatCompletionCreateParamsPluginChainOfThoughtTypedDict,
|
|
ChatCompletionCreateParamsPluginFileParserTypedDict,
|
|
ChatCompletionCreateParamsPluginWebTypedDict,
|
|
],
|
|
)
|
|
|
|
|
|
ChatCompletionCreateParamsPluginUnion = TypeAliasType(
|
|
"ChatCompletionCreateParamsPluginUnion",
|
|
Union[
|
|
ChatCompletionCreateParamsPluginModeration,
|
|
ChatCompletionCreateParamsPluginChainOfThought,
|
|
ChatCompletionCreateParamsPluginFileParser,
|
|
ChatCompletionCreateParamsPluginWeb,
|
|
],
|
|
)
|
|
|
|
|
|
class ChatCompletionCreateParamsTypedDict(TypedDict):
|
|
r"""Chat completion request parameters"""
|
|
|
|
messages: List[ChatCompletionMessageParamTypedDict]
|
|
r"""List of messages for the conversation"""
|
|
model: NotRequired[str]
|
|
r"""Model 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[Nullable[ChatCompletionCreateParamsReasoningTypedDict]]
|
|
r"""Reasoning configuration"""
|
|
response_format: NotRequired[ChatCompletionCreateParamsResponseFormatUnionTypedDict]
|
|
r"""Response format configuration"""
|
|
seed: NotRequired[Nullable[int]]
|
|
r"""Random seed for deterministic outputs"""
|
|
stop: NotRequired[Nullable[ChatCompletionCreateParamsStopTypedDict]]
|
|
r"""Stop sequences (up to 4)"""
|
|
stream: NotRequired[Nullable[bool]]
|
|
r"""Enable streaming response"""
|
|
stream_options: NotRequired[
|
|
Nullable[ChatCompletionCreateParamsStreamOptionsTypedDict]
|
|
]
|
|
temperature: NotRequired[Nullable[float]]
|
|
r"""Sampling temperature (0-2)"""
|
|
tool_choice: NotRequired[ChatCompletionToolChoiceOptionTypedDict]
|
|
r"""Tool choice configuration"""
|
|
tools: NotRequired[List[ChatCompletionToolTypedDict]]
|
|
r"""Available tools for function calling"""
|
|
top_p: NotRequired[Nullable[float]]
|
|
r"""Nucleus sampling parameter (0-1)"""
|
|
user: NotRequired[str]
|
|
r"""Unique user identifier"""
|
|
fallback_models: NotRequired[Nullable[List[str]]]
|
|
r"""Order of models to fallback to for this request"""
|
|
reasoning_effort: NotRequired[Nullable[ChatCompletionCreateParamsReasoningEffort]]
|
|
r"""Reasoning effort"""
|
|
provider: NotRequired[Nullable[ChatCompletionCreateParamsProviderTypedDict]]
|
|
r"""When multiple model providers are available, optionally indicate your routing preference."""
|
|
plugins: NotRequired[List[ChatCompletionCreateParamsPluginUnionTypedDict]]
|
|
r"""Plugins you want to enable for this request, including their settings."""
|
|
|
|
|
|
class ChatCompletionCreateParams(BaseModel):
|
|
r"""Chat completion request parameters"""
|
|
|
|
messages: List[ChatCompletionMessageParam]
|
|
r"""List of messages for the conversation"""
|
|
|
|
model: Optional[str] = None
|
|
r"""Model 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: OptionalNullable[ChatCompletionCreateParamsReasoning] = UNSET
|
|
r"""Reasoning configuration"""
|
|
|
|
response_format: Optional[ChatCompletionCreateParamsResponseFormatUnion] = None
|
|
r"""Response format configuration"""
|
|
|
|
seed: OptionalNullable[int] = UNSET
|
|
r"""Random seed for deterministic outputs"""
|
|
|
|
stop: OptionalNullable[ChatCompletionCreateParamsStop] = UNSET
|
|
r"""Stop sequences (up to 4)"""
|
|
|
|
stream: OptionalNullable[bool] = False
|
|
r"""Enable streaming response"""
|
|
|
|
stream_options: OptionalNullable[ChatCompletionCreateParamsStreamOptions] = UNSET
|
|
|
|
temperature: OptionalNullable[float] = 1
|
|
r"""Sampling temperature (0-2)"""
|
|
|
|
tool_choice: Optional[ChatCompletionToolChoiceOption] = None
|
|
r"""Tool choice configuration"""
|
|
|
|
tools: Optional[List[ChatCompletionTool]] = None
|
|
r"""Available tools for function calling"""
|
|
|
|
top_p: OptionalNullable[float] = 1
|
|
r"""Nucleus sampling parameter (0-1)"""
|
|
|
|
user: Optional[str] = None
|
|
r"""Unique user identifier"""
|
|
|
|
fallback_models: Annotated[
|
|
OptionalNullable[List[str]], pydantic.Field(alias="models")
|
|
] = UNSET
|
|
r"""Order of models to fallback to for this request"""
|
|
|
|
reasoning_effort: OptionalNullable[ChatCompletionCreateParamsReasoningEffort] = (
|
|
UNSET
|
|
)
|
|
r"""Reasoning effort"""
|
|
|
|
provider: OptionalNullable[ChatCompletionCreateParamsProvider] = UNSET
|
|
r"""When multiple model providers are available, optionally indicate your routing preference."""
|
|
|
|
plugins: Optional[List[ChatCompletionCreateParamsPluginUnion]] = None
|
|
r"""Plugins you want to enable for this request, including their settings."""
|
|
|
|
@model_serializer(mode="wrap")
|
|
def serialize_model(self, handler):
|
|
optional_fields = [
|
|
"model",
|
|
"frequency_penalty",
|
|
"logit_bias",
|
|
"logprobs",
|
|
"top_logprobs",
|
|
"max_completion_tokens",
|
|
"max_tokens",
|
|
"metadata",
|
|
"presence_penalty",
|
|
"reasoning",
|
|
"response_format",
|
|
"seed",
|
|
"stop",
|
|
"stream",
|
|
"stream_options",
|
|
"temperature",
|
|
"tool_choice",
|
|
"tools",
|
|
"top_p",
|
|
"user",
|
|
"fallback_models",
|
|
"reasoning_effort",
|
|
"provider",
|
|
"plugins",
|
|
]
|
|
nullable_fields = [
|
|
"frequency_penalty",
|
|
"logit_bias",
|
|
"logprobs",
|
|
"top_logprobs",
|
|
"max_completion_tokens",
|
|
"max_tokens",
|
|
"presence_penalty",
|
|
"reasoning",
|
|
"seed",
|
|
"stop",
|
|
"stream",
|
|
"stream_options",
|
|
"temperature",
|
|
"top_p",
|
|
"fallback_models",
|
|
"reasoning_effort",
|
|
"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
|