openrouter 0.0.19__py3-none-any.whl → 0.0.21__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openrouter/_version.py +3 -3
- openrouter/analytics.py +2 -0
- openrouter/api_keys.py +24 -4
- openrouter/basesdk.py +6 -0
- openrouter/chat.py +16 -0
- openrouter/completions.py +2 -0
- openrouter/components/__init__.py +32 -13
- openrouter/components/chatcompletionfinishreason.py +17 -0
- openrouter/components/chatgenerationparams.py +22 -10
- openrouter/components/chatmessagecontentitem.py +1 -1
- openrouter/components/chatmessagecontentitemaudio.py +6 -25
- openrouter/components/chatmessagecontentitemcachecontrol.py +32 -0
- openrouter/components/chatmessagecontentitemtext.py +9 -2
- openrouter/components/chatmessagecontentitemvideo.py +9 -5
- openrouter/components/chatresponsechoice.py +1 -67
- openrouter/components/chatstreamingchoice.py +72 -0
- openrouter/components/chatstreamingresponsechunk.py +1 -1
- openrouter/components/completionchoice.py +18 -5
- openrouter/components/completioncreateparams.py +10 -10
- openrouter/components/completionresponse.py +3 -0
- openrouter/components/message.py +10 -9
- openrouter/components/openairesponsesannotation.py +11 -4
- openrouter/components/openresponsesnonstreamingresponse.py +13 -10
- openrouter/components/openresponsesrequest.py +55 -31
- openrouter/components/openresponsesstreamevent.py +110 -39
- openrouter/components/outputmessage.py +10 -4
- openrouter/components/providername.py +6 -1
- openrouter/components/responseformattextconfig.py +9 -7
- openrouter/components/responsesoutputitem.py +12 -10
- openrouter/components/responsesoutputmessage.py +10 -5
- openrouter/credits.py +4 -0
- openrouter/embeddings.py +4 -0
- openrouter/endpoints.py +4 -0
- openrouter/generations.py +2 -0
- openrouter/models/__init__.py +3 -0
- openrouter/models/internal/__init__.py +54 -0
- openrouter/models/internal/globals.py +41 -0
- openrouter/models_.py +6 -0
- openrouter/oauth.py +4 -0
- openrouter/operations/__init__.py +10 -1
- openrouter/operations/createembeddings.py +9 -3
- openrouter/operations/getcredits.py +19 -0
- openrouter/operations/getparameters.py +6 -1
- openrouter/operations/updatekeys.py +2 -2
- openrouter/parameters.py +2 -0
- openrouter/providers.py +2 -0
- openrouter/responses.py +22 -20
- openrouter/sdk.py +13 -0
- openrouter/sdkconfiguration.py +2 -0
- openrouter/utils/forms.py +21 -10
- openrouter/utils/queryparams.py +14 -2
- openrouter/utils/retries.py +69 -5
- {openrouter-0.0.19.dist-info → openrouter-0.0.21.dist-info}/METADATA +1 -1
- {openrouter-0.0.19.dist-info → openrouter-0.0.21.dist-info}/RECORD +57 -51
- {openrouter-0.0.19.dist-info → openrouter-0.0.21.dist-info}/WHEEL +0 -0
- {openrouter-0.0.19.dist-info → openrouter-0.0.21.dist-info}/licenses/LICENSE +0 -0
- {openrouter-0.0.19.dist-info → openrouter-0.0.21.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
from openrouter.types import BaseModel, UnrecognizedStr
|
|
5
|
+
from openrouter.utils import validate_const, validate_open_enum
|
|
6
|
+
import pydantic
|
|
7
|
+
from pydantic.functional_validators import AfterValidator, PlainValidator
|
|
8
|
+
from typing import Literal, Optional, Union
|
|
9
|
+
from typing_extensions import Annotated, NotRequired, TypedDict
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
TTL = Union[
|
|
13
|
+
Literal[
|
|
14
|
+
"5m",
|
|
15
|
+
"1h",
|
|
16
|
+
],
|
|
17
|
+
UnrecognizedStr,
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class ChatMessageContentItemCacheControlTypedDict(TypedDict):
|
|
22
|
+
type: Literal["ephemeral"]
|
|
23
|
+
ttl: NotRequired[TTL]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ChatMessageContentItemCacheControl(BaseModel):
|
|
27
|
+
TYPE: Annotated[
|
|
28
|
+
Annotated[Literal["ephemeral"], AfterValidator(validate_const("ephemeral"))],
|
|
29
|
+
pydantic.Field(alias="type"),
|
|
30
|
+
] = "ephemeral"
|
|
31
|
+
|
|
32
|
+
ttl: Annotated[Optional[TTL], PlainValidator(validate_open_enum(False))] = None
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
|
+
from .chatmessagecontentitemcachecontrol import (
|
|
5
|
+
ChatMessageContentItemCacheControl,
|
|
6
|
+
ChatMessageContentItemCacheControlTypedDict,
|
|
7
|
+
)
|
|
4
8
|
from openrouter.types import BaseModel
|
|
5
9
|
from openrouter.utils import validate_const
|
|
6
10
|
import pydantic
|
|
7
11
|
from pydantic.functional_validators import AfterValidator
|
|
8
|
-
from typing import Literal
|
|
9
|
-
from typing_extensions import Annotated, TypedDict
|
|
12
|
+
from typing import Literal, Optional
|
|
13
|
+
from typing_extensions import Annotated, NotRequired, TypedDict
|
|
10
14
|
|
|
11
15
|
|
|
12
16
|
class ChatMessageContentItemTextTypedDict(TypedDict):
|
|
13
17
|
text: str
|
|
14
18
|
type: Literal["text"]
|
|
19
|
+
cache_control: NotRequired[ChatMessageContentItemCacheControlTypedDict]
|
|
15
20
|
|
|
16
21
|
|
|
17
22
|
class ChatMessageContentItemText(BaseModel):
|
|
@@ -21,3 +26,5 @@ class ChatMessageContentItemText(BaseModel):
|
|
|
21
26
|
Annotated[Literal["text"], AfterValidator(validate_const("text"))],
|
|
22
27
|
pydantic.Field(alias="type"),
|
|
23
28
|
] = "text"
|
|
29
|
+
|
|
30
|
+
cache_control: Optional[ChatMessageContentItemCacheControl] = None
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
from openrouter.types import BaseModel
|
|
5
|
-
from openrouter.utils import validate_const
|
|
5
|
+
from openrouter.utils import get_discriminator, validate_const
|
|
6
6
|
import pydantic
|
|
7
|
+
from pydantic import Discriminator, Tag
|
|
7
8
|
from pydantic.functional_validators import AfterValidator
|
|
8
9
|
from typing import Literal, Union
|
|
9
10
|
from typing_extensions import Annotated, TypeAliasType, TypedDict
|
|
@@ -64,7 +65,10 @@ ChatMessageContentItemVideoTypedDict = TypeAliasType(
|
|
|
64
65
|
)
|
|
65
66
|
|
|
66
67
|
|
|
67
|
-
ChatMessageContentItemVideo =
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
)
|
|
68
|
+
ChatMessageContentItemVideo = Annotated[
|
|
69
|
+
Union[
|
|
70
|
+
Annotated[ChatMessageContentItemVideoInputVideo, Tag("input_video")],
|
|
71
|
+
Annotated[ChatMessageContentItemVideoVideoURL, Tag("video_url")],
|
|
72
|
+
],
|
|
73
|
+
Discriminator(lambda m: get_discriminator(m, "type", "type")),
|
|
74
|
+
]
|
|
@@ -2,41 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
from .assistantmessage import AssistantMessage, AssistantMessageTypedDict
|
|
5
|
+
from .chatcompletionfinishreason import ChatCompletionFinishReason
|
|
5
6
|
from .chatmessagetokenlogprobs import (
|
|
6
7
|
ChatMessageTokenLogprobs,
|
|
7
8
|
ChatMessageTokenLogprobsTypedDict,
|
|
8
9
|
)
|
|
9
|
-
from .chatstreamingmessagechunk import (
|
|
10
|
-
ChatStreamingMessageChunk,
|
|
11
|
-
ChatStreamingMessageChunkTypedDict,
|
|
12
|
-
)
|
|
13
10
|
from openrouter.types import (
|
|
14
11
|
BaseModel,
|
|
15
12
|
Nullable,
|
|
16
13
|
OptionalNullable,
|
|
17
14
|
UNSET,
|
|
18
15
|
UNSET_SENTINEL,
|
|
19
|
-
UnrecognizedStr,
|
|
20
16
|
)
|
|
21
17
|
from openrouter.utils import validate_open_enum
|
|
22
18
|
from pydantic import model_serializer
|
|
23
19
|
from pydantic.functional_validators import PlainValidator
|
|
24
|
-
from typing import Literal, Union
|
|
25
20
|
from typing_extensions import Annotated, NotRequired, TypedDict
|
|
26
21
|
|
|
27
22
|
|
|
28
|
-
ChatCompletionFinishReason = Union[
|
|
29
|
-
Literal[
|
|
30
|
-
"tool_calls",
|
|
31
|
-
"stop",
|
|
32
|
-
"length",
|
|
33
|
-
"content_filter",
|
|
34
|
-
"error",
|
|
35
|
-
],
|
|
36
|
-
UnrecognizedStr,
|
|
37
|
-
]
|
|
38
|
-
|
|
39
|
-
|
|
40
23
|
class ChatResponseChoiceTypedDict(TypedDict):
|
|
41
24
|
finish_reason: Nullable[ChatCompletionFinishReason]
|
|
42
25
|
index: float
|
|
@@ -84,52 +67,3 @@ class ChatResponseChoice(BaseModel):
|
|
|
84
67
|
m[k] = val
|
|
85
68
|
|
|
86
69
|
return m
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
class ChatStreamingChoiceTypedDict(TypedDict):
|
|
90
|
-
delta: ChatStreamingMessageChunkTypedDict
|
|
91
|
-
finish_reason: Nullable[ChatCompletionFinishReason]
|
|
92
|
-
index: float
|
|
93
|
-
logprobs: NotRequired[Nullable[ChatMessageTokenLogprobsTypedDict]]
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
class ChatStreamingChoice(BaseModel):
|
|
97
|
-
delta: ChatStreamingMessageChunk
|
|
98
|
-
|
|
99
|
-
finish_reason: Annotated[
|
|
100
|
-
Nullable[ChatCompletionFinishReason], PlainValidator(validate_open_enum(False))
|
|
101
|
-
]
|
|
102
|
-
|
|
103
|
-
index: float
|
|
104
|
-
|
|
105
|
-
logprobs: OptionalNullable[ChatMessageTokenLogprobs] = UNSET
|
|
106
|
-
|
|
107
|
-
@model_serializer(mode="wrap")
|
|
108
|
-
def serialize_model(self, handler):
|
|
109
|
-
optional_fields = ["logprobs"]
|
|
110
|
-
nullable_fields = ["finish_reason", "logprobs"]
|
|
111
|
-
null_default_fields = []
|
|
112
|
-
|
|
113
|
-
serialized = handler(self)
|
|
114
|
-
|
|
115
|
-
m = {}
|
|
116
|
-
|
|
117
|
-
for n, f in type(self).model_fields.items():
|
|
118
|
-
k = f.alias or n
|
|
119
|
-
val = serialized.get(k)
|
|
120
|
-
serialized.pop(k, None)
|
|
121
|
-
|
|
122
|
-
optional_nullable = k in optional_fields and k in nullable_fields
|
|
123
|
-
is_set = (
|
|
124
|
-
self.__pydantic_fields_set__.intersection({n})
|
|
125
|
-
or k in null_default_fields
|
|
126
|
-
) # pylint: disable=no-member
|
|
127
|
-
|
|
128
|
-
if val is not None and val != UNSET_SENTINEL:
|
|
129
|
-
m[k] = val
|
|
130
|
-
elif val != UNSET_SENTINEL and (
|
|
131
|
-
not k in optional_fields or (optional_nullable and is_set)
|
|
132
|
-
):
|
|
133
|
-
m[k] = val
|
|
134
|
-
|
|
135
|
-
return m
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
from .chatcompletionfinishreason import ChatCompletionFinishReason
|
|
5
|
+
from .chatmessagetokenlogprobs import (
|
|
6
|
+
ChatMessageTokenLogprobs,
|
|
7
|
+
ChatMessageTokenLogprobsTypedDict,
|
|
8
|
+
)
|
|
9
|
+
from .chatstreamingmessagechunk import (
|
|
10
|
+
ChatStreamingMessageChunk,
|
|
11
|
+
ChatStreamingMessageChunkTypedDict,
|
|
12
|
+
)
|
|
13
|
+
from openrouter.types import (
|
|
14
|
+
BaseModel,
|
|
15
|
+
Nullable,
|
|
16
|
+
OptionalNullable,
|
|
17
|
+
UNSET,
|
|
18
|
+
UNSET_SENTINEL,
|
|
19
|
+
)
|
|
20
|
+
from openrouter.utils import validate_open_enum
|
|
21
|
+
from pydantic import model_serializer
|
|
22
|
+
from pydantic.functional_validators import PlainValidator
|
|
23
|
+
from typing_extensions import Annotated, NotRequired, TypedDict
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ChatStreamingChoiceTypedDict(TypedDict):
|
|
27
|
+
delta: ChatStreamingMessageChunkTypedDict
|
|
28
|
+
finish_reason: Nullable[ChatCompletionFinishReason]
|
|
29
|
+
index: float
|
|
30
|
+
logprobs: NotRequired[Nullable[ChatMessageTokenLogprobsTypedDict]]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class ChatStreamingChoice(BaseModel):
|
|
34
|
+
delta: ChatStreamingMessageChunk
|
|
35
|
+
|
|
36
|
+
finish_reason: Annotated[
|
|
37
|
+
Nullable[ChatCompletionFinishReason], PlainValidator(validate_open_enum(False))
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
index: float
|
|
41
|
+
|
|
42
|
+
logprobs: OptionalNullable[ChatMessageTokenLogprobs] = UNSET
|
|
43
|
+
|
|
44
|
+
@model_serializer(mode="wrap")
|
|
45
|
+
def serialize_model(self, handler):
|
|
46
|
+
optional_fields = ["logprobs"]
|
|
47
|
+
nullable_fields = ["finish_reason", "logprobs"]
|
|
48
|
+
null_default_fields = []
|
|
49
|
+
|
|
50
|
+
serialized = handler(self)
|
|
51
|
+
|
|
52
|
+
m = {}
|
|
53
|
+
|
|
54
|
+
for n, f in type(self).model_fields.items():
|
|
55
|
+
k = f.alias or n
|
|
56
|
+
val = serialized.get(k)
|
|
57
|
+
serialized.pop(k, None)
|
|
58
|
+
|
|
59
|
+
optional_nullable = k in optional_fields and k in nullable_fields
|
|
60
|
+
is_set = (
|
|
61
|
+
self.__pydantic_fields_set__.intersection({n})
|
|
62
|
+
or k in null_default_fields
|
|
63
|
+
) # pylint: disable=no-member
|
|
64
|
+
|
|
65
|
+
if val is not None and val != UNSET_SENTINEL:
|
|
66
|
+
m[k] = val
|
|
67
|
+
elif val != UNSET_SENTINEL and (
|
|
68
|
+
not k in optional_fields or (optional_nullable and is_set)
|
|
69
|
+
):
|
|
70
|
+
m[k] = val
|
|
71
|
+
|
|
72
|
+
return m
|
|
@@ -5,7 +5,7 @@ from .chatgenerationtokenusage import (
|
|
|
5
5
|
ChatGenerationTokenUsage,
|
|
6
6
|
ChatGenerationTokenUsageTypedDict,
|
|
7
7
|
)
|
|
8
|
-
from .
|
|
8
|
+
from .chatstreamingchoice import ChatStreamingChoice, ChatStreamingChoiceTypedDict
|
|
9
9
|
from openrouter.types import (
|
|
10
10
|
BaseModel,
|
|
11
11
|
Nullable,
|
|
@@ -2,12 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
from .completionlogprobs import CompletionLogprobs, CompletionLogprobsTypedDict
|
|
5
|
-
from openrouter.types import
|
|
5
|
+
from openrouter.types import (
|
|
6
|
+
BaseModel,
|
|
7
|
+
Nullable,
|
|
8
|
+
OptionalNullable,
|
|
9
|
+
UNSET,
|
|
10
|
+
UNSET_SENTINEL,
|
|
11
|
+
UnrecognizedStr,
|
|
12
|
+
)
|
|
6
13
|
from openrouter.utils import validate_open_enum
|
|
7
14
|
from pydantic import model_serializer
|
|
8
15
|
from pydantic.functional_validators import PlainValidator
|
|
9
|
-
from typing import Literal, Union
|
|
10
|
-
from typing_extensions import Annotated, TypedDict
|
|
16
|
+
from typing import Literal, Optional, Union
|
|
17
|
+
from typing_extensions import Annotated, NotRequired, TypedDict
|
|
11
18
|
|
|
12
19
|
|
|
13
20
|
CompletionFinishReason = Union[
|
|
@@ -25,6 +32,8 @@ class CompletionChoiceTypedDict(TypedDict):
|
|
|
25
32
|
index: float
|
|
26
33
|
logprobs: Nullable[CompletionLogprobsTypedDict]
|
|
27
34
|
finish_reason: Nullable[CompletionFinishReason]
|
|
35
|
+
native_finish_reason: NotRequired[str]
|
|
36
|
+
reasoning: NotRequired[Nullable[str]]
|
|
28
37
|
|
|
29
38
|
|
|
30
39
|
class CompletionChoice(BaseModel):
|
|
@@ -38,10 +47,14 @@ class CompletionChoice(BaseModel):
|
|
|
38
47
|
Nullable[CompletionFinishReason], PlainValidator(validate_open_enum(False))
|
|
39
48
|
]
|
|
40
49
|
|
|
50
|
+
native_finish_reason: Optional[str] = None
|
|
51
|
+
|
|
52
|
+
reasoning: OptionalNullable[str] = UNSET
|
|
53
|
+
|
|
41
54
|
@model_serializer(mode="wrap")
|
|
42
55
|
def serialize_model(self, handler):
|
|
43
|
-
optional_fields = []
|
|
44
|
-
nullable_fields = ["logprobs", "finish_reason"]
|
|
56
|
+
optional_fields = ["native_finish_reason", "reasoning"]
|
|
57
|
+
nullable_fields = ["logprobs", "finish_reason", "reasoning"]
|
|
45
58
|
null_default_fields = []
|
|
46
59
|
|
|
47
60
|
serialized = handler(self)
|
|
@@ -16,9 +16,9 @@ from openrouter.types import (
|
|
|
16
16
|
UNSET,
|
|
17
17
|
UNSET_SENTINEL,
|
|
18
18
|
)
|
|
19
|
-
from openrouter.utils import validate_const
|
|
19
|
+
from openrouter.utils import get_discriminator, validate_const
|
|
20
20
|
import pydantic
|
|
21
|
-
from pydantic import model_serializer
|
|
21
|
+
from pydantic import Discriminator, Tag, model_serializer
|
|
22
22
|
from pydantic.functional_validators import AfterValidator
|
|
23
23
|
from typing import Dict, List, Literal, Optional, Union
|
|
24
24
|
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict
|
|
@@ -127,16 +127,16 @@ CompletionCreateParamsResponseFormatUnionTypedDict = TypeAliasType(
|
|
|
127
127
|
)
|
|
128
128
|
|
|
129
129
|
|
|
130
|
-
CompletionCreateParamsResponseFormatUnion =
|
|
131
|
-
"CompletionCreateParamsResponseFormatUnion",
|
|
130
|
+
CompletionCreateParamsResponseFormatUnion = Annotated[
|
|
132
131
|
Union[
|
|
133
|
-
CompletionCreateParamsResponseFormatText,
|
|
134
|
-
CompletionCreateParamsResponseFormatJSONObject,
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
132
|
+
Annotated[CompletionCreateParamsResponseFormatText, Tag("text")],
|
|
133
|
+
Annotated[CompletionCreateParamsResponseFormatJSONObject, Tag("json_object")],
|
|
134
|
+
Annotated[ResponseFormatJSONSchema, Tag("json_schema")],
|
|
135
|
+
Annotated[ResponseFormatTextGrammar, Tag("grammar")],
|
|
136
|
+
Annotated[CompletionCreateParamsResponseFormatPython, Tag("python")],
|
|
138
137
|
],
|
|
139
|
-
)
|
|
138
|
+
Discriminator(lambda m: get_discriminator(m, "type", "type")),
|
|
139
|
+
]
|
|
140
140
|
|
|
141
141
|
|
|
142
142
|
class CompletionCreateParamsTypedDict(TypedDict):
|
|
@@ -17,6 +17,7 @@ class CompletionResponseTypedDict(TypedDict):
|
|
|
17
17
|
model: str
|
|
18
18
|
choices: List[CompletionChoiceTypedDict]
|
|
19
19
|
object: Literal["text_completion"]
|
|
20
|
+
provider: NotRequired[str]
|
|
20
21
|
system_fingerprint: NotRequired[str]
|
|
21
22
|
usage: NotRequired[CompletionUsageTypedDict]
|
|
22
23
|
|
|
@@ -38,6 +39,8 @@ class CompletionResponse(BaseModel):
|
|
|
38
39
|
pydantic.Field(alias="object"),
|
|
39
40
|
] = "text_completion"
|
|
40
41
|
|
|
42
|
+
provider: Optional[str] = None
|
|
43
|
+
|
|
41
44
|
system_fingerprint: Optional[str] = None
|
|
42
45
|
|
|
43
46
|
usage: Optional[CompletionUsage] = None
|
openrouter/components/message.py
CHANGED
|
@@ -10,8 +10,9 @@ from .systemmessage import SystemMessage, SystemMessageTypedDict
|
|
|
10
10
|
from .toolresponsemessage import ToolResponseMessage, ToolResponseMessageTypedDict
|
|
11
11
|
from .usermessage import UserMessage, UserMessageTypedDict
|
|
12
12
|
from openrouter.types import BaseModel
|
|
13
|
-
from openrouter.utils import validate_const
|
|
13
|
+
from openrouter.utils import get_discriminator, validate_const
|
|
14
14
|
import pydantic
|
|
15
|
+
from pydantic import Discriminator, Tag
|
|
15
16
|
from pydantic.functional_validators import AfterValidator
|
|
16
17
|
from typing import List, Literal, Optional, Union
|
|
17
18
|
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict
|
|
@@ -56,13 +57,13 @@ MessageTypedDict = TypeAliasType(
|
|
|
56
57
|
)
|
|
57
58
|
|
|
58
59
|
|
|
59
|
-
Message =
|
|
60
|
-
"Message",
|
|
60
|
+
Message = Annotated[
|
|
61
61
|
Union[
|
|
62
|
-
SystemMessage,
|
|
63
|
-
UserMessage,
|
|
64
|
-
MessageDeveloper,
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
Annotated[SystemMessage, Tag("system")],
|
|
63
|
+
Annotated[UserMessage, Tag("user")],
|
|
64
|
+
Annotated[MessageDeveloper, Tag("developer")],
|
|
65
|
+
Annotated[AssistantMessage, Tag("assistant")],
|
|
66
|
+
Annotated[ToolResponseMessage, Tag("tool")],
|
|
67
67
|
],
|
|
68
|
-
)
|
|
68
|
+
Discriminator(lambda m: get_discriminator(m, "role", "role")),
|
|
69
|
+
]
|
|
@@ -4,8 +4,10 @@ from __future__ import annotations
|
|
|
4
4
|
from .filecitation import FileCitation, FileCitationTypedDict
|
|
5
5
|
from .filepath import FilePath, FilePathTypedDict
|
|
6
6
|
from .urlcitation import URLCitation, URLCitationTypedDict
|
|
7
|
+
from openrouter.utils import get_discriminator
|
|
8
|
+
from pydantic import Discriminator, Tag
|
|
7
9
|
from typing import Union
|
|
8
|
-
from typing_extensions import TypeAliasType
|
|
10
|
+
from typing_extensions import Annotated, TypeAliasType
|
|
9
11
|
|
|
10
12
|
|
|
11
13
|
OpenAIResponsesAnnotationTypedDict = TypeAliasType(
|
|
@@ -14,6 +16,11 @@ OpenAIResponsesAnnotationTypedDict = TypeAliasType(
|
|
|
14
16
|
)
|
|
15
17
|
|
|
16
18
|
|
|
17
|
-
OpenAIResponsesAnnotation =
|
|
18
|
-
|
|
19
|
-
)
|
|
19
|
+
OpenAIResponsesAnnotation = Annotated[
|
|
20
|
+
Union[
|
|
21
|
+
Annotated[FileCitation, Tag("file_citation")],
|
|
22
|
+
Annotated[URLCitation, Tag("url_citation")],
|
|
23
|
+
Annotated[FilePath, Tag("file_path")],
|
|
24
|
+
],
|
|
25
|
+
Discriminator(lambda m: get_discriminator(m, "type", "type")),
|
|
26
|
+
]
|
|
@@ -48,8 +48,8 @@ from openrouter.types import (
|
|
|
48
48
|
UNSET,
|
|
49
49
|
UNSET_SENTINEL,
|
|
50
50
|
)
|
|
51
|
-
from openrouter.utils import validate_open_enum
|
|
52
|
-
from pydantic import model_serializer
|
|
51
|
+
from openrouter.utils import get_discriminator, validate_open_enum
|
|
52
|
+
from pydantic import Discriminator, Tag, model_serializer
|
|
53
53
|
from pydantic.functional_validators import PlainValidator
|
|
54
54
|
from typing import Any, Dict, List, Literal, Optional, Union
|
|
55
55
|
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict
|
|
@@ -127,16 +127,19 @@ OpenResponsesNonStreamingResponseToolUnionTypedDict = TypeAliasType(
|
|
|
127
127
|
)
|
|
128
128
|
|
|
129
129
|
|
|
130
|
-
OpenResponsesNonStreamingResponseToolUnion =
|
|
131
|
-
"OpenResponsesNonStreamingResponseToolUnion",
|
|
130
|
+
OpenResponsesNonStreamingResponseToolUnion = Annotated[
|
|
132
131
|
Union[
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
132
|
+
Annotated[OpenResponsesNonStreamingResponseToolFunction, Tag("function")],
|
|
133
|
+
Annotated[OpenResponsesWebSearchPreviewTool, Tag("web_search_preview")],
|
|
134
|
+
Annotated[
|
|
135
|
+
OpenResponsesWebSearchPreview20250311Tool,
|
|
136
|
+
Tag("web_search_preview_2025_03_11"),
|
|
137
|
+
],
|
|
138
|
+
Annotated[OpenResponsesWebSearchTool, Tag("web_search")],
|
|
139
|
+
Annotated[OpenResponsesWebSearch20250826Tool, Tag("web_search_2025_08_26")],
|
|
138
140
|
],
|
|
139
|
-
)
|
|
141
|
+
Discriminator(lambda m: get_discriminator(m, "type", "type")),
|
|
142
|
+
]
|
|
140
143
|
|
|
141
144
|
|
|
142
145
|
class OpenResponsesNonStreamingResponseTypedDict(TypedDict):
|
|
@@ -44,9 +44,10 @@ from openrouter.types import (
|
|
|
44
44
|
UNSET_SENTINEL,
|
|
45
45
|
UnrecognizedStr,
|
|
46
46
|
)
|
|
47
|
-
from openrouter.utils import validate_open_enum
|
|
48
|
-
|
|
49
|
-
from pydantic
|
|
47
|
+
from openrouter.utils import get_discriminator, validate_const, validate_open_enum
|
|
48
|
+
import pydantic
|
|
49
|
+
from pydantic import Discriminator, Tag, model_serializer
|
|
50
|
+
from pydantic.functional_validators import AfterValidator, PlainValidator
|
|
50
51
|
from typing import Any, Dict, List, Literal, Optional, Union
|
|
51
52
|
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict
|
|
52
53
|
|
|
@@ -120,28 +121,22 @@ OpenResponsesRequestToolUnionTypedDict = TypeAliasType(
|
|
|
120
121
|
)
|
|
121
122
|
|
|
122
123
|
|
|
123
|
-
OpenResponsesRequestToolUnion =
|
|
124
|
-
"OpenResponsesRequestToolUnion",
|
|
124
|
+
OpenResponsesRequestToolUnion = Annotated[
|
|
125
125
|
Union[
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
126
|
+
Annotated[OpenResponsesRequestToolFunction, Tag("function")],
|
|
127
|
+
Annotated[OpenResponsesWebSearchPreviewTool, Tag("web_search_preview")],
|
|
128
|
+
Annotated[
|
|
129
|
+
OpenResponsesWebSearchPreview20250311Tool,
|
|
130
|
+
Tag("web_search_preview_2025_03_11"),
|
|
131
|
+
],
|
|
132
|
+
Annotated[OpenResponsesWebSearchTool, Tag("web_search")],
|
|
133
|
+
Annotated[OpenResponsesWebSearch20250826Tool, Tag("web_search_2025_08_26")],
|
|
131
134
|
],
|
|
132
|
-
)
|
|
135
|
+
Discriminator(lambda m: get_discriminator(m, "type", "type")),
|
|
136
|
+
]
|
|
133
137
|
|
|
134
138
|
|
|
135
|
-
ServiceTier =
|
|
136
|
-
Literal[
|
|
137
|
-
"auto",
|
|
138
|
-
"default",
|
|
139
|
-
"flex",
|
|
140
|
-
"priority",
|
|
141
|
-
"scale",
|
|
142
|
-
],
|
|
143
|
-
UnrecognizedStr,
|
|
144
|
-
]
|
|
139
|
+
ServiceTier = Literal["auto",]
|
|
145
140
|
|
|
146
141
|
|
|
147
142
|
Truncation = Union[
|
|
@@ -353,6 +348,17 @@ class Provider(BaseModel):
|
|
|
353
348
|
return m
|
|
354
349
|
|
|
355
350
|
|
|
351
|
+
IDResponseHealing = Literal["response-healing",]
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
class PluginResponseHealingTypedDict(TypedDict):
|
|
355
|
+
id: IDResponseHealing
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
class PluginResponseHealing(BaseModel):
|
|
359
|
+
id: IDResponseHealing
|
|
360
|
+
|
|
361
|
+
|
|
356
362
|
IDFileParser = Literal["file-parser",]
|
|
357
363
|
|
|
358
364
|
|
|
@@ -434,11 +440,24 @@ class PluginModeration(BaseModel):
|
|
|
434
440
|
|
|
435
441
|
PluginTypedDict = TypeAliasType(
|
|
436
442
|
"PluginTypedDict",
|
|
437
|
-
Union[
|
|
443
|
+
Union[
|
|
444
|
+
PluginModerationTypedDict,
|
|
445
|
+
PluginResponseHealingTypedDict,
|
|
446
|
+
PluginFileParserTypedDict,
|
|
447
|
+
PluginWebTypedDict,
|
|
448
|
+
],
|
|
438
449
|
)
|
|
439
450
|
|
|
440
451
|
|
|
441
|
-
Plugin =
|
|
452
|
+
Plugin = Annotated[
|
|
453
|
+
Union[
|
|
454
|
+
Annotated[PluginModeration, Tag("moderation")],
|
|
455
|
+
Annotated[PluginWeb, Tag("web")],
|
|
456
|
+
Annotated[PluginFileParser, Tag("file-parser")],
|
|
457
|
+
Annotated[PluginResponseHealing, Tag("response-healing")],
|
|
458
|
+
],
|
|
459
|
+
Discriminator(lambda m: get_discriminator(m, "id", "id")),
|
|
460
|
+
]
|
|
442
461
|
|
|
443
462
|
|
|
444
463
|
class OpenResponsesRequestTypedDict(TypedDict):
|
|
@@ -468,8 +487,8 @@ class OpenResponsesRequestTypedDict(TypedDict):
|
|
|
468
487
|
include: NotRequired[Nullable[List[OpenAIResponsesIncludable]]]
|
|
469
488
|
background: NotRequired[Nullable[bool]]
|
|
470
489
|
safety_identifier: NotRequired[Nullable[str]]
|
|
471
|
-
store:
|
|
472
|
-
service_tier: NotRequired[
|
|
490
|
+
store: Literal[False]
|
|
491
|
+
service_tier: NotRequired[ServiceTier]
|
|
473
492
|
truncation: NotRequired[Nullable[Truncation]]
|
|
474
493
|
stream: NotRequired[bool]
|
|
475
494
|
provider: NotRequired[Nullable[ProviderTypedDict]]
|
|
@@ -478,6 +497,8 @@ class OpenResponsesRequestTypedDict(TypedDict):
|
|
|
478
497
|
r"""Plugins you want to enable for this request, including their settings."""
|
|
479
498
|
user: NotRequired[str]
|
|
480
499
|
r"""A unique identifier representing your end-user, which helps distinguish between different users of your app. This allows your app to identify specific users in case of abuse reports, preventing your entire app from being affected by the actions of individual users. Maximum of 128 characters."""
|
|
500
|
+
session_id: NotRequired[str]
|
|
501
|
+
r"""A unique identifier for grouping related requests (e.g., a conversation or agent workflow) for observability. If provided in both the request body and the x-session-id header, the body value takes precedence. Maximum of 128 characters."""
|
|
481
502
|
|
|
482
503
|
|
|
483
504
|
class OpenResponsesRequest(BaseModel):
|
|
@@ -533,11 +554,12 @@ class OpenResponsesRequest(BaseModel):
|
|
|
533
554
|
|
|
534
555
|
safety_identifier: OptionalNullable[str] = UNSET
|
|
535
556
|
|
|
536
|
-
|
|
557
|
+
STORE: Annotated[
|
|
558
|
+
Annotated[Optional[Literal[False]], AfterValidator(validate_const(False))],
|
|
559
|
+
pydantic.Field(alias="store"),
|
|
560
|
+
] = False
|
|
537
561
|
|
|
538
|
-
service_tier:
|
|
539
|
-
OptionalNullable[ServiceTier], PlainValidator(validate_open_enum(False))
|
|
540
|
-
] = UNSET
|
|
562
|
+
service_tier: Optional[ServiceTier] = "auto"
|
|
541
563
|
|
|
542
564
|
truncation: Annotated[
|
|
543
565
|
OptionalNullable[Truncation], PlainValidator(validate_open_enum(False))
|
|
@@ -554,6 +576,9 @@ class OpenResponsesRequest(BaseModel):
|
|
|
554
576
|
user: Optional[str] = None
|
|
555
577
|
r"""A unique identifier representing your end-user, which helps distinguish between different users of your app. This allows your app to identify specific users in case of abuse reports, preventing your entire app from being affected by the actions of individual users. Maximum of 128 characters."""
|
|
556
578
|
|
|
579
|
+
session_id: Optional[str] = None
|
|
580
|
+
r"""A unique identifier for grouping related requests (e.g., a conversation or agent workflow) for observability. If provided in both the request body and the x-session-id header, the body value takes precedence. Maximum of 128 characters."""
|
|
581
|
+
|
|
557
582
|
@model_serializer(mode="wrap")
|
|
558
583
|
def serialize_model(self, handler):
|
|
559
584
|
optional_fields = [
|
|
@@ -584,6 +609,7 @@ class OpenResponsesRequest(BaseModel):
|
|
|
584
609
|
"provider",
|
|
585
610
|
"plugins",
|
|
586
611
|
"user",
|
|
612
|
+
"session_id",
|
|
587
613
|
]
|
|
588
614
|
nullable_fields = [
|
|
589
615
|
"instructions",
|
|
@@ -599,8 +625,6 @@ class OpenResponsesRequest(BaseModel):
|
|
|
599
625
|
"include",
|
|
600
626
|
"background",
|
|
601
627
|
"safety_identifier",
|
|
602
|
-
"store",
|
|
603
|
-
"service_tier",
|
|
604
628
|
"truncation",
|
|
605
629
|
"provider",
|
|
606
630
|
]
|