mirror of
https://github.com/wassname/openrouter-python-sdk-retry-errors.git
synced 2026-07-29 11:23:49 +08:00
latest updates
This commit is contained in:
@@ -3,10 +3,10 @@
|
||||
import importlib.metadata
|
||||
|
||||
__title__: str = "openrouter"
|
||||
__version__: str = "0.0.19"
|
||||
__version__: str = "0.1.1"
|
||||
__openapi_doc_version__: str = "1.0.0"
|
||||
__gen_version__: str = "2.755.9"
|
||||
__user_agent__: str = "speakeasy-sdk/python 0.0.19 2.755.9 1.0.0 openrouter"
|
||||
__gen_version__: str = "2.768.0"
|
||||
__user_agent__: str = "speakeasy-sdk/python 0.1.1 2.768.0 1.0.0 openrouter"
|
||||
|
||||
try:
|
||||
if __package__ is not None:
|
||||
|
||||
@@ -58,6 +58,7 @@ class Analytics(BaseSDK):
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -166,6 +167,7 @@ class Analytics(BaseSDK):
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ class APIKeys(BaseSDK):
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -164,6 +165,7 @@ class APIKeys(BaseSDK):
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -280,6 +282,7 @@ class APIKeys(BaseSDK):
|
||||
get_serialized_body=lambda: utils.serialize_request_body(
|
||||
request, False, False, "json", operations.CreateKeysRequest
|
||||
),
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -401,6 +404,7 @@ class APIKeys(BaseSDK):
|
||||
get_serialized_body=lambda: utils.serialize_request_body(
|
||||
request, False, False, "json", operations.CreateKeysRequest
|
||||
),
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -527,6 +531,7 @@ class APIKeys(BaseSDK):
|
||||
get_serialized_body=lambda: utils.serialize_request_body(
|
||||
request.body, False, False, "json", operations.UpdateKeysRequestBody
|
||||
),
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -658,6 +663,7 @@ class APIKeys(BaseSDK):
|
||||
get_serialized_body=lambda: utils.serialize_request_body(
|
||||
request.body, False, False, "json", operations.UpdateKeysRequestBody
|
||||
),
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -769,6 +775,7 @@ class APIKeys(BaseSDK):
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -875,6 +882,7 @@ class APIKeys(BaseSDK):
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -981,6 +989,7 @@ class APIKeys(BaseSDK):
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -1087,6 +1096,7 @@ class APIKeys(BaseSDK):
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -1188,6 +1198,7 @@ class APIKeys(BaseSDK):
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -1279,6 +1290,7 @@ class APIKeys(BaseSDK):
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ class BaseSDK:
|
||||
] = None,
|
||||
url_override: Optional[str] = None,
|
||||
http_headers: Optional[Mapping[str, str]] = None,
|
||||
allow_empty_value: Optional[List[str]] = None,
|
||||
) -> httpx.Request:
|
||||
client = self.sdk_configuration.async_client
|
||||
return self._build_request_with_client(
|
||||
@@ -80,6 +81,7 @@ class BaseSDK:
|
||||
get_serialized_body,
|
||||
url_override,
|
||||
http_headers,
|
||||
allow_empty_value,
|
||||
)
|
||||
|
||||
def _build_request(
|
||||
@@ -102,6 +104,7 @@ class BaseSDK:
|
||||
] = None,
|
||||
url_override: Optional[str] = None,
|
||||
http_headers: Optional[Mapping[str, str]] = None,
|
||||
allow_empty_value: Optional[List[str]] = None,
|
||||
) -> httpx.Request:
|
||||
client = self.sdk_configuration.client
|
||||
return self._build_request_with_client(
|
||||
@@ -122,6 +125,7 @@ class BaseSDK:
|
||||
get_serialized_body,
|
||||
url_override,
|
||||
http_headers,
|
||||
allow_empty_value,
|
||||
)
|
||||
|
||||
def _build_request_with_client(
|
||||
@@ -145,6 +149,7 @@ class BaseSDK:
|
||||
] = None,
|
||||
url_override: Optional[str] = None,
|
||||
http_headers: Optional[Mapping[str, str]] = None,
|
||||
allow_empty_value: Optional[List[str]] = None,
|
||||
) -> httpx.Request:
|
||||
query_params = {}
|
||||
|
||||
@@ -160,6 +165,7 @@ class BaseSDK:
|
||||
query_params = utils.get_query_params(
|
||||
request if request_has_query_params else None,
|
||||
_globals if request_has_query_params else None,
|
||||
allow_empty_value,
|
||||
)
|
||||
else:
|
||||
# Pick up the query parameter from the override so they can be
|
||||
|
||||
@@ -61,6 +61,7 @@ class Chat(BaseSDK):
|
||||
] = None,
|
||||
top_p: OptionalNullable[float] = UNSET,
|
||||
user: Optional[str] = None,
|
||||
debug: Optional[Union[components.Debug, components.DebugTypedDict]] = None,
|
||||
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
||||
server_url: Optional[str] = None,
|
||||
timeout_ms: Optional[int] = None,
|
||||
@@ -92,6 +93,7 @@ class Chat(BaseSDK):
|
||||
:param tools:
|
||||
:param top_p:
|
||||
:param user:
|
||||
:param debug:
|
||||
:param retries: Override the default retry configuration for this method
|
||||
:param server_url: Override the default server URL for this method
|
||||
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
||||
@@ -144,6 +146,7 @@ class Chat(BaseSDK):
|
||||
] = None,
|
||||
top_p: OptionalNullable[float] = UNSET,
|
||||
user: Optional[str] = None,
|
||||
debug: Optional[Union[components.Debug, components.DebugTypedDict]] = None,
|
||||
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
||||
server_url: Optional[str] = None,
|
||||
timeout_ms: Optional[int] = None,
|
||||
@@ -175,6 +178,7 @@ class Chat(BaseSDK):
|
||||
:param tools:
|
||||
:param top_p:
|
||||
:param user:
|
||||
:param debug:
|
||||
:param retries: Override the default retry configuration for this method
|
||||
:param server_url: Override the default server URL for this method
|
||||
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
||||
@@ -226,6 +230,7 @@ class Chat(BaseSDK):
|
||||
] = None,
|
||||
top_p: OptionalNullable[float] = UNSET,
|
||||
user: Optional[str] = None,
|
||||
debug: Optional[Union[components.Debug, components.DebugTypedDict]] = None,
|
||||
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
||||
server_url: Optional[str] = None,
|
||||
timeout_ms: Optional[int] = None,
|
||||
@@ -257,6 +262,7 @@ class Chat(BaseSDK):
|
||||
:param tools:
|
||||
:param top_p:
|
||||
:param user:
|
||||
:param debug:
|
||||
:param retries: Override the default retry configuration for this method
|
||||
:param server_url: Override the default server URL for this method
|
||||
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
||||
@@ -305,6 +311,7 @@ class Chat(BaseSDK):
|
||||
),
|
||||
top_p=top_p,
|
||||
user=user,
|
||||
debug=utils.get_pydantic_model(debug, Optional[components.Debug]),
|
||||
)
|
||||
|
||||
req = self._build_request(
|
||||
@@ -323,6 +330,7 @@ class Chat(BaseSDK):
|
||||
get_serialized_body=lambda: utils.serialize_request_body(
|
||||
request, False, False, "json", components.ChatGenerationParams
|
||||
),
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -438,6 +446,7 @@ class Chat(BaseSDK):
|
||||
] = None,
|
||||
top_p: OptionalNullable[float] = UNSET,
|
||||
user: Optional[str] = None,
|
||||
debug: Optional[Union[components.Debug, components.DebugTypedDict]] = None,
|
||||
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
||||
server_url: Optional[str] = None,
|
||||
timeout_ms: Optional[int] = None,
|
||||
@@ -469,6 +478,7 @@ class Chat(BaseSDK):
|
||||
:param tools:
|
||||
:param top_p:
|
||||
:param user:
|
||||
:param debug:
|
||||
:param retries: Override the default retry configuration for this method
|
||||
:param server_url: Override the default server URL for this method
|
||||
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
||||
@@ -521,6 +531,7 @@ class Chat(BaseSDK):
|
||||
] = None,
|
||||
top_p: OptionalNullable[float] = UNSET,
|
||||
user: Optional[str] = None,
|
||||
debug: Optional[Union[components.Debug, components.DebugTypedDict]] = None,
|
||||
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
||||
server_url: Optional[str] = None,
|
||||
timeout_ms: Optional[int] = None,
|
||||
@@ -552,6 +563,7 @@ class Chat(BaseSDK):
|
||||
:param tools:
|
||||
:param top_p:
|
||||
:param user:
|
||||
:param debug:
|
||||
:param retries: Override the default retry configuration for this method
|
||||
:param server_url: Override the default server URL for this method
|
||||
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
||||
@@ -603,6 +615,7 @@ class Chat(BaseSDK):
|
||||
] = None,
|
||||
top_p: OptionalNullable[float] = UNSET,
|
||||
user: Optional[str] = None,
|
||||
debug: Optional[Union[components.Debug, components.DebugTypedDict]] = None,
|
||||
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
||||
server_url: Optional[str] = None,
|
||||
timeout_ms: Optional[int] = None,
|
||||
@@ -634,6 +647,7 @@ class Chat(BaseSDK):
|
||||
:param tools:
|
||||
:param top_p:
|
||||
:param user:
|
||||
:param debug:
|
||||
:param retries: Override the default retry configuration for this method
|
||||
:param server_url: Override the default server URL for this method
|
||||
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
||||
@@ -682,6 +696,7 @@ class Chat(BaseSDK):
|
||||
),
|
||||
top_p=top_p,
|
||||
user=user,
|
||||
debug=utils.get_pydantic_model(debug, Optional[components.Debug]),
|
||||
)
|
||||
|
||||
req = self._build_request_async(
|
||||
@@ -700,6 +715,7 @@ class Chat(BaseSDK):
|
||||
get_serialized_body=lambda: utils.serialize_request_body(
|
||||
request, False, False, "json", components.ChatGenerationParams
|
||||
),
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
|
||||
@@ -136,6 +136,7 @@ class Completions(BaseSDK):
|
||||
get_serialized_body=lambda: utils.serialize_request_body(
|
||||
request, False, False, "json", components.CompletionCreateParams
|
||||
),
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -310,6 +311,7 @@ class Completions(BaseSDK):
|
||||
get_serialized_body=lambda: utils.serialize_request_body(
|
||||
request, False, False, "json", components.CompletionCreateParams
|
||||
),
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ if TYPE_CHECKING:
|
||||
BadRequestResponseErrorData,
|
||||
BadRequestResponseErrorDataTypedDict,
|
||||
)
|
||||
from .chatcompletionfinishreason import ChatCompletionFinishReason
|
||||
from .chaterror import ChatErrorError, ChatErrorErrorTypedDict, Code, CodeTypedDict
|
||||
from .chatgenerationparams import (
|
||||
ChatGenerationParams,
|
||||
@@ -35,6 +36,8 @@ if TYPE_CHECKING:
|
||||
ChatGenerationParamsStop,
|
||||
ChatGenerationParamsStopTypedDict,
|
||||
ChatGenerationParamsTypedDict,
|
||||
Debug,
|
||||
DebugTypedDict,
|
||||
Effort,
|
||||
Reasoning,
|
||||
ReasoningTypedDict,
|
||||
@@ -53,11 +56,15 @@ if TYPE_CHECKING:
|
||||
)
|
||||
from .chatmessagecontentitemaudio import (
|
||||
ChatMessageContentItemAudio,
|
||||
ChatMessageContentItemAudioFormat,
|
||||
ChatMessageContentItemAudioInputAudio,
|
||||
ChatMessageContentItemAudioInputAudioTypedDict,
|
||||
ChatMessageContentItemAudioTypedDict,
|
||||
)
|
||||
from .chatmessagecontentitemcachecontrol import (
|
||||
ChatMessageContentItemCacheControl,
|
||||
ChatMessageContentItemCacheControlTypedDict,
|
||||
TTL,
|
||||
)
|
||||
from .chatmessagecontentitemimage import (
|
||||
ChatMessageContentItemImage,
|
||||
ChatMessageContentItemImageDetail,
|
||||
@@ -98,13 +105,8 @@ if TYPE_CHECKING:
|
||||
ChatMessageToolCallTypedDict,
|
||||
)
|
||||
from .chatresponse import ChatResponse, ChatResponseTypedDict
|
||||
from .chatresponsechoice import (
|
||||
ChatCompletionFinishReason,
|
||||
ChatResponseChoice,
|
||||
ChatResponseChoiceTypedDict,
|
||||
ChatStreamingChoice,
|
||||
ChatStreamingChoiceTypedDict,
|
||||
)
|
||||
from .chatresponsechoice import ChatResponseChoice, ChatResponseChoiceTypedDict
|
||||
from .chatstreamingchoice import ChatStreamingChoice, ChatStreamingChoiceTypedDict
|
||||
from .chatstreamingmessagechunk import (
|
||||
ChatStreamingMessageChunk,
|
||||
ChatStreamingMessageChunkRole,
|
||||
@@ -422,6 +424,7 @@ if TYPE_CHECKING:
|
||||
Engine,
|
||||
IDFileParser,
|
||||
IDModeration,
|
||||
IDResponseHealing,
|
||||
IDWeb,
|
||||
Ignore,
|
||||
IgnoreTypedDict,
|
||||
@@ -446,6 +449,8 @@ if TYPE_CHECKING:
|
||||
PluginFileParserTypedDict,
|
||||
PluginModeration,
|
||||
PluginModerationTypedDict,
|
||||
PluginResponseHealing,
|
||||
PluginResponseHealingTypedDict,
|
||||
PluginTypedDict,
|
||||
PluginWeb,
|
||||
PluginWebTypedDict,
|
||||
@@ -820,10 +825,11 @@ __all__ = [
|
||||
"ChatGenerationTokenUsageTypedDict",
|
||||
"ChatMessageContentItem",
|
||||
"ChatMessageContentItemAudio",
|
||||
"ChatMessageContentItemAudioFormat",
|
||||
"ChatMessageContentItemAudioInputAudio",
|
||||
"ChatMessageContentItemAudioInputAudioTypedDict",
|
||||
"ChatMessageContentItemAudioTypedDict",
|
||||
"ChatMessageContentItemCacheControl",
|
||||
"ChatMessageContentItemCacheControlTypedDict",
|
||||
"ChatMessageContentItemImage",
|
||||
"ChatMessageContentItemImageDetail",
|
||||
"ChatMessageContentItemImageTypedDict",
|
||||
@@ -896,6 +902,8 @@ __all__ = [
|
||||
"CreateChargeRequest",
|
||||
"CreateChargeRequestTypedDict",
|
||||
"DataCollection",
|
||||
"Debug",
|
||||
"DebugTypedDict",
|
||||
"DefaultParameters",
|
||||
"DefaultParametersTypedDict",
|
||||
"EdgeNetworkTimeoutResponseErrorData",
|
||||
@@ -913,6 +921,7 @@ __all__ = [
|
||||
"ForbiddenResponseErrorDataTypedDict",
|
||||
"IDFileParser",
|
||||
"IDModeration",
|
||||
"IDResponseHealing",
|
||||
"IDWeb",
|
||||
"Ignore",
|
||||
"IgnoreTypedDict",
|
||||
@@ -1206,6 +1215,8 @@ __all__ = [
|
||||
"PluginFileParserTypedDict",
|
||||
"PluginModeration",
|
||||
"PluginModerationTypedDict",
|
||||
"PluginResponseHealing",
|
||||
"PluginResponseHealingTypedDict",
|
||||
"PluginTypedDict",
|
||||
"PluginWeb",
|
||||
"PluginWebTypedDict",
|
||||
@@ -1331,6 +1342,7 @@ __all__ = [
|
||||
"SystemMessageContent",
|
||||
"SystemMessageContentTypedDict",
|
||||
"SystemMessageTypedDict",
|
||||
"TTL",
|
||||
"Tokenizer",
|
||||
"TooManyRequestsResponseErrorData",
|
||||
"TooManyRequestsResponseErrorDataTypedDict",
|
||||
@@ -1401,6 +1413,7 @@ _dynamic_imports: dict[str, str] = {
|
||||
"BadGatewayResponseErrorDataTypedDict": ".badgatewayresponseerrordata",
|
||||
"BadRequestResponseErrorData": ".badrequestresponseerrordata",
|
||||
"BadRequestResponseErrorDataTypedDict": ".badrequestresponseerrordata",
|
||||
"ChatCompletionFinishReason": ".chatcompletionfinishreason",
|
||||
"ChatErrorError": ".chaterror",
|
||||
"ChatErrorErrorTypedDict": ".chaterror",
|
||||
"Code": ".chaterror",
|
||||
@@ -1417,6 +1430,8 @@ _dynamic_imports: dict[str, str] = {
|
||||
"ChatGenerationParamsStop": ".chatgenerationparams",
|
||||
"ChatGenerationParamsStopTypedDict": ".chatgenerationparams",
|
||||
"ChatGenerationParamsTypedDict": ".chatgenerationparams",
|
||||
"Debug": ".chatgenerationparams",
|
||||
"DebugTypedDict": ".chatgenerationparams",
|
||||
"Effort": ".chatgenerationparams",
|
||||
"Reasoning": ".chatgenerationparams",
|
||||
"ReasoningTypedDict": ".chatgenerationparams",
|
||||
@@ -1429,10 +1444,12 @@ _dynamic_imports: dict[str, str] = {
|
||||
"ChatMessageContentItem": ".chatmessagecontentitem",
|
||||
"ChatMessageContentItemTypedDict": ".chatmessagecontentitem",
|
||||
"ChatMessageContentItemAudio": ".chatmessagecontentitemaudio",
|
||||
"ChatMessageContentItemAudioFormat": ".chatmessagecontentitemaudio",
|
||||
"ChatMessageContentItemAudioInputAudio": ".chatmessagecontentitemaudio",
|
||||
"ChatMessageContentItemAudioInputAudioTypedDict": ".chatmessagecontentitemaudio",
|
||||
"ChatMessageContentItemAudioTypedDict": ".chatmessagecontentitemaudio",
|
||||
"ChatMessageContentItemCacheControl": ".chatmessagecontentitemcachecontrol",
|
||||
"ChatMessageContentItemCacheControlTypedDict": ".chatmessagecontentitemcachecontrol",
|
||||
"TTL": ".chatmessagecontentitemcachecontrol",
|
||||
"ChatMessageContentItemImage": ".chatmessagecontentitemimage",
|
||||
"ChatMessageContentItemImageDetail": ".chatmessagecontentitemimage",
|
||||
"ChatMessageContentItemImageTypedDict": ".chatmessagecontentitemimage",
|
||||
@@ -1462,11 +1479,10 @@ _dynamic_imports: dict[str, str] = {
|
||||
"ChatMessageToolCallTypedDict": ".chatmessagetoolcall",
|
||||
"ChatResponse": ".chatresponse",
|
||||
"ChatResponseTypedDict": ".chatresponse",
|
||||
"ChatCompletionFinishReason": ".chatresponsechoice",
|
||||
"ChatResponseChoice": ".chatresponsechoice",
|
||||
"ChatResponseChoiceTypedDict": ".chatresponsechoice",
|
||||
"ChatStreamingChoice": ".chatresponsechoice",
|
||||
"ChatStreamingChoiceTypedDict": ".chatresponsechoice",
|
||||
"ChatStreamingChoice": ".chatstreamingchoice",
|
||||
"ChatStreamingChoiceTypedDict": ".chatstreamingchoice",
|
||||
"ChatStreamingMessageChunk": ".chatstreamingmessagechunk",
|
||||
"ChatStreamingMessageChunkRole": ".chatstreamingmessagechunk",
|
||||
"ChatStreamingMessageChunkTypedDict": ".chatstreamingmessagechunk",
|
||||
@@ -1713,6 +1729,7 @@ _dynamic_imports: dict[str, str] = {
|
||||
"Engine": ".openresponsesrequest",
|
||||
"IDFileParser": ".openresponsesrequest",
|
||||
"IDModeration": ".openresponsesrequest",
|
||||
"IDResponseHealing": ".openresponsesrequest",
|
||||
"IDWeb": ".openresponsesrequest",
|
||||
"Ignore": ".openresponsesrequest",
|
||||
"IgnoreTypedDict": ".openresponsesrequest",
|
||||
@@ -1737,6 +1754,8 @@ _dynamic_imports: dict[str, str] = {
|
||||
"PluginFileParserTypedDict": ".openresponsesrequest",
|
||||
"PluginModeration": ".openresponsesrequest",
|
||||
"PluginModerationTypedDict": ".openresponsesrequest",
|
||||
"PluginResponseHealing": ".openresponsesrequest",
|
||||
"PluginResponseHealingTypedDict": ".openresponsesrequest",
|
||||
"PluginTypedDict": ".openresponsesrequest",
|
||||
"PluginWeb": ".openresponsesrequest",
|
||||
"PluginWebTypedDict": ".openresponsesrequest",
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
||||
|
||||
from __future__ import annotations
|
||||
from openrouter.types import UnrecognizedStr
|
||||
from typing import Literal, Union
|
||||
|
||||
|
||||
ChatCompletionFinishReason = Union[
|
||||
Literal[
|
||||
"tool_calls",
|
||||
"stop",
|
||||
"length",
|
||||
"content_filter",
|
||||
"error",
|
||||
],
|
||||
UnrecognizedStr,
|
||||
]
|
||||
@@ -21,9 +21,9 @@ from openrouter.types import (
|
||||
UNSET_SENTINEL,
|
||||
UnrecognizedStr,
|
||||
)
|
||||
from openrouter.utils import validate_const, validate_open_enum
|
||||
from openrouter.utils import get_discriminator, validate_const, validate_open_enum
|
||||
import pydantic
|
||||
from pydantic import model_serializer
|
||||
from pydantic import Discriminator, Tag, model_serializer
|
||||
from pydantic.functional_validators import AfterValidator, PlainValidator
|
||||
from typing import Any, Dict, List, Literal, Optional, Union
|
||||
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict
|
||||
@@ -134,16 +134,16 @@ ChatGenerationParamsResponseFormatUnionTypedDict = TypeAliasType(
|
||||
)
|
||||
|
||||
|
||||
ChatGenerationParamsResponseFormatUnion = TypeAliasType(
|
||||
"ChatGenerationParamsResponseFormatUnion",
|
||||
ChatGenerationParamsResponseFormatUnion = Annotated[
|
||||
Union[
|
||||
ChatGenerationParamsResponseFormatText,
|
||||
ChatGenerationParamsResponseFormatJSONObject,
|
||||
ChatGenerationParamsResponseFormatPython,
|
||||
ResponseFormatJSONSchema,
|
||||
ResponseFormatTextGrammar,
|
||||
Annotated[ChatGenerationParamsResponseFormatText, Tag("text")],
|
||||
Annotated[ChatGenerationParamsResponseFormatJSONObject, Tag("json_object")],
|
||||
Annotated[ResponseFormatJSONSchema, Tag("json_schema")],
|
||||
Annotated[ResponseFormatTextGrammar, Tag("grammar")],
|
||||
Annotated[ChatGenerationParamsResponseFormatPython, Tag("python")],
|
||||
],
|
||||
)
|
||||
Discriminator(lambda m: get_discriminator(m, "type", "type")),
|
||||
]
|
||||
|
||||
|
||||
ChatGenerationParamsStopTypedDict = TypeAliasType(
|
||||
@@ -156,6 +156,14 @@ ChatGenerationParamsStop = TypeAliasType(
|
||||
)
|
||||
|
||||
|
||||
class DebugTypedDict(TypedDict):
|
||||
echo_upstream_body: NotRequired[bool]
|
||||
|
||||
|
||||
class Debug(BaseModel):
|
||||
echo_upstream_body: Optional[bool] = None
|
||||
|
||||
|
||||
class ChatGenerationParamsTypedDict(TypedDict):
|
||||
messages: List[MessageTypedDict]
|
||||
model: NotRequired[str]
|
||||
@@ -179,6 +187,7 @@ class ChatGenerationParamsTypedDict(TypedDict):
|
||||
tools: NotRequired[List[ToolDefinitionJSONTypedDict]]
|
||||
top_p: NotRequired[Nullable[float]]
|
||||
user: NotRequired[str]
|
||||
debug: NotRequired[DebugTypedDict]
|
||||
|
||||
|
||||
class ChatGenerationParams(BaseModel):
|
||||
@@ -226,6 +235,8 @@ class ChatGenerationParams(BaseModel):
|
||||
|
||||
user: Optional[str] = None
|
||||
|
||||
debug: Optional[Debug] = None
|
||||
|
||||
@model_serializer(mode="wrap")
|
||||
def serialize_model(self, handler):
|
||||
optional_fields = [
|
||||
@@ -250,6 +261,7 @@ class ChatGenerationParams(BaseModel):
|
||||
"tools",
|
||||
"top_p",
|
||||
"user",
|
||||
"debug",
|
||||
]
|
||||
nullable_fields = [
|
||||
"frequency_penalty",
|
||||
|
||||
@@ -26,9 +26,9 @@ from typing_extensions import Annotated, TypeAliasType
|
||||
ChatMessageContentItemTypedDict = TypeAliasType(
|
||||
"ChatMessageContentItemTypedDict",
|
||||
Union[
|
||||
ChatMessageContentItemTextTypedDict,
|
||||
ChatMessageContentItemImageTypedDict,
|
||||
ChatMessageContentItemAudioTypedDict,
|
||||
ChatMessageContentItemTextTypedDict,
|
||||
ChatMessageContentItemVideoTypedDict,
|
||||
],
|
||||
)
|
||||
|
||||
@@ -1,42 +1,23 @@
|
||||
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
||||
|
||||
from __future__ import annotations
|
||||
from openrouter.types import BaseModel, UnrecognizedStr
|
||||
from openrouter.utils import validate_const, validate_open_enum
|
||||
from openrouter.types import BaseModel
|
||||
from openrouter.utils import validate_const
|
||||
import pydantic
|
||||
from pydantic.functional_validators import AfterValidator, PlainValidator
|
||||
from typing import Literal, Union
|
||||
from pydantic.functional_validators import AfterValidator
|
||||
from typing import Literal
|
||||
from typing_extensions import Annotated, TypedDict
|
||||
|
||||
|
||||
ChatMessageContentItemAudioFormat = Union[
|
||||
Literal[
|
||||
"wav",
|
||||
"mp3",
|
||||
"flac",
|
||||
"m4a",
|
||||
"ogg",
|
||||
"pcm16",
|
||||
"pcm24",
|
||||
],
|
||||
UnrecognizedStr,
|
||||
]
|
||||
|
||||
|
||||
class ChatMessageContentItemAudioInputAudioTypedDict(TypedDict):
|
||||
data: str
|
||||
format_: ChatMessageContentItemAudioFormat
|
||||
format_: str
|
||||
|
||||
|
||||
class ChatMessageContentItemAudioInputAudio(BaseModel):
|
||||
data: str
|
||||
|
||||
format_: Annotated[
|
||||
Annotated[
|
||||
ChatMessageContentItemAudioFormat, PlainValidator(validate_open_enum(False))
|
||||
],
|
||||
pydantic.Field(alias="format"),
|
||||
]
|
||||
format_: Annotated[str, pydantic.Field(alias="format")]
|
||||
|
||||
|
||||
class ChatMessageContentItemAudioTypedDict(TypedDict):
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
||||
|
||||
from __future__ import annotations
|
||||
from openrouter.types import BaseModel, UnrecognizedStr
|
||||
from openrouter.utils import validate_const, validate_open_enum
|
||||
import pydantic
|
||||
from pydantic.functional_validators import AfterValidator, PlainValidator
|
||||
from typing import Literal, Optional, Union
|
||||
from typing_extensions import Annotated, NotRequired, TypedDict
|
||||
|
||||
|
||||
TTL = Union[
|
||||
Literal[
|
||||
"5m",
|
||||
"1h",
|
||||
],
|
||||
UnrecognizedStr,
|
||||
]
|
||||
|
||||
|
||||
class ChatMessageContentItemCacheControlTypedDict(TypedDict):
|
||||
type: Literal["ephemeral"]
|
||||
ttl: NotRequired[TTL]
|
||||
|
||||
|
||||
class ChatMessageContentItemCacheControl(BaseModel):
|
||||
TYPE: Annotated[
|
||||
Annotated[Literal["ephemeral"], AfterValidator(validate_const("ephemeral"))],
|
||||
pydantic.Field(alias="type"),
|
||||
] = "ephemeral"
|
||||
|
||||
ttl: Annotated[Optional[TTL], PlainValidator(validate_open_enum(False))] = None
|
||||
@@ -1,17 +1,22 @@
|
||||
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
||||
|
||||
from __future__ import annotations
|
||||
from .chatmessagecontentitemcachecontrol import (
|
||||
ChatMessageContentItemCacheControl,
|
||||
ChatMessageContentItemCacheControlTypedDict,
|
||||
)
|
||||
from openrouter.types import BaseModel
|
||||
from openrouter.utils import validate_const
|
||||
import pydantic
|
||||
from pydantic.functional_validators import AfterValidator
|
||||
from typing import Literal
|
||||
from typing_extensions import Annotated, TypedDict
|
||||
from typing import Literal, Optional
|
||||
from typing_extensions import Annotated, NotRequired, TypedDict
|
||||
|
||||
|
||||
class ChatMessageContentItemTextTypedDict(TypedDict):
|
||||
text: str
|
||||
type: Literal["text"]
|
||||
cache_control: NotRequired[ChatMessageContentItemCacheControlTypedDict]
|
||||
|
||||
|
||||
class ChatMessageContentItemText(BaseModel):
|
||||
@@ -21,3 +26,5 @@ class ChatMessageContentItemText(BaseModel):
|
||||
Annotated[Literal["text"], AfterValidator(validate_const("text"))],
|
||||
pydantic.Field(alias="type"),
|
||||
] = "text"
|
||||
|
||||
cache_control: Optional[ChatMessageContentItemCacheControl] = None
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
from __future__ import annotations
|
||||
from openrouter.types import BaseModel
|
||||
from openrouter.utils import validate_const
|
||||
from openrouter.utils import get_discriminator, validate_const
|
||||
import pydantic
|
||||
from pydantic import Discriminator, Tag
|
||||
from pydantic.functional_validators import AfterValidator
|
||||
from typing import Literal, Union
|
||||
from typing_extensions import Annotated, TypeAliasType, TypedDict
|
||||
@@ -64,7 +65,10 @@ ChatMessageContentItemVideoTypedDict = TypeAliasType(
|
||||
)
|
||||
|
||||
|
||||
ChatMessageContentItemVideo = TypeAliasType(
|
||||
"ChatMessageContentItemVideo",
|
||||
Union[ChatMessageContentItemVideoInputVideo, ChatMessageContentItemVideoVideoURL],
|
||||
)
|
||||
ChatMessageContentItemVideo = Annotated[
|
||||
Union[
|
||||
Annotated[ChatMessageContentItemVideoInputVideo, Tag("input_video")],
|
||||
Annotated[ChatMessageContentItemVideoVideoURL, Tag("video_url")],
|
||||
],
|
||||
Discriminator(lambda m: get_discriminator(m, "type", "type")),
|
||||
]
|
||||
|
||||
@@ -2,41 +2,24 @@
|
||||
|
||||
from __future__ import annotations
|
||||
from .assistantmessage import AssistantMessage, AssistantMessageTypedDict
|
||||
from .chatcompletionfinishreason import ChatCompletionFinishReason
|
||||
from .chatmessagetokenlogprobs import (
|
||||
ChatMessageTokenLogprobs,
|
||||
ChatMessageTokenLogprobsTypedDict,
|
||||
)
|
||||
from .chatstreamingmessagechunk import (
|
||||
ChatStreamingMessageChunk,
|
||||
ChatStreamingMessageChunkTypedDict,
|
||||
)
|
||||
from openrouter.types import (
|
||||
BaseModel,
|
||||
Nullable,
|
||||
OptionalNullable,
|
||||
UNSET,
|
||||
UNSET_SENTINEL,
|
||||
UnrecognizedStr,
|
||||
)
|
||||
from openrouter.utils import validate_open_enum
|
||||
from pydantic import model_serializer
|
||||
from pydantic.functional_validators import PlainValidator
|
||||
from typing import Literal, Union
|
||||
from typing_extensions import Annotated, NotRequired, TypedDict
|
||||
|
||||
|
||||
ChatCompletionFinishReason = Union[
|
||||
Literal[
|
||||
"tool_calls",
|
||||
"stop",
|
||||
"length",
|
||||
"content_filter",
|
||||
"error",
|
||||
],
|
||||
UnrecognizedStr,
|
||||
]
|
||||
|
||||
|
||||
class ChatResponseChoiceTypedDict(TypedDict):
|
||||
finish_reason: Nullable[ChatCompletionFinishReason]
|
||||
index: float
|
||||
@@ -84,52 +67,3 @@ class ChatResponseChoice(BaseModel):
|
||||
m[k] = val
|
||||
|
||||
return m
|
||||
|
||||
|
||||
class ChatStreamingChoiceTypedDict(TypedDict):
|
||||
delta: ChatStreamingMessageChunkTypedDict
|
||||
finish_reason: Nullable[ChatCompletionFinishReason]
|
||||
index: float
|
||||
logprobs: NotRequired[Nullable[ChatMessageTokenLogprobsTypedDict]]
|
||||
|
||||
|
||||
class ChatStreamingChoice(BaseModel):
|
||||
delta: ChatStreamingMessageChunk
|
||||
|
||||
finish_reason: Annotated[
|
||||
Nullable[ChatCompletionFinishReason], PlainValidator(validate_open_enum(False))
|
||||
]
|
||||
|
||||
index: float
|
||||
|
||||
logprobs: OptionalNullable[ChatMessageTokenLogprobs] = UNSET
|
||||
|
||||
@model_serializer(mode="wrap")
|
||||
def serialize_model(self, handler):
|
||||
optional_fields = ["logprobs"]
|
||||
nullable_fields = ["finish_reason", "logprobs"]
|
||||
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
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
||||
|
||||
from __future__ import annotations
|
||||
from .chatcompletionfinishreason import ChatCompletionFinishReason
|
||||
from .chatmessagetokenlogprobs import (
|
||||
ChatMessageTokenLogprobs,
|
||||
ChatMessageTokenLogprobsTypedDict,
|
||||
)
|
||||
from .chatstreamingmessagechunk import (
|
||||
ChatStreamingMessageChunk,
|
||||
ChatStreamingMessageChunkTypedDict,
|
||||
)
|
||||
from openrouter.types import (
|
||||
BaseModel,
|
||||
Nullable,
|
||||
OptionalNullable,
|
||||
UNSET,
|
||||
UNSET_SENTINEL,
|
||||
)
|
||||
from openrouter.utils import validate_open_enum
|
||||
from pydantic import model_serializer
|
||||
from pydantic.functional_validators import PlainValidator
|
||||
from typing_extensions import Annotated, NotRequired, TypedDict
|
||||
|
||||
|
||||
class ChatStreamingChoiceTypedDict(TypedDict):
|
||||
delta: ChatStreamingMessageChunkTypedDict
|
||||
finish_reason: Nullable[ChatCompletionFinishReason]
|
||||
index: float
|
||||
logprobs: NotRequired[Nullable[ChatMessageTokenLogprobsTypedDict]]
|
||||
|
||||
|
||||
class ChatStreamingChoice(BaseModel):
|
||||
delta: ChatStreamingMessageChunk
|
||||
|
||||
finish_reason: Annotated[
|
||||
Nullable[ChatCompletionFinishReason], PlainValidator(validate_open_enum(False))
|
||||
]
|
||||
|
||||
index: float
|
||||
|
||||
logprobs: OptionalNullable[ChatMessageTokenLogprobs] = UNSET
|
||||
|
||||
@model_serializer(mode="wrap")
|
||||
def serialize_model(self, handler):
|
||||
optional_fields = ["logprobs"]
|
||||
nullable_fields = ["finish_reason", "logprobs"]
|
||||
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
|
||||
@@ -5,7 +5,7 @@ from .chatgenerationtokenusage import (
|
||||
ChatGenerationTokenUsage,
|
||||
ChatGenerationTokenUsageTypedDict,
|
||||
)
|
||||
from .chatresponsechoice import ChatStreamingChoice, ChatStreamingChoiceTypedDict
|
||||
from .chatstreamingchoice import ChatStreamingChoice, ChatStreamingChoiceTypedDict
|
||||
from openrouter.types import (
|
||||
BaseModel,
|
||||
Nullable,
|
||||
|
||||
@@ -2,12 +2,19 @@
|
||||
|
||||
from __future__ import annotations
|
||||
from .completionlogprobs import CompletionLogprobs, CompletionLogprobsTypedDict
|
||||
from openrouter.types import BaseModel, Nullable, UNSET_SENTINEL, UnrecognizedStr
|
||||
from openrouter.types import (
|
||||
BaseModel,
|
||||
Nullable,
|
||||
OptionalNullable,
|
||||
UNSET,
|
||||
UNSET_SENTINEL,
|
||||
UnrecognizedStr,
|
||||
)
|
||||
from openrouter.utils import validate_open_enum
|
||||
from pydantic import model_serializer
|
||||
from pydantic.functional_validators import PlainValidator
|
||||
from typing import Literal, Union
|
||||
from typing_extensions import Annotated, TypedDict
|
||||
from typing import Literal, Optional, Union
|
||||
from typing_extensions import Annotated, NotRequired, TypedDict
|
||||
|
||||
|
||||
CompletionFinishReason = Union[
|
||||
@@ -25,6 +32,8 @@ class CompletionChoiceTypedDict(TypedDict):
|
||||
index: float
|
||||
logprobs: Nullable[CompletionLogprobsTypedDict]
|
||||
finish_reason: Nullable[CompletionFinishReason]
|
||||
native_finish_reason: NotRequired[str]
|
||||
reasoning: NotRequired[Nullable[str]]
|
||||
|
||||
|
||||
class CompletionChoice(BaseModel):
|
||||
@@ -38,10 +47,14 @@ class CompletionChoice(BaseModel):
|
||||
Nullable[CompletionFinishReason], PlainValidator(validate_open_enum(False))
|
||||
]
|
||||
|
||||
native_finish_reason: Optional[str] = None
|
||||
|
||||
reasoning: OptionalNullable[str] = UNSET
|
||||
|
||||
@model_serializer(mode="wrap")
|
||||
def serialize_model(self, handler):
|
||||
optional_fields = []
|
||||
nullable_fields = ["logprobs", "finish_reason"]
|
||||
optional_fields = ["native_finish_reason", "reasoning"]
|
||||
nullable_fields = ["logprobs", "finish_reason", "reasoning"]
|
||||
null_default_fields = []
|
||||
|
||||
serialized = handler(self)
|
||||
|
||||
@@ -16,9 +16,9 @@ from openrouter.types import (
|
||||
UNSET,
|
||||
UNSET_SENTINEL,
|
||||
)
|
||||
from openrouter.utils import validate_const
|
||||
from openrouter.utils import get_discriminator, validate_const
|
||||
import pydantic
|
||||
from pydantic import model_serializer
|
||||
from pydantic import Discriminator, Tag, model_serializer
|
||||
from pydantic.functional_validators import AfterValidator
|
||||
from typing import Dict, List, Literal, Optional, Union
|
||||
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict
|
||||
@@ -127,16 +127,16 @@ CompletionCreateParamsResponseFormatUnionTypedDict = TypeAliasType(
|
||||
)
|
||||
|
||||
|
||||
CompletionCreateParamsResponseFormatUnion = TypeAliasType(
|
||||
"CompletionCreateParamsResponseFormatUnion",
|
||||
CompletionCreateParamsResponseFormatUnion = Annotated[
|
||||
Union[
|
||||
CompletionCreateParamsResponseFormatText,
|
||||
CompletionCreateParamsResponseFormatJSONObject,
|
||||
CompletionCreateParamsResponseFormatPython,
|
||||
ResponseFormatJSONSchema,
|
||||
ResponseFormatTextGrammar,
|
||||
Annotated[CompletionCreateParamsResponseFormatText, Tag("text")],
|
||||
Annotated[CompletionCreateParamsResponseFormatJSONObject, Tag("json_object")],
|
||||
Annotated[ResponseFormatJSONSchema, Tag("json_schema")],
|
||||
Annotated[ResponseFormatTextGrammar, Tag("grammar")],
|
||||
Annotated[CompletionCreateParamsResponseFormatPython, Tag("python")],
|
||||
],
|
||||
)
|
||||
Discriminator(lambda m: get_discriminator(m, "type", "type")),
|
||||
]
|
||||
|
||||
|
||||
class CompletionCreateParamsTypedDict(TypedDict):
|
||||
|
||||
@@ -17,6 +17,7 @@ class CompletionResponseTypedDict(TypedDict):
|
||||
model: str
|
||||
choices: List[CompletionChoiceTypedDict]
|
||||
object: Literal["text_completion"]
|
||||
provider: NotRequired[str]
|
||||
system_fingerprint: NotRequired[str]
|
||||
usage: NotRequired[CompletionUsageTypedDict]
|
||||
|
||||
@@ -38,6 +39,8 @@ class CompletionResponse(BaseModel):
|
||||
pydantic.Field(alias="object"),
|
||||
] = "text_completion"
|
||||
|
||||
provider: Optional[str] = None
|
||||
|
||||
system_fingerprint: Optional[str] = None
|
||||
|
||||
usage: Optional[CompletionUsage] = None
|
||||
|
||||
@@ -10,8 +10,9 @@ from .systemmessage import SystemMessage, SystemMessageTypedDict
|
||||
from .toolresponsemessage import ToolResponseMessage, ToolResponseMessageTypedDict
|
||||
from .usermessage import UserMessage, UserMessageTypedDict
|
||||
from openrouter.types import BaseModel
|
||||
from openrouter.utils import validate_const
|
||||
from openrouter.utils import get_discriminator, validate_const
|
||||
import pydantic
|
||||
from pydantic import Discriminator, Tag
|
||||
from pydantic.functional_validators import AfterValidator
|
||||
from typing import List, Literal, Optional, Union
|
||||
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict
|
||||
@@ -56,13 +57,13 @@ MessageTypedDict = TypeAliasType(
|
||||
)
|
||||
|
||||
|
||||
Message = TypeAliasType(
|
||||
"Message",
|
||||
Message = Annotated[
|
||||
Union[
|
||||
SystemMessage,
|
||||
UserMessage,
|
||||
MessageDeveloper,
|
||||
ToolResponseMessage,
|
||||
AssistantMessage,
|
||||
Annotated[SystemMessage, Tag("system")],
|
||||
Annotated[UserMessage, Tag("user")],
|
||||
Annotated[MessageDeveloper, Tag("developer")],
|
||||
Annotated[AssistantMessage, Tag("assistant")],
|
||||
Annotated[ToolResponseMessage, Tag("tool")],
|
||||
],
|
||||
)
|
||||
Discriminator(lambda m: get_discriminator(m, "role", "role")),
|
||||
]
|
||||
|
||||
@@ -4,8 +4,10 @@ from __future__ import annotations
|
||||
from .filecitation import FileCitation, FileCitationTypedDict
|
||||
from .filepath import FilePath, FilePathTypedDict
|
||||
from .urlcitation import URLCitation, URLCitationTypedDict
|
||||
from openrouter.utils import get_discriminator
|
||||
from pydantic import Discriminator, Tag
|
||||
from typing import Union
|
||||
from typing_extensions import TypeAliasType
|
||||
from typing_extensions import Annotated, TypeAliasType
|
||||
|
||||
|
||||
OpenAIResponsesAnnotationTypedDict = TypeAliasType(
|
||||
@@ -14,6 +16,11 @@ OpenAIResponsesAnnotationTypedDict = TypeAliasType(
|
||||
)
|
||||
|
||||
|
||||
OpenAIResponsesAnnotation = TypeAliasType(
|
||||
"OpenAIResponsesAnnotation", Union[FilePath, FileCitation, URLCitation]
|
||||
)
|
||||
OpenAIResponsesAnnotation = Annotated[
|
||||
Union[
|
||||
Annotated[FileCitation, Tag("file_citation")],
|
||||
Annotated[URLCitation, Tag("url_citation")],
|
||||
Annotated[FilePath, Tag("file_path")],
|
||||
],
|
||||
Discriminator(lambda m: get_discriminator(m, "type", "type")),
|
||||
]
|
||||
|
||||
@@ -48,8 +48,8 @@ from openrouter.types import (
|
||||
UNSET,
|
||||
UNSET_SENTINEL,
|
||||
)
|
||||
from openrouter.utils import validate_open_enum
|
||||
from pydantic import model_serializer
|
||||
from openrouter.utils import get_discriminator, validate_open_enum
|
||||
from pydantic import 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
|
||||
@@ -127,16 +127,19 @@ OpenResponsesNonStreamingResponseToolUnionTypedDict = TypeAliasType(
|
||||
)
|
||||
|
||||
|
||||
OpenResponsesNonStreamingResponseToolUnion = TypeAliasType(
|
||||
"OpenResponsesNonStreamingResponseToolUnion",
|
||||
OpenResponsesNonStreamingResponseToolUnion = Annotated[
|
||||
Union[
|
||||
OpenResponsesWebSearchPreviewTool,
|
||||
OpenResponsesWebSearchPreview20250311Tool,
|
||||
OpenResponsesWebSearchTool,
|
||||
OpenResponsesWebSearch20250826Tool,
|
||||
OpenResponsesNonStreamingResponseToolFunction,
|
||||
Annotated[OpenResponsesNonStreamingResponseToolFunction, Tag("function")],
|
||||
Annotated[OpenResponsesWebSearchPreviewTool, Tag("web_search_preview")],
|
||||
Annotated[
|
||||
OpenResponsesWebSearchPreview20250311Tool,
|
||||
Tag("web_search_preview_2025_03_11"),
|
||||
],
|
||||
Annotated[OpenResponsesWebSearchTool, Tag("web_search")],
|
||||
Annotated[OpenResponsesWebSearch20250826Tool, Tag("web_search_2025_08_26")],
|
||||
],
|
||||
)
|
||||
Discriminator(lambda m: get_discriminator(m, "type", "type")),
|
||||
]
|
||||
|
||||
|
||||
class OpenResponsesNonStreamingResponseTypedDict(TypedDict):
|
||||
|
||||
@@ -44,9 +44,10 @@ from openrouter.types import (
|
||||
UNSET_SENTINEL,
|
||||
UnrecognizedStr,
|
||||
)
|
||||
from openrouter.utils import validate_open_enum
|
||||
from pydantic import model_serializer
|
||||
from pydantic.functional_validators import PlainValidator
|
||||
from openrouter.utils import get_discriminator, validate_const, validate_open_enum
|
||||
import pydantic
|
||||
from pydantic import Discriminator, Tag, model_serializer
|
||||
from pydantic.functional_validators import AfterValidator, PlainValidator
|
||||
from typing import Any, Dict, List, Literal, Optional, Union
|
||||
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict
|
||||
|
||||
@@ -120,30 +121,24 @@ OpenResponsesRequestToolUnionTypedDict = TypeAliasType(
|
||||
)
|
||||
|
||||
|
||||
OpenResponsesRequestToolUnion = TypeAliasType(
|
||||
"OpenResponsesRequestToolUnion",
|
||||
OpenResponsesRequestToolUnion = Annotated[
|
||||
Union[
|
||||
OpenResponsesWebSearchPreviewTool,
|
||||
OpenResponsesWebSearchPreview20250311Tool,
|
||||
OpenResponsesWebSearchTool,
|
||||
OpenResponsesWebSearch20250826Tool,
|
||||
OpenResponsesRequestToolFunction,
|
||||
Annotated[OpenResponsesRequestToolFunction, Tag("function")],
|
||||
Annotated[OpenResponsesWebSearchPreviewTool, Tag("web_search_preview")],
|
||||
Annotated[
|
||||
OpenResponsesWebSearchPreview20250311Tool,
|
||||
Tag("web_search_preview_2025_03_11"),
|
||||
],
|
||||
Annotated[OpenResponsesWebSearchTool, Tag("web_search")],
|
||||
Annotated[OpenResponsesWebSearch20250826Tool, Tag("web_search_2025_08_26")],
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
ServiceTier = Union[
|
||||
Literal[
|
||||
"auto",
|
||||
"default",
|
||||
"flex",
|
||||
"priority",
|
||||
"scale",
|
||||
],
|
||||
UnrecognizedStr,
|
||||
Discriminator(lambda m: get_discriminator(m, "type", "type")),
|
||||
]
|
||||
|
||||
|
||||
ServiceTier = Literal["auto",]
|
||||
|
||||
|
||||
Truncation = Union[
|
||||
Literal[
|
||||
"auto",
|
||||
@@ -353,6 +348,17 @@ class Provider(BaseModel):
|
||||
return m
|
||||
|
||||
|
||||
IDResponseHealing = Literal["response-healing",]
|
||||
|
||||
|
||||
class PluginResponseHealingTypedDict(TypedDict):
|
||||
id: IDResponseHealing
|
||||
|
||||
|
||||
class PluginResponseHealing(BaseModel):
|
||||
id: IDResponseHealing
|
||||
|
||||
|
||||
IDFileParser = Literal["file-parser",]
|
||||
|
||||
|
||||
@@ -434,11 +440,24 @@ class PluginModeration(BaseModel):
|
||||
|
||||
PluginTypedDict = TypeAliasType(
|
||||
"PluginTypedDict",
|
||||
Union[PluginModerationTypedDict, PluginFileParserTypedDict, PluginWebTypedDict],
|
||||
Union[
|
||||
PluginModerationTypedDict,
|
||||
PluginResponseHealingTypedDict,
|
||||
PluginFileParserTypedDict,
|
||||
PluginWebTypedDict,
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
Plugin = TypeAliasType("Plugin", Union[PluginModeration, PluginFileParser, PluginWeb])
|
||||
Plugin = Annotated[
|
||||
Union[
|
||||
Annotated[PluginModeration, Tag("moderation")],
|
||||
Annotated[PluginWeb, Tag("web")],
|
||||
Annotated[PluginFileParser, Tag("file-parser")],
|
||||
Annotated[PluginResponseHealing, Tag("response-healing")],
|
||||
],
|
||||
Discriminator(lambda m: get_discriminator(m, "id", "id")),
|
||||
]
|
||||
|
||||
|
||||
class OpenResponsesRequestTypedDict(TypedDict):
|
||||
@@ -468,8 +487,8 @@ class OpenResponsesRequestTypedDict(TypedDict):
|
||||
include: NotRequired[Nullable[List[OpenAIResponsesIncludable]]]
|
||||
background: NotRequired[Nullable[bool]]
|
||||
safety_identifier: NotRequired[Nullable[str]]
|
||||
store: NotRequired[Nullable[bool]]
|
||||
service_tier: NotRequired[Nullable[ServiceTier]]
|
||||
store: Literal[False]
|
||||
service_tier: NotRequired[ServiceTier]
|
||||
truncation: NotRequired[Nullable[Truncation]]
|
||||
stream: NotRequired[bool]
|
||||
provider: NotRequired[Nullable[ProviderTypedDict]]
|
||||
@@ -533,11 +552,12 @@ class OpenResponsesRequest(BaseModel):
|
||||
|
||||
safety_identifier: OptionalNullable[str] = UNSET
|
||||
|
||||
store: OptionalNullable[bool] = UNSET
|
||||
STORE: Annotated[
|
||||
Annotated[Optional[Literal[False]], AfterValidator(validate_const(False))],
|
||||
pydantic.Field(alias="store"),
|
||||
] = False
|
||||
|
||||
service_tier: Annotated[
|
||||
OptionalNullable[ServiceTier], PlainValidator(validate_open_enum(False))
|
||||
] = UNSET
|
||||
service_tier: Optional[ServiceTier] = "auto"
|
||||
|
||||
truncation: Annotated[
|
||||
OptionalNullable[Truncation], PlainValidator(validate_open_enum(False))
|
||||
@@ -599,8 +619,6 @@ class OpenResponsesRequest(BaseModel):
|
||||
"include",
|
||||
"background",
|
||||
"safety_identifier",
|
||||
"store",
|
||||
"service_tier",
|
||||
"truncation",
|
||||
"provider",
|
||||
]
|
||||
|
||||
@@ -59,8 +59,10 @@ from .reasoningtextcontent import ReasoningTextContent, ReasoningTextContentType
|
||||
from .responseoutputtext import ResponseOutputText, ResponseOutputTextTypedDict
|
||||
from .responsesoutputitem import ResponsesOutputItem, ResponsesOutputItemTypedDict
|
||||
from openrouter.types import BaseModel
|
||||
from openrouter.utils import get_discriminator
|
||||
from pydantic import Discriminator, Tag
|
||||
from typing import List, Literal, Union
|
||||
from typing_extensions import TypeAliasType, TypedDict
|
||||
from typing_extensions import Annotated, TypeAliasType, TypedDict
|
||||
|
||||
|
||||
TypeResponseReasoningSummaryPartDone = Literal["response.reasoning_summary_part.done",]
|
||||
@@ -328,10 +330,14 @@ Part2TypedDict = TypeAliasType(
|
||||
)
|
||||
|
||||
|
||||
Part2 = TypeAliasType(
|
||||
"Part2",
|
||||
Union[ReasoningTextContent, OpenAIResponsesRefusalContent, ResponseOutputText],
|
||||
)
|
||||
Part2 = Annotated[
|
||||
Union[
|
||||
Annotated[ResponseOutputText, Tag("output_text")],
|
||||
Annotated[ReasoningTextContent, Tag("reasoning_text")],
|
||||
Annotated[OpenAIResponsesRefusalContent, Tag("refusal")],
|
||||
],
|
||||
Discriminator(lambda m: get_discriminator(m, "type", "type")),
|
||||
]
|
||||
|
||||
|
||||
class OpenResponsesStreamEventResponseContentPartDoneTypedDict(TypedDict):
|
||||
@@ -374,10 +380,14 @@ Part1TypedDict = TypeAliasType(
|
||||
)
|
||||
|
||||
|
||||
Part1 = TypeAliasType(
|
||||
"Part1",
|
||||
Union[ReasoningTextContent, OpenAIResponsesRefusalContent, ResponseOutputText],
|
||||
)
|
||||
Part1 = Annotated[
|
||||
Union[
|
||||
Annotated[ResponseOutputText, Tag("output_text")],
|
||||
Annotated[ReasoningTextContent, Tag("reasoning_text")],
|
||||
Annotated[OpenAIResponsesRefusalContent, Tag("refusal")],
|
||||
],
|
||||
Discriminator(lambda m: get_discriminator(m, "type", "type")),
|
||||
]
|
||||
|
||||
|
||||
class OpenResponsesStreamEventResponseContentPartAddedTypedDict(TypedDict):
|
||||
@@ -609,36 +619,97 @@ OpenResponsesStreamEventTypedDict = TypeAliasType(
|
||||
r"""Union of all possible event types emitted during response streaming"""
|
||||
|
||||
|
||||
OpenResponsesStreamEvent = TypeAliasType(
|
||||
"OpenResponsesStreamEvent",
|
||||
OpenResponsesStreamEvent = Annotated[
|
||||
Union[
|
||||
OpenResponsesStreamEventResponseCreated,
|
||||
OpenResponsesStreamEventResponseInProgress,
|
||||
OpenResponsesStreamEventResponseCompleted,
|
||||
OpenResponsesStreamEventResponseIncomplete,
|
||||
OpenResponsesStreamEventResponseFailed,
|
||||
OpenResponsesStreamEventResponseOutputItemAdded,
|
||||
OpenResponsesStreamEventResponseOutputItemDone,
|
||||
OpenResponsesImageGenCallCompleted,
|
||||
OpenResponsesImageGenCallGenerating,
|
||||
OpenResponsesImageGenCallInProgress,
|
||||
OpenResponsesErrorEvent,
|
||||
OpenResponsesStreamEventResponseFunctionCallArgumentsDelta,
|
||||
OpenResponsesStreamEventResponseRefusalDelta,
|
||||
OpenResponsesReasoningSummaryPartAddedEvent,
|
||||
OpenResponsesStreamEventResponseContentPartAdded,
|
||||
OpenResponsesImageGenCallPartialImage,
|
||||
OpenResponsesStreamEventResponseFunctionCallArgumentsDone,
|
||||
OpenResponsesReasoningDeltaEvent,
|
||||
OpenResponsesReasoningDoneEvent,
|
||||
OpenResponsesStreamEventResponseRefusalDone,
|
||||
OpenResponsesStreamEventResponseReasoningSummaryPartDone,
|
||||
OpenResponsesReasoningSummaryTextDeltaEvent,
|
||||
OpenResponsesReasoningSummaryTextDoneEvent,
|
||||
OpenResponsesStreamEventResponseContentPartDone,
|
||||
OpenResponsesStreamEventResponseOutputTextDelta,
|
||||
OpenResponsesStreamEventResponseOutputTextDone,
|
||||
OpenResponsesStreamEventResponseOutputTextAnnotationAdded,
|
||||
Annotated[OpenResponsesStreamEventResponseCreated, Tag("response.created")],
|
||||
Annotated[
|
||||
OpenResponsesStreamEventResponseInProgress, Tag("response.in_progress")
|
||||
],
|
||||
Annotated[OpenResponsesStreamEventResponseCompleted, Tag("response.completed")],
|
||||
Annotated[
|
||||
OpenResponsesStreamEventResponseIncomplete, Tag("response.incomplete")
|
||||
],
|
||||
Annotated[OpenResponsesStreamEventResponseFailed, Tag("response.failed")],
|
||||
Annotated[OpenResponsesErrorEvent, Tag("error")],
|
||||
Annotated[
|
||||
OpenResponsesStreamEventResponseOutputItemAdded,
|
||||
Tag("response.output_item.added"),
|
||||
],
|
||||
Annotated[
|
||||
OpenResponsesStreamEventResponseOutputItemDone,
|
||||
Tag("response.output_item.done"),
|
||||
],
|
||||
Annotated[
|
||||
OpenResponsesStreamEventResponseContentPartAdded,
|
||||
Tag("response.content_part.added"),
|
||||
],
|
||||
Annotated[
|
||||
OpenResponsesStreamEventResponseContentPartDone,
|
||||
Tag("response.content_part.done"),
|
||||
],
|
||||
Annotated[
|
||||
OpenResponsesStreamEventResponseOutputTextDelta,
|
||||
Tag("response.output_text.delta"),
|
||||
],
|
||||
Annotated[
|
||||
OpenResponsesStreamEventResponseOutputTextDone,
|
||||
Tag("response.output_text.done"),
|
||||
],
|
||||
Annotated[
|
||||
OpenResponsesStreamEventResponseRefusalDelta, Tag("response.refusal.delta")
|
||||
],
|
||||
Annotated[
|
||||
OpenResponsesStreamEventResponseRefusalDone, Tag("response.refusal.done")
|
||||
],
|
||||
Annotated[
|
||||
OpenResponsesStreamEventResponseOutputTextAnnotationAdded,
|
||||
Tag("response.output_text.annotation.added"),
|
||||
],
|
||||
Annotated[
|
||||
OpenResponsesStreamEventResponseFunctionCallArgumentsDelta,
|
||||
Tag("response.function_call_arguments.delta"),
|
||||
],
|
||||
Annotated[
|
||||
OpenResponsesStreamEventResponseFunctionCallArgumentsDone,
|
||||
Tag("response.function_call_arguments.done"),
|
||||
],
|
||||
Annotated[
|
||||
OpenResponsesReasoningDeltaEvent, Tag("response.reasoning_text.delta")
|
||||
],
|
||||
Annotated[OpenResponsesReasoningDoneEvent, Tag("response.reasoning_text.done")],
|
||||
Annotated[
|
||||
OpenResponsesReasoningSummaryPartAddedEvent,
|
||||
Tag("response.reasoning_summary_part.added"),
|
||||
],
|
||||
Annotated[
|
||||
OpenResponsesStreamEventResponseReasoningSummaryPartDone,
|
||||
Tag("response.reasoning_summary_part.done"),
|
||||
],
|
||||
Annotated[
|
||||
OpenResponsesReasoningSummaryTextDeltaEvent,
|
||||
Tag("response.reasoning_summary_text.delta"),
|
||||
],
|
||||
Annotated[
|
||||
OpenResponsesReasoningSummaryTextDoneEvent,
|
||||
Tag("response.reasoning_summary_text.done"),
|
||||
],
|
||||
Annotated[
|
||||
OpenResponsesImageGenCallInProgress,
|
||||
Tag("response.image_generation_call.in_progress"),
|
||||
],
|
||||
Annotated[
|
||||
OpenResponsesImageGenCallGenerating,
|
||||
Tag("response.image_generation_call.generating"),
|
||||
],
|
||||
Annotated[
|
||||
OpenResponsesImageGenCallPartialImage,
|
||||
Tag("response.image_generation_call.partial_image"),
|
||||
],
|
||||
Annotated[
|
||||
OpenResponsesImageGenCallCompleted,
|
||||
Tag("response.image_generation_call.completed"),
|
||||
],
|
||||
],
|
||||
)
|
||||
Discriminator(lambda m: get_discriminator(m, "type", "type")),
|
||||
]
|
||||
r"""Union of all possible event types emitted during response streaming"""
|
||||
|
||||
@@ -7,8 +7,10 @@ from .openairesponsesrefusalcontent import (
|
||||
)
|
||||
from .responseoutputtext import ResponseOutputText, ResponseOutputTextTypedDict
|
||||
from openrouter.types import BaseModel
|
||||
from openrouter.utils import get_discriminator
|
||||
from pydantic import Discriminator, Tag
|
||||
from typing import List, Literal, Optional, Union
|
||||
from typing_extensions import NotRequired, TypeAliasType, TypedDict
|
||||
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict
|
||||
|
||||
|
||||
OutputMessageRole = Literal["assistant",]
|
||||
@@ -52,9 +54,13 @@ OutputMessageContentTypedDict = TypeAliasType(
|
||||
)
|
||||
|
||||
|
||||
OutputMessageContent = TypeAliasType(
|
||||
"OutputMessageContent", Union[OpenAIResponsesRefusalContent, ResponseOutputText]
|
||||
)
|
||||
OutputMessageContent = Annotated[
|
||||
Union[
|
||||
Annotated[ResponseOutputText, Tag("output_text")],
|
||||
Annotated[OpenAIResponsesRefusalContent, Tag("refusal")],
|
||||
],
|
||||
Discriminator(lambda m: get_discriminator(m, "type", "type")),
|
||||
]
|
||||
|
||||
|
||||
class OutputMessageTypedDict(TypedDict):
|
||||
|
||||
@@ -11,12 +11,14 @@ ProviderName = Union[
|
||||
"AionLabs",
|
||||
"Alibaba",
|
||||
"Amazon Bedrock",
|
||||
"Amazon Nova",
|
||||
"Anthropic",
|
||||
"Arcee",
|
||||
"Arcee AI",
|
||||
"AtlasCloud",
|
||||
"Avian",
|
||||
"Azure",
|
||||
"BaseTen",
|
||||
"BytePlus",
|
||||
"Black Forest Labs",
|
||||
"Cerebras",
|
||||
"Chutes",
|
||||
@@ -31,6 +33,7 @@ ProviderName = Union[
|
||||
"Fireworks",
|
||||
"Friendli",
|
||||
"GMICloud",
|
||||
"GoPomelo",
|
||||
"Google",
|
||||
"Google AI Studio",
|
||||
"Groq",
|
||||
@@ -61,6 +64,7 @@ ProviderName = Union[
|
||||
"SambaNova",
|
||||
"SiliconFlow",
|
||||
"Stealth",
|
||||
"StreamLake",
|
||||
"Switchpoint",
|
||||
"Targon",
|
||||
"Together",
|
||||
|
||||
@@ -10,8 +10,10 @@ from .responsesformattextjsonschemaconfig import (
|
||||
ResponsesFormatTextJSONSchemaConfig,
|
||||
ResponsesFormatTextJSONSchemaConfigTypedDict,
|
||||
)
|
||||
from openrouter.utils import get_discriminator
|
||||
from pydantic import Discriminator, Tag
|
||||
from typing import Union
|
||||
from typing_extensions import TypeAliasType
|
||||
from typing_extensions import Annotated, TypeAliasType
|
||||
|
||||
|
||||
ResponseFormatTextConfigTypedDict = TypeAliasType(
|
||||
@@ -25,12 +27,12 @@ ResponseFormatTextConfigTypedDict = TypeAliasType(
|
||||
r"""Text response format configuration"""
|
||||
|
||||
|
||||
ResponseFormatTextConfig = TypeAliasType(
|
||||
"ResponseFormatTextConfig",
|
||||
ResponseFormatTextConfig = Annotated[
|
||||
Union[
|
||||
ResponsesFormatText,
|
||||
ResponsesFormatJSONObject,
|
||||
ResponsesFormatTextJSONSchemaConfig,
|
||||
Annotated[ResponsesFormatText, Tag("text")],
|
||||
Annotated[ResponsesFormatJSONObject, Tag("json_object")],
|
||||
Annotated[ResponsesFormatTextJSONSchemaConfig, Tag("json_schema")],
|
||||
],
|
||||
)
|
||||
Discriminator(lambda m: get_discriminator(m, "type", "type")),
|
||||
]
|
||||
r"""Text response format configuration"""
|
||||
|
||||
@@ -25,8 +25,10 @@ from .responseswebsearchcalloutput import (
|
||||
ResponsesWebSearchCallOutput,
|
||||
ResponsesWebSearchCallOutputTypedDict,
|
||||
)
|
||||
from openrouter.utils import get_discriminator
|
||||
from pydantic import Discriminator, Tag
|
||||
from typing import Union
|
||||
from typing_extensions import TypeAliasType
|
||||
from typing_extensions import Annotated, TypeAliasType
|
||||
|
||||
|
||||
ResponsesOutputItemTypedDict = TypeAliasType(
|
||||
@@ -43,15 +45,15 @@ ResponsesOutputItemTypedDict = TypeAliasType(
|
||||
r"""An output item from the response"""
|
||||
|
||||
|
||||
ResponsesOutputItem = TypeAliasType(
|
||||
"ResponsesOutputItem",
|
||||
ResponsesOutputItem = Annotated[
|
||||
Union[
|
||||
ResponsesWebSearchCallOutput,
|
||||
ResponsesOutputItemFileSearchCall,
|
||||
ResponsesImageGenerationCall,
|
||||
ResponsesOutputMessage,
|
||||
ResponsesOutputItemReasoning,
|
||||
ResponsesOutputItemFunctionCall,
|
||||
Annotated[ResponsesOutputMessage, Tag("message")],
|
||||
Annotated[ResponsesOutputItemReasoning, Tag("reasoning")],
|
||||
Annotated[ResponsesOutputItemFunctionCall, Tag("function_call")],
|
||||
Annotated[ResponsesWebSearchCallOutput, Tag("web_search_call")],
|
||||
Annotated[ResponsesOutputItemFileSearchCall, Tag("file_search_call")],
|
||||
Annotated[ResponsesImageGenerationCall, Tag("image_generation_call")],
|
||||
],
|
||||
)
|
||||
Discriminator(lambda m: get_discriminator(m, "type", "type")),
|
||||
]
|
||||
r"""An output item from the response"""
|
||||
|
||||
@@ -7,8 +7,10 @@ from .openairesponsesrefusalcontent import (
|
||||
)
|
||||
from .responseoutputtext import ResponseOutputText, ResponseOutputTextTypedDict
|
||||
from openrouter.types import BaseModel
|
||||
from openrouter.utils import get_discriminator
|
||||
from pydantic import Discriminator, Tag
|
||||
from typing import List, Literal, Optional, Union
|
||||
from typing_extensions import NotRequired, TypeAliasType, TypedDict
|
||||
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict
|
||||
|
||||
|
||||
ResponsesOutputMessageRole = Literal["assistant",]
|
||||
@@ -52,10 +54,13 @@ ResponsesOutputMessageContentTypedDict = TypeAliasType(
|
||||
)
|
||||
|
||||
|
||||
ResponsesOutputMessageContent = TypeAliasType(
|
||||
"ResponsesOutputMessageContent",
|
||||
Union[OpenAIResponsesRefusalContent, ResponseOutputText],
|
||||
)
|
||||
ResponsesOutputMessageContent = Annotated[
|
||||
Union[
|
||||
Annotated[ResponseOutputText, Tag("output_text")],
|
||||
Annotated[OpenAIResponsesRefusalContent, Tag("refusal")],
|
||||
],
|
||||
Discriminator(lambda m: get_discriminator(m, "type", "type")),
|
||||
]
|
||||
|
||||
|
||||
class ResponsesOutputMessageTypedDict(TypedDict):
|
||||
|
||||
@@ -51,6 +51,7 @@ class Credits(BaseSDK):
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -147,6 +148,7 @@ class Credits(BaseSDK):
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -266,6 +268,7 @@ class Credits(BaseSDK):
|
||||
get_serialized_body=lambda: utils.serialize_request_body(
|
||||
request, False, False, "json", components.CreateChargeRequest
|
||||
),
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -390,6 +393,7 @@ class Credits(BaseSDK):
|
||||
get_serialized_body=lambda: utils.serialize_request_body(
|
||||
request, False, False, "json", components.CreateChargeRequest
|
||||
),
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
||||
|
||||
from .basesdk import BaseSDK
|
||||
from enum import Enum
|
||||
from openrouter import components, errors, operations, utils
|
||||
from openrouter._hooks import HookContext
|
||||
from openrouter.types import OptionalNullable, UNSET
|
||||
@@ -10,11 +9,6 @@ from openrouter.utils.unmarshal_json_response import unmarshal_json_response
|
||||
from typing import Any, Mapping, Optional, Union
|
||||
|
||||
|
||||
class GenerateAcceptEnum(str, Enum):
|
||||
APPLICATION_JSON = "application/json"
|
||||
TEXT_EVENT_STREAM = "text/event-stream"
|
||||
|
||||
|
||||
class Embeddings(BaseSDK):
|
||||
r"""Text embedding endpoints"""
|
||||
|
||||
@@ -36,7 +30,6 @@ class Embeddings(BaseSDK):
|
||||
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
||||
server_url: Optional[str] = None,
|
||||
timeout_ms: Optional[int] = None,
|
||||
accept_header_override: Optional[GenerateAcceptEnum] = None,
|
||||
http_headers: Optional[Mapping[str, str]] = None,
|
||||
) -> operations.CreateEmbeddingsResponse:
|
||||
r"""Submit an embedding request
|
||||
@@ -53,7 +46,6 @@ class Embeddings(BaseSDK):
|
||||
:param retries: Override the default retry configuration for this method
|
||||
:param server_url: Override the default server URL for this method
|
||||
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
||||
:param accept_header_override: Override the default accept header for this method
|
||||
:param http_headers: Additional headers to set or replace on requests.
|
||||
"""
|
||||
base_url = None
|
||||
@@ -88,14 +80,13 @@ class Embeddings(BaseSDK):
|
||||
request_has_path_params=False,
|
||||
request_has_query_params=True,
|
||||
user_agent_header="user-agent",
|
||||
accept_header_value=accept_header_override.value
|
||||
if accept_header_override is not None
|
||||
else "application/json;q=1, text/event-stream;q=0",
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
get_serialized_body=lambda: utils.serialize_request_body(
|
||||
request, False, False, "json", operations.CreateEmbeddingsRequest
|
||||
),
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -138,10 +129,8 @@ class Embeddings(BaseSDK):
|
||||
response_data: Any = None
|
||||
if utils.match_response(http_res, "200", "application/json"):
|
||||
return unmarshal_json_response(
|
||||
operations.CreateEmbeddingsResponseBody, http_res
|
||||
operations.CreateEmbeddingsResponse, http_res
|
||||
)
|
||||
if utils.match_response(http_res, "200", "text/event-stream"):
|
||||
return http_res.text
|
||||
if utils.match_response(http_res, "400", "application/json"):
|
||||
response_data = unmarshal_json_response(
|
||||
errors.BadRequestResponseErrorData, http_res
|
||||
@@ -223,7 +212,6 @@ class Embeddings(BaseSDK):
|
||||
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
||||
server_url: Optional[str] = None,
|
||||
timeout_ms: Optional[int] = None,
|
||||
accept_header_override: Optional[GenerateAcceptEnum] = None,
|
||||
http_headers: Optional[Mapping[str, str]] = None,
|
||||
) -> operations.CreateEmbeddingsResponse:
|
||||
r"""Submit an embedding request
|
||||
@@ -240,7 +228,6 @@ class Embeddings(BaseSDK):
|
||||
:param retries: Override the default retry configuration for this method
|
||||
:param server_url: Override the default server URL for this method
|
||||
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
||||
:param accept_header_override: Override the default accept header for this method
|
||||
:param http_headers: Additional headers to set or replace on requests.
|
||||
"""
|
||||
base_url = None
|
||||
@@ -275,14 +262,13 @@ class Embeddings(BaseSDK):
|
||||
request_has_path_params=False,
|
||||
request_has_query_params=True,
|
||||
user_agent_header="user-agent",
|
||||
accept_header_value=accept_header_override.value
|
||||
if accept_header_override is not None
|
||||
else "application/json;q=1, text/event-stream;q=0",
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
get_serialized_body=lambda: utils.serialize_request_body(
|
||||
request, False, False, "json", operations.CreateEmbeddingsRequest
|
||||
),
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -325,10 +311,8 @@ class Embeddings(BaseSDK):
|
||||
response_data: Any = None
|
||||
if utils.match_response(http_res, "200", "application/json"):
|
||||
return unmarshal_json_response(
|
||||
operations.CreateEmbeddingsResponseBody, http_res
|
||||
operations.CreateEmbeddingsResponse, http_res
|
||||
)
|
||||
if utils.match_response(http_res, "200", "text/event-stream"):
|
||||
return http_res.text
|
||||
if utils.match_response(http_res, "400", "application/json"):
|
||||
response_data = unmarshal_json_response(
|
||||
errors.BadRequestResponseErrorData, http_res
|
||||
@@ -431,6 +415,7 @@ class Embeddings(BaseSDK):
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -522,6 +507,7 @@ class Embeddings(BaseSDK):
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ class Endpoints(BaseSDK):
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -158,6 +159,7 @@ class Endpoints(BaseSDK):
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -247,6 +249,7 @@ class Endpoints(BaseSDK):
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -333,6 +336,7 @@ class Endpoints(BaseSDK):
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ class Generations(BaseSDK):
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -193,6 +194,7 @@ class Generations(BaseSDK):
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
||||
|
||||
# package
|
||||
@@ -0,0 +1,54 @@
|
||||
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
from importlib import import_module
|
||||
import builtins
|
||||
import sys
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .globals import Globals, GlobalsTypedDict
|
||||
|
||||
__all__ = ["Globals", "GlobalsTypedDict"]
|
||||
|
||||
_dynamic_imports: dict[str, str] = {
|
||||
"Globals": ".globals",
|
||||
"GlobalsTypedDict": ".globals",
|
||||
}
|
||||
|
||||
|
||||
def dynamic_import(modname, retries=3):
|
||||
for attempt in range(retries):
|
||||
try:
|
||||
return import_module(modname, __package__)
|
||||
except KeyError:
|
||||
# Clear any half-initialized module and retry
|
||||
sys.modules.pop(modname, None)
|
||||
if attempt == retries - 1:
|
||||
break
|
||||
raise KeyError(f"Failed to import module '{modname}' after {retries} attempts")
|
||||
|
||||
|
||||
def __getattr__(attr_name: str) -> object:
|
||||
module_name = _dynamic_imports.get(attr_name)
|
||||
if module_name is None:
|
||||
raise AttributeError(
|
||||
f"No {attr_name} found in _dynamic_imports for module name -> {__name__} "
|
||||
)
|
||||
|
||||
try:
|
||||
module = dynamic_import(module_name)
|
||||
result = getattr(module, attr_name)
|
||||
return result
|
||||
except ImportError as e:
|
||||
raise ImportError(
|
||||
f"Failed to import {attr_name} from {module_name}: {e}"
|
||||
) from e
|
||||
except AttributeError as e:
|
||||
raise AttributeError(
|
||||
f"Failed to get {attr_name} from {module_name}: {e}"
|
||||
) from e
|
||||
|
||||
|
||||
def __dir__():
|
||||
lazy_attrs = builtins.list(_dynamic_imports.keys())
|
||||
return builtins.sorted(lazy_attrs)
|
||||
@@ -0,0 +1,41 @@
|
||||
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
||||
|
||||
from __future__ import annotations
|
||||
from openrouter.types import BaseModel
|
||||
from openrouter.utils import FieldMetadata, HeaderMetadata
|
||||
import pydantic
|
||||
from typing import Optional
|
||||
from typing_extensions import Annotated, NotRequired, TypedDict
|
||||
|
||||
|
||||
class GlobalsTypedDict(TypedDict):
|
||||
http_referer: NotRequired[str]
|
||||
r"""The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
||||
This is used to track API usage per application.
|
||||
|
||||
"""
|
||||
x_title: NotRequired[str]
|
||||
r"""The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
class Globals(BaseModel):
|
||||
http_referer: Annotated[
|
||||
Optional[str],
|
||||
pydantic.Field(alias="HTTP-Referer"),
|
||||
FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
|
||||
] = None
|
||||
r"""The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
||||
This is used to track API usage per application.
|
||||
|
||||
"""
|
||||
|
||||
x_title: Annotated[
|
||||
Optional[str],
|
||||
pydantic.Field(alias="X-Title"),
|
||||
FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
|
||||
] = None
|
||||
r"""The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
||||
|
||||
"""
|
||||
@@ -49,6 +49,7 @@ class Models(BaseSDK):
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -133,6 +134,7 @@ class Models(BaseSDK):
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -227,6 +229,7 @@ class Models(BaseSDK):
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -326,6 +329,7 @@ class Models(BaseSDK):
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -422,6 +426,7 @@ class Models(BaseSDK):
|
||||
security=utils.get_pydantic_model(
|
||||
security, operations.ListModelsUserSecurity
|
||||
),
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -516,6 +521,7 @@ class Models(BaseSDK):
|
||||
security=utils.get_pydantic_model(
|
||||
security, operations.ListModelsUserSecurity
|
||||
),
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
|
||||
@@ -74,6 +74,7 @@ class OAuth(BaseSDK):
|
||||
"json",
|
||||
operations.ExchangeAuthCodeForAPIKeyRequest,
|
||||
),
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -194,6 +195,7 @@ class OAuth(BaseSDK):
|
||||
"json",
|
||||
operations.ExchangeAuthCodeForAPIKeyRequest,
|
||||
),
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -316,6 +318,7 @@ class OAuth(BaseSDK):
|
||||
get_serialized_body=lambda: utils.serialize_request_body(
|
||||
request, False, False, "json", operations.CreateAuthKeysCodeRequest
|
||||
),
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -438,6 +441,7 @@ class OAuth(BaseSDK):
|
||||
get_serialized_body=lambda: utils.serialize_request_body(
|
||||
request, False, False, "json", operations.CreateAuthKeysCodeRequest
|
||||
),
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
|
||||
@@ -45,8 +45,6 @@ if TYPE_CHECKING:
|
||||
CreateEmbeddingsRequest,
|
||||
CreateEmbeddingsRequestTypedDict,
|
||||
CreateEmbeddingsResponse,
|
||||
CreateEmbeddingsResponseBody,
|
||||
CreateEmbeddingsResponseBodyTypedDict,
|
||||
CreateEmbeddingsResponseTypedDict,
|
||||
Embedding,
|
||||
EmbeddingTypedDict,
|
||||
@@ -100,7 +98,12 @@ if TYPE_CHECKING:
|
||||
ExchangeAuthCodeForAPIKeyResponse,
|
||||
ExchangeAuthCodeForAPIKeyResponseTypedDict,
|
||||
)
|
||||
from .getcredits import GetCreditsResponse, GetCreditsResponseTypedDict
|
||||
from .getcredits import (
|
||||
GetCreditsData,
|
||||
GetCreditsDataTypedDict,
|
||||
GetCreditsResponse,
|
||||
GetCreditsResponseTypedDict,
|
||||
)
|
||||
from .getcurrentkey import (
|
||||
GetCurrentKeyData,
|
||||
GetCurrentKeyDataTypedDict,
|
||||
@@ -216,8 +219,6 @@ __all__ = [
|
||||
"CreateEmbeddingsRequest",
|
||||
"CreateEmbeddingsRequestTypedDict",
|
||||
"CreateEmbeddingsResponse",
|
||||
"CreateEmbeddingsResponseBody",
|
||||
"CreateEmbeddingsResponseBodyTypedDict",
|
||||
"CreateEmbeddingsResponseTypedDict",
|
||||
"CreateKeysData",
|
||||
"CreateKeysDataTypedDict",
|
||||
@@ -242,6 +243,8 @@ __all__ = [
|
||||
"ExchangeAuthCodeForAPIKeyRequestTypedDict",
|
||||
"ExchangeAuthCodeForAPIKeyResponse",
|
||||
"ExchangeAuthCodeForAPIKeyResponseTypedDict",
|
||||
"GetCreditsData",
|
||||
"GetCreditsDataTypedDict",
|
||||
"GetCreditsResponse",
|
||||
"GetCreditsResponseTypedDict",
|
||||
"GetCurrentKeyData",
|
||||
@@ -370,8 +373,6 @@ _dynamic_imports: dict[str, str] = {
|
||||
"CreateEmbeddingsRequest": ".createembeddings",
|
||||
"CreateEmbeddingsRequestTypedDict": ".createembeddings",
|
||||
"CreateEmbeddingsResponse": ".createembeddings",
|
||||
"CreateEmbeddingsResponseBody": ".createembeddings",
|
||||
"CreateEmbeddingsResponseBodyTypedDict": ".createembeddings",
|
||||
"CreateEmbeddingsResponseTypedDict": ".createembeddings",
|
||||
"Embedding": ".createembeddings",
|
||||
"EmbeddingTypedDict": ".createembeddings",
|
||||
@@ -416,6 +417,8 @@ _dynamic_imports: dict[str, str] = {
|
||||
"ExchangeAuthCodeForAPIKeyRequestTypedDict": ".exchangeauthcodeforapikey",
|
||||
"ExchangeAuthCodeForAPIKeyResponse": ".exchangeauthcodeforapikey",
|
||||
"ExchangeAuthCodeForAPIKeyResponseTypedDict": ".exchangeauthcodeforapikey",
|
||||
"GetCreditsData": ".getcredits",
|
||||
"GetCreditsDataTypedDict": ".getcredits",
|
||||
"GetCreditsResponse": ".getcredits",
|
||||
"GetCreditsResponseTypedDict": ".getcredits",
|
||||
"GetCurrentKeyData": ".getcurrentkey",
|
||||
|
||||
@@ -15,8 +15,8 @@ from openrouter.types import (
|
||||
UNSET_SENTINEL,
|
||||
UnrecognizedStr,
|
||||
)
|
||||
from openrouter.utils import validate_open_enum
|
||||
from pydantic import model_serializer
|
||||
from openrouter.utils import get_discriminator, validate_open_enum
|
||||
from pydantic import Discriminator, Tag, model_serializer
|
||||
from pydantic.functional_validators import PlainValidator
|
||||
from typing import Any, List, Literal, Optional, Union
|
||||
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict
|
||||
@@ -63,7 +63,13 @@ ContentTypedDict = TypeAliasType(
|
||||
)
|
||||
|
||||
|
||||
Content = TypeAliasType("Content", Union[ContentText, ContentImageURL])
|
||||
Content = Annotated[
|
||||
Union[
|
||||
Annotated[ContentText, Tag("text")],
|
||||
Annotated[ContentImageURL, Tag("image_url")],
|
||||
],
|
||||
Discriminator(lambda m: get_discriminator(m, "type", "type")),
|
||||
]
|
||||
|
||||
|
||||
class InputTypedDict(TypedDict):
|
||||
@@ -389,7 +395,7 @@ class Usage(BaseModel):
|
||||
cost: Optional[float] = None
|
||||
|
||||
|
||||
class CreateEmbeddingsResponseBodyTypedDict(TypedDict):
|
||||
class CreateEmbeddingsResponseTypedDict(TypedDict):
|
||||
r"""Embedding response"""
|
||||
|
||||
object: Object
|
||||
@@ -399,7 +405,7 @@ class CreateEmbeddingsResponseBodyTypedDict(TypedDict):
|
||||
usage: NotRequired[UsageTypedDict]
|
||||
|
||||
|
||||
class CreateEmbeddingsResponseBody(BaseModel):
|
||||
class CreateEmbeddingsResponse(BaseModel):
|
||||
r"""Embedding response"""
|
||||
|
||||
object: Object
|
||||
@@ -411,14 +417,3 @@ class CreateEmbeddingsResponseBody(BaseModel):
|
||||
id: Optional[str] = None
|
||||
|
||||
usage: Optional[Usage] = None
|
||||
|
||||
|
||||
CreateEmbeddingsResponseTypedDict = TypeAliasType(
|
||||
"CreateEmbeddingsResponseTypedDict",
|
||||
Union[CreateEmbeddingsResponseBodyTypedDict, str],
|
||||
)
|
||||
|
||||
|
||||
CreateEmbeddingsResponse = TypeAliasType(
|
||||
"CreateEmbeddingsResponse", Union[CreateEmbeddingsResponseBody, str]
|
||||
)
|
||||
|
||||
@@ -5,9 +5,28 @@ from openrouter.types import BaseModel
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
|
||||
class GetCreditsDataTypedDict(TypedDict):
|
||||
total_credits: float
|
||||
r"""Total credits purchased"""
|
||||
total_usage: float
|
||||
r"""Total credits used"""
|
||||
|
||||
|
||||
class GetCreditsData(BaseModel):
|
||||
total_credits: float
|
||||
r"""Total credits purchased"""
|
||||
|
||||
total_usage: float
|
||||
r"""Total credits used"""
|
||||
|
||||
|
||||
class GetCreditsResponseTypedDict(TypedDict):
|
||||
r"""Total credits purchased and used"""
|
||||
|
||||
data: GetCreditsDataTypedDict
|
||||
|
||||
|
||||
class GetCreditsResponse(BaseModel):
|
||||
r"""Total credits purchased and used"""
|
||||
|
||||
data: GetCreditsData
|
||||
|
||||
@@ -38,12 +38,14 @@ GetParametersProvider = Union[
|
||||
"AionLabs",
|
||||
"Alibaba",
|
||||
"Amazon Bedrock",
|
||||
"Amazon Nova",
|
||||
"Anthropic",
|
||||
"Arcee",
|
||||
"Arcee AI",
|
||||
"AtlasCloud",
|
||||
"Avian",
|
||||
"Azure",
|
||||
"BaseTen",
|
||||
"BytePlus",
|
||||
"Black Forest Labs",
|
||||
"Cerebras",
|
||||
"Chutes",
|
||||
@@ -58,6 +60,7 @@ GetParametersProvider = Union[
|
||||
"Fireworks",
|
||||
"Friendli",
|
||||
"GMICloud",
|
||||
"GoPomelo",
|
||||
"Google",
|
||||
"Google AI Studio",
|
||||
"Groq",
|
||||
@@ -88,6 +91,7 @@ GetParametersProvider = Union[
|
||||
"SambaNova",
|
||||
"SiliconFlow",
|
||||
"Stealth",
|
||||
"StreamLake",
|
||||
"Switchpoint",
|
||||
"Targon",
|
||||
"Together",
|
||||
|
||||
@@ -68,6 +68,7 @@ class Parameters(BaseSDK):
|
||||
security=utils.get_pydantic_model(
|
||||
security, operations.GetParametersSecurity
|
||||
),
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -179,6 +180,7 @@ class Parameters(BaseSDK):
|
||||
security=utils.get_pydantic_model(
|
||||
security, operations.GetParametersSecurity
|
||||
),
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ class Providers(BaseSDK):
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -133,6 +134,7 @@ class Providers(BaseSDK):
|
||||
accept_header_value="application/json",
|
||||
http_headers=http_headers,
|
||||
security=self.sdk_configuration.security,
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
|
||||
@@ -69,8 +69,7 @@ class Responses(BaseSDK):
|
||||
include: OptionalNullable[List[components.OpenAIResponsesIncludable]] = UNSET,
|
||||
background: OptionalNullable[bool] = UNSET,
|
||||
safety_identifier: OptionalNullable[str] = UNSET,
|
||||
store: OptionalNullable[bool] = UNSET,
|
||||
service_tier: OptionalNullable[components.ServiceTier] = UNSET,
|
||||
service_tier: Optional[components.ServiceTier] = "auto",
|
||||
truncation: OptionalNullable[components.Truncation] = UNSET,
|
||||
stream: Union[Literal[False], None] = None,
|
||||
provider: OptionalNullable[
|
||||
@@ -109,7 +108,6 @@ class Responses(BaseSDK):
|
||||
:param include:
|
||||
:param background:
|
||||
:param safety_identifier:
|
||||
:param store:
|
||||
:param service_tier:
|
||||
:param truncation:
|
||||
:param stream:
|
||||
@@ -174,8 +172,7 @@ class Responses(BaseSDK):
|
||||
include: OptionalNullable[List[components.OpenAIResponsesIncludable]] = UNSET,
|
||||
background: OptionalNullable[bool] = UNSET,
|
||||
safety_identifier: OptionalNullable[str] = UNSET,
|
||||
store: OptionalNullable[bool] = UNSET,
|
||||
service_tier: OptionalNullable[components.ServiceTier] = UNSET,
|
||||
service_tier: Optional[components.ServiceTier] = "auto",
|
||||
truncation: OptionalNullable[components.Truncation] = UNSET,
|
||||
stream: Literal[True],
|
||||
provider: OptionalNullable[
|
||||
@@ -214,7 +211,6 @@ class Responses(BaseSDK):
|
||||
:param include:
|
||||
:param background:
|
||||
:param safety_identifier:
|
||||
:param store:
|
||||
:param service_tier:
|
||||
:param truncation:
|
||||
:param stream:
|
||||
@@ -278,8 +274,7 @@ class Responses(BaseSDK):
|
||||
include: OptionalNullable[List[components.OpenAIResponsesIncludable]] = UNSET,
|
||||
background: OptionalNullable[bool] = UNSET,
|
||||
safety_identifier: OptionalNullable[str] = UNSET,
|
||||
store: OptionalNullable[bool] = UNSET,
|
||||
service_tier: OptionalNullable[components.ServiceTier] = UNSET,
|
||||
service_tier: Optional[components.ServiceTier] = "auto",
|
||||
truncation: OptionalNullable[components.Truncation] = UNSET,
|
||||
stream: Optional[bool] = False,
|
||||
provider: OptionalNullable[
|
||||
@@ -318,7 +313,6 @@ class Responses(BaseSDK):
|
||||
:param include:
|
||||
:param background:
|
||||
:param safety_identifier:
|
||||
:param store:
|
||||
:param service_tier:
|
||||
:param truncation:
|
||||
:param stream:
|
||||
@@ -374,7 +368,6 @@ class Responses(BaseSDK):
|
||||
include=include,
|
||||
background=background,
|
||||
safety_identifier=safety_identifier,
|
||||
store=store,
|
||||
service_tier=service_tier,
|
||||
truncation=truncation,
|
||||
stream=stream,
|
||||
@@ -403,6 +396,7 @@ class Responses(BaseSDK):
|
||||
get_serialized_body=lambda: utils.serialize_request_body(
|
||||
request, False, False, "json", components.OpenResponsesRequest
|
||||
),
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
@@ -626,8 +620,7 @@ class Responses(BaseSDK):
|
||||
include: OptionalNullable[List[components.OpenAIResponsesIncludable]] = UNSET,
|
||||
background: OptionalNullable[bool] = UNSET,
|
||||
safety_identifier: OptionalNullable[str] = UNSET,
|
||||
store: OptionalNullable[bool] = UNSET,
|
||||
service_tier: OptionalNullable[components.ServiceTier] = UNSET,
|
||||
service_tier: Optional[components.ServiceTier] = "auto",
|
||||
truncation: OptionalNullable[components.Truncation] = UNSET,
|
||||
stream: Union[Literal[False], None] = None,
|
||||
provider: OptionalNullable[
|
||||
@@ -666,7 +659,6 @@ class Responses(BaseSDK):
|
||||
:param include:
|
||||
:param background:
|
||||
:param safety_identifier:
|
||||
:param store:
|
||||
:param service_tier:
|
||||
:param truncation:
|
||||
:param stream:
|
||||
@@ -731,8 +723,7 @@ class Responses(BaseSDK):
|
||||
include: OptionalNullable[List[components.OpenAIResponsesIncludable]] = UNSET,
|
||||
background: OptionalNullable[bool] = UNSET,
|
||||
safety_identifier: OptionalNullable[str] = UNSET,
|
||||
store: OptionalNullable[bool] = UNSET,
|
||||
service_tier: OptionalNullable[components.ServiceTier] = UNSET,
|
||||
service_tier: Optional[components.ServiceTier] = "auto",
|
||||
truncation: OptionalNullable[components.Truncation] = UNSET,
|
||||
stream: Literal[True],
|
||||
provider: OptionalNullable[
|
||||
@@ -771,7 +762,6 @@ class Responses(BaseSDK):
|
||||
:param include:
|
||||
:param background:
|
||||
:param safety_identifier:
|
||||
:param store:
|
||||
:param service_tier:
|
||||
:param truncation:
|
||||
:param stream:
|
||||
@@ -835,8 +825,7 @@ class Responses(BaseSDK):
|
||||
include: OptionalNullable[List[components.OpenAIResponsesIncludable]] = UNSET,
|
||||
background: OptionalNullable[bool] = UNSET,
|
||||
safety_identifier: OptionalNullable[str] = UNSET,
|
||||
store: OptionalNullable[bool] = UNSET,
|
||||
service_tier: OptionalNullable[components.ServiceTier] = UNSET,
|
||||
service_tier: Optional[components.ServiceTier] = "auto",
|
||||
truncation: OptionalNullable[components.Truncation] = UNSET,
|
||||
stream: Optional[bool] = False,
|
||||
provider: OptionalNullable[
|
||||
@@ -875,7 +864,6 @@ class Responses(BaseSDK):
|
||||
:param include:
|
||||
:param background:
|
||||
:param safety_identifier:
|
||||
:param store:
|
||||
:param service_tier:
|
||||
:param truncation:
|
||||
:param stream:
|
||||
@@ -931,7 +919,6 @@ class Responses(BaseSDK):
|
||||
include=include,
|
||||
background=background,
|
||||
safety_identifier=safety_identifier,
|
||||
store=store,
|
||||
service_tier=service_tier,
|
||||
truncation=truncation,
|
||||
stream=stream,
|
||||
@@ -960,6 +947,7 @@ class Responses(BaseSDK):
|
||||
get_serialized_body=lambda: utils.serialize_request_body(
|
||||
request, False, False, "json", components.OpenResponsesRequest
|
||||
),
|
||||
allow_empty_value=None,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import httpx
|
||||
import importlib
|
||||
from openrouter import components, utils
|
||||
from openrouter._hooks import SDKHooks
|
||||
from openrouter.models import internal
|
||||
from openrouter.types import OptionalNullable, UNSET
|
||||
import sys
|
||||
from typing import Any, Callable, Dict, Optional, TYPE_CHECKING, Union, cast
|
||||
@@ -77,6 +78,8 @@ class OpenRouter(BaseSDK):
|
||||
def __init__(
|
||||
self,
|
||||
api_key: Optional[Union[Optional[str], Callable[[], Optional[str]]]] = None,
|
||||
http_referer: Optional[str] = None,
|
||||
x_title: Optional[str] = None,
|
||||
server: Optional[str] = None,
|
||||
server_url: Optional[str] = None,
|
||||
url_params: Optional[Dict[str, str]] = None,
|
||||
@@ -89,6 +92,8 @@ class OpenRouter(BaseSDK):
|
||||
r"""Instantiates the SDK configuring it with the provided parameters.
|
||||
|
||||
:param api_key: The api_key required for authentication
|
||||
:param http_referer: Configures the http_referer parameter for all supported operations
|
||||
:param x_title: Configures the x_title parameter for all supported operations
|
||||
:param server: The server by name to use for all methods
|
||||
:param server_url: The server URL to use for all methods
|
||||
:param url_params: Parameters to optionally template the server URL with
|
||||
@@ -129,6 +134,13 @@ class OpenRouter(BaseSDK):
|
||||
if url_params is not None:
|
||||
server_url = utils.template_url(server_url, url_params)
|
||||
|
||||
_globals = internal.Globals(
|
||||
http_referer=utils.get_global_from_env(
|
||||
http_referer, "OPENROUTER_HTTP_REFERER", str
|
||||
),
|
||||
x_title=utils.get_global_from_env(x_title, "OPENROUTER_X_TITLE", str),
|
||||
)
|
||||
|
||||
BaseSDK.__init__(
|
||||
self,
|
||||
SDKConfiguration(
|
||||
@@ -136,6 +148,7 @@ class OpenRouter(BaseSDK):
|
||||
client_supplied=client_supplied,
|
||||
async_client=async_client,
|
||||
async_client_supplied=async_client_supplied,
|
||||
globals=_globals,
|
||||
security=security,
|
||||
server_url=server_url,
|
||||
server=server,
|
||||
|
||||
@@ -10,6 +10,7 @@ from .httpclient import AsyncHttpClient, HttpClient
|
||||
from .utils import Logger, RetryConfig, remove_suffix
|
||||
from dataclasses import dataclass
|
||||
from openrouter import components
|
||||
from openrouter.models import internal
|
||||
from openrouter.types import OptionalNullable, UNSET
|
||||
from pydantic import Field
|
||||
from typing import Callable, Dict, Optional, Tuple, Union
|
||||
@@ -30,6 +31,7 @@ class SDKConfiguration:
|
||||
async_client: Union[AsyncHttpClient, None]
|
||||
async_client_supplied: bool
|
||||
debug_logger: Logger
|
||||
globals: internal.Globals
|
||||
security: Optional[
|
||||
Union[components.Security, Callable[[], components.Security]]
|
||||
] = None
|
||||
|
||||
@@ -142,16 +142,21 @@ def serialize_multipart_form(
|
||||
if field_metadata.file:
|
||||
if isinstance(val, List):
|
||||
# Handle array of files
|
||||
array_field_name = f_name + "[]"
|
||||
for file_obj in val:
|
||||
if not _is_set(file_obj):
|
||||
continue
|
||||
|
||||
file_name, content, content_type = _extract_file_properties(file_obj)
|
||||
|
||||
file_name, content, content_type = _extract_file_properties(
|
||||
file_obj
|
||||
)
|
||||
|
||||
if content_type is not None:
|
||||
files.append((f_name + "[]", (file_name, content, content_type)))
|
||||
files.append(
|
||||
(array_field_name, (file_name, content, content_type))
|
||||
)
|
||||
else:
|
||||
files.append((f_name + "[]", (file_name, content)))
|
||||
files.append((array_field_name, (file_name, content)))
|
||||
else:
|
||||
# Handle single file
|
||||
file_name, content, content_type = _extract_file_properties(val)
|
||||
@@ -161,11 +166,16 @@ def serialize_multipart_form(
|
||||
else:
|
||||
files.append((f_name, (file_name, content)))
|
||||
elif field_metadata.json:
|
||||
files.append((f_name, (
|
||||
None,
|
||||
marshal_json(val, request_field_types[name]),
|
||||
"application/json",
|
||||
)))
|
||||
files.append(
|
||||
(
|
||||
f_name,
|
||||
(
|
||||
None,
|
||||
marshal_json(val, request_field_types[name]),
|
||||
"application/json",
|
||||
),
|
||||
)
|
||||
)
|
||||
else:
|
||||
if isinstance(val, List):
|
||||
values = []
|
||||
@@ -175,7 +185,8 @@ def serialize_multipart_form(
|
||||
continue
|
||||
values.append(_val_to_string(value))
|
||||
|
||||
form[f_name + "[]"] = values
|
||||
array_field_name = f_name + "[]"
|
||||
form[array_field_name] = values
|
||||
else:
|
||||
form[f_name] = _val_to_string(val)
|
||||
return media_type, form, files
|
||||
|
||||
@@ -27,12 +27,13 @@ from .forms import _populate_form
|
||||
def get_query_params(
|
||||
query_params: Any,
|
||||
gbls: Optional[Any] = None,
|
||||
allow_empty_value: Optional[List[str]] = None,
|
||||
) -> Dict[str, List[str]]:
|
||||
params: Dict[str, List[str]] = {}
|
||||
|
||||
globals_already_populated = _populate_query_params(query_params, gbls, params, [])
|
||||
globals_already_populated = _populate_query_params(query_params, gbls, params, [], allow_empty_value)
|
||||
if _is_set(gbls):
|
||||
_populate_query_params(gbls, None, params, globals_already_populated)
|
||||
_populate_query_params(gbls, None, params, globals_already_populated, allow_empty_value)
|
||||
|
||||
return params
|
||||
|
||||
@@ -42,6 +43,7 @@ def _populate_query_params(
|
||||
gbls: Any,
|
||||
query_param_values: Dict[str, List[str]],
|
||||
skip_fields: List[str],
|
||||
allow_empty_value: Optional[List[str]] = None,
|
||||
) -> List[str]:
|
||||
globals_already_populated: List[str] = []
|
||||
|
||||
@@ -69,6 +71,16 @@ def _populate_query_params(
|
||||
globals_already_populated.append(name)
|
||||
|
||||
f_name = field.alias if field.alias is not None else name
|
||||
|
||||
allow_empty_set = set(allow_empty_value or [])
|
||||
should_include_empty = f_name in allow_empty_set and (
|
||||
value is None or value == [] or value == ""
|
||||
)
|
||||
|
||||
if should_include_empty:
|
||||
query_param_values[f_name] = [""]
|
||||
continue
|
||||
|
||||
serialization = metadata.serialization
|
||||
if serialization is not None:
|
||||
serialized_parms = _get_serialized_params(
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
import asyncio
|
||||
import random
|
||||
import time
|
||||
from typing import List
|
||||
from datetime import datetime
|
||||
from email.utils import parsedate_to_datetime
|
||||
from typing import List, Optional
|
||||
|
||||
import httpx
|
||||
|
||||
@@ -51,9 +53,11 @@ class Retries:
|
||||
|
||||
class TemporaryError(Exception):
|
||||
response: httpx.Response
|
||||
retry_after: Optional[int]
|
||||
|
||||
def __init__(self, response: httpx.Response):
|
||||
self.response = response
|
||||
self.retry_after = _parse_retry_after_header(response)
|
||||
|
||||
|
||||
class PermanentError(Exception):
|
||||
@@ -63,6 +67,62 @@ class PermanentError(Exception):
|
||||
self.inner = inner
|
||||
|
||||
|
||||
def _parse_retry_after_header(response: httpx.Response) -> Optional[int]:
|
||||
"""Parse Retry-After header from response.
|
||||
|
||||
Returns:
|
||||
Retry interval in milliseconds, or None if header is missing or invalid.
|
||||
"""
|
||||
retry_after_header = response.headers.get("retry-after")
|
||||
if not retry_after_header:
|
||||
return None
|
||||
|
||||
try:
|
||||
seconds = float(retry_after_header)
|
||||
return round(seconds * 1000)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
try:
|
||||
retry_date = parsedate_to_datetime(retry_after_header)
|
||||
delta = (retry_date - datetime.now(retry_date.tzinfo)).total_seconds()
|
||||
return round(max(0, delta) * 1000)
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def _get_sleep_interval(
|
||||
exception: Exception,
|
||||
initial_interval: int,
|
||||
max_interval: int,
|
||||
exponent: float,
|
||||
retries: int,
|
||||
) -> float:
|
||||
"""Get sleep interval for retry with exponential backoff.
|
||||
|
||||
Args:
|
||||
exception: The exception that triggered the retry.
|
||||
initial_interval: Initial retry interval in milliseconds.
|
||||
max_interval: Maximum retry interval in milliseconds.
|
||||
exponent: Base for exponential backoff calculation.
|
||||
retries: Current retry attempt count.
|
||||
|
||||
Returns:
|
||||
Sleep interval in seconds.
|
||||
"""
|
||||
if (
|
||||
isinstance(exception, TemporaryError)
|
||||
and exception.retry_after is not None
|
||||
and exception.retry_after > 0
|
||||
):
|
||||
return exception.retry_after / 1000
|
||||
|
||||
sleep = (initial_interval / 1000) * exponent**retries + random.uniform(0, 1)
|
||||
return min(sleep, max_interval / 1000)
|
||||
|
||||
|
||||
def retry(func, retries: Retries):
|
||||
if retries.config.strategy == "backoff":
|
||||
|
||||
@@ -183,8 +243,10 @@ def retry_with_backoff(
|
||||
return exception.response
|
||||
|
||||
raise
|
||||
sleep = (initial_interval / 1000) * exponent**retries + random.uniform(0, 1)
|
||||
sleep = min(sleep, max_interval / 1000)
|
||||
|
||||
sleep = _get_sleep_interval(
|
||||
exception, initial_interval, max_interval, exponent, retries
|
||||
)
|
||||
time.sleep(sleep)
|
||||
retries += 1
|
||||
|
||||
@@ -211,7 +273,9 @@ async def retry_with_backoff_async(
|
||||
return exception.response
|
||||
|
||||
raise
|
||||
sleep = (initial_interval / 1000) * exponent**retries + random.uniform(0, 1)
|
||||
sleep = min(sleep, max_interval / 1000)
|
||||
|
||||
sleep = _get_sleep_interval(
|
||||
exception, initial_interval, max_interval, exponent, retries
|
||||
)
|
||||
await asyncio.sleep(sleep)
|
||||
retries += 1
|
||||
|
||||
Reference in New Issue
Block a user